Skip to main content

Create a Cart

When to Create a Cart

You can either create a cart from local storage right before checkout or you can create a cart as soon as a user selects a store, delivery type and time for delivery.

This slightly affects the flow of actions taken later but the system can handle both.

createSlerpCart Mutation

To create a cart use the createSlerpCart Mutation:

mutation CreateSlerpCart($storeId: ID!, $merchantId: ID!, $fulfillmentType: String!, $deliveryAddress: DeliveryAddressParams, $fulfillmentDate: String, $fulfillmentTime: String, $orderItems: [OrderItemParams], $discountCode: String, $customerId: String) {
createSlerpCart(
storeId: $storeId
merchantId: $merchantId
fulfillmentType: $fulfillmentType
deliveryAddress: $deliveryAddress
fulfillmentDate: $fulfillmentDate
fulfillmentTime: $fulfillmentTime
orderItems: $orderItems
discountCode: $discountCode
customerId: $customerId
) {
id
}
}

Variables

When creating a cart the variables are important, a cart can be created with or without products and can be ammended later (see adding items).

Key variables:

  • storeId - The ID of the store being purchased from
  • merchantId - The ID of the merchant being purchased from
  • fulfillmentType - this is either pickup or delivery, if delivery an address is required
  • fulfillmentDate - always in yyyy-mm-dd format
  • fulfillmentTime - always in HH:MM format unless asap, then pass "asap"
  • orderItems - Array of objects containing the details of the product, see example below
  • customerId - optional, only use if a customer is logged in.
  • deliveryAddress - only required if delivery, else pass a null value. If you're using one of our delivery partners to fulfil, make sure for the line_1 to contain the street number and name and line_2 any extra information. For example, the name of the apartment name, house name or flat number.

Delivery Address parameter

If it is a delivery cart by default Slerp will try to geocode the given address and do the needed validations to verify that the address is valid for the given store. If this address is not valid the order acceptance will fail, this can be checked beforehand in the status property of the cart. If this has the value validation_required it means that something went wrong with the address validation.

If you are certain about the address latitude and longitude, it can be passed with the deliveryAddress and Slerp will not geocode the address and use these parameters as source of truth for the delivery (the validation of the address for the given store will still be made).

Example:

{
"deliveryAddress": {
"line_1": "2 Broadway Market",
"line_2": "Flat 30",
"city": "London",
"zip": "SE1 111",
"country": "United Kingdom",
"type": "GEOCODE",
"geom": {
"lat": "51.5357579",
"long": "-0.0619462"
}
}
}

Creating with products

Products are passed in the orderItems array.

{
"storeId": "<store-id>",
"merchantId": "<merchant-id>",
"fulfillmentType": "pickup",
"fulfillmentDate": "YYYY-MM-DD",
"fulfillmentTime": "HH:mm",
"deliveryAddress": {
"line_1": "2 Broadway Market",
"line_2": "Flat 30",
"city": "London",
"zip": "SE1 111",
"country": "United Kingdom"
},
"orderItems": [
{
"productVariantId": "<product-variant-id>",
"quantity": 10,
"appliedModifiers": [
{
"modifierId": "<modifier-id>",
"quantity": 1
}
]
}
],
"customerId": null
}

Success response:

{
"data": {
"updateCartCustomerDetails": {
"id": "b68df2c0-8ca5-4320-8cd8-b2bb0b79d452" //cart id
}
}
}

NOTE: When passing the productVariantId to create a card it must be the variant id and not the product.id