Carts
A shopping cart holds product variants and can be ordered. Each cart either belongs to a registered customer or is an anonymous cart.
The maximum number of carts that can be added to a project is 10 000 000. If your project contains more carts, the commercetools platform will automatically delete the ones that have been least recently modified. This limit can be increased per project after we review the performance impact. Please contact Support via the Support Portal and provide the region, project key, and use case.
Representations
All representations are JSON objects submitted or received as payload to API requests or responses.
Cart
id
- String
The unique ID of the cart.key
- String - Optional
User-specific unique identifier of the cart.version
- Number
The current version of the cart.createdAt
- DateTimecreatedBy
- CreatedBy BETA
Present on resources created after 2019-02-01 except for events not tracked.lastModifiedAt
- DateTimelastModifiedBy
- LastModifiedBy BETA
Present on resources updated after 2019-02-01 except for events not tracked.customerId
- String - OptionalcustomerEmail
- String - OptionalanonymousId
- String - Optional
Identifies carts and orders belonging to an anonymous session (the customer has not signed up/in yet).store
- KeyReference to a Store - OptionallineItems
- Array of LineItemcustomLineItems
- Array of CustomLineItemtotalLineItemQuantity
- The sum off all the lineItems quantities. Does not takecustomLineItems
into consideration.totalPrice
- CentPrecisionMoney
The sum of alltotalPrice
fields of thelineItems
andcustomLineItems
, as well as theprice
field ofshippingInfo
(if it exists).totalPrice
may or may not include the taxes: it depends on the taxRate.includedInPrice property of each price.taxedPrice
- TaxedPrice - Optional
Not set until the shipping address is set. Will be set automatically in thePlatform
TaxMode. For theExternal
tax mode it will be set as soon as the external tax rates for all line items, custom line items, and shipping in the cart are set.cartState
- CartStateshippingAddress
- Address - Optional
The shipping address is used to determine the eligible shipping methods and rates as well as the tax rate of the line items.billingAddress
- Address - OptionalinventoryMode
- InventoryModetaxMode
- TaxModetaxRoundingMode
- RoundingMode
When calculating taxes fortaxedPrice
, the selected mode is used for rounding.taxCalculationMode
- TaxCalculationMode
When calculating taxes fortaxedPrice
, the selected mode is used for calculating the price withLineItemLevel
(horizontally) orUnitPriceLevel
(vertically) calculation mode.customerGroup
- Reference to a CustomerGroup - Optional
Set automatically when the customer is set and the customer is a member of a customer group. Used for product variant price selection.country
- String - Optional
A two-digit country code as per ISO 3166-1 alpha-2. Used for product variant price selection.shippingInfo
- ShippingInfo - Optional
Set automatically once the ShippingMethod is set.discountCodes
- Array of DiscountCodeInforefusedGifts
- Array of References to CartDiscounts
Automatically filled when a line item with LineItemModeGiftLineItem
is removed from the cart.custom
- CustomFields - OptionalpaymentInfo
- PaymentInfo - Optionallocale
- String conforming to IETF language tag - OptionaldeleteDaysAfterLastModification
- Number - Optional
The cart will be deleted automatically if it hasn't been modified for the specified amount of days.shippingRateInput
-ShippingRateInput - Optional
The shippingRateInput is used as an input to select a ShippingRatePriceTier.origin
- CartOrigin
The origin field indicates how this cart was created. The valueCustomer
indicates, that the cart was created by the customer.itemShippingAddresses
- Array of Addresses
Contains addresses for carts with multiple shipping addresses. Line items reference these addresses under theirshippingDetails
. The addresses captured here are not used to determine eligible shipping methods or the applicable tax rate. Only the cart'sshippingAddress
is used for this.
Cart fields that can be used in query predicates: id
, version
, createdAt
,
lastModifiedAt
, customerId
, customerEmail
, anonymousId
, country
, totalPrice
, taxedPrice
, shippingAddress
, billingAddress
, customerGroup
, lineItems
, customLineItems
, shippingInfo
, discountCodes
, paymentInfo
, cartState
, inventoryMode
, locale
, shippingRateInput
, taxCalculationMode
, itemShippingAddresses
.
Cart Price precision
- Prices with TypedMoney can have cent-precision and high-precision.
- When calculating net and gross prices, prices with decimals are rounded. In case the fraction of
centAmount
is exactly 0.5, the RoundingMode defined bytaxRoundingMode
is applied on the cart's price. - The tax portions are derived from the net prices in case the tax is not included in the price, meaning the
includedInPrice
-field in the TaxRate for the product is set tofalse
. When the tax is included in the price (includedInPrice:true
), then the tax portions are derived from the gross prices. This only applies when thePlatform
TaxMode is used. - When prices are discounted with relative discounts, they are always rounded in favor of the customer with the half down rounding.
Cart tax rate selection
A cart cannot calculate taxes for the items in it until the shippingAddress
property is set. The shippingAddress.country
and shippingAddress.state
properties affect the selection criteria. These are compared to the TaxRate
's country
and state
fields. A tax rate is only eligible if the country
and state
properties are an exact match. Because the state
field is optional on both TaxRate
and shippingAddress
, this means the following:
- If
shippingAddress.country
andTaxRate.country
are an exact match , and nostate
properties are present, theTaxRate
applies to the cart. - If
shippingAddress.country
andTaxRate.country
are an exact match, but eithershippingAddress.state
orTaxRate.state
are present, the tax rate does not apply to the cart. - If
shippingAddress.country
andTaxRate.country
are an exact match, andshippingAddress.state
andTaxRate.state
are an exact match, the tax rate applies to the cart. - If
shippingAddress.country
andTaxRate.country
are present, andshippingAddress.state
andTaxRate.state
are present, but there is a mismatch of eithercountry
orstate
, the tax rate does not apply to the cart.
If you need to include a state or country sub-unit for shipping purposes, use shippingAddress.region
to avoid tax rate conflicts.
CartDraft
A CartDraft is the object submitted as payload to a Create Cart method.
currency
- String - Required
A three-digit currency code as per ISO 4217.key
- String - Optional
User-specific unique identifier of the cart.customerId
- String - Optional
Id of an existing Customer.customerEmail
- String - OptionalcustomerGroup
- ResourceIdentifier of a CustomerGroup - Optional
Will be set automatically when thecustomerId
is set and the customer is a member of a customer group. Can be set explicitly when nocustomerId
is present.anonymousId
- String - Optional
Assigns the new cart to an anonymous session (the customer has not signed up/in yet).store
- ResourceIdentifier of a Store - Optional Assigns the new cart to the store. The store assignment can not be modified.country
- String - Optional
A two-digit country code as per ISO 3166-1 alpha-2.inventoryMode
- InventoryMode - Optional
Default inventory mode isNone
.taxMode
- TaxMode - Optional
The default tax mode isPlatform
.taxRoundingMode
- RoundingMode - Optional
The default tax rounding mode isHalfEven
.taxCalculationMode
- TaxCalculationMode - Optional
The default tax calculation mode isLineItemLevel
.lineItems
- Array of LineItemDraft - OptionalcustomLineItems
- Array of CustomLineItemDraft - OptionalshippingAddress
- AddressDraft - Optional
The shipping address is used to determine the eligible shipping methods and rates as well as the tax rate of the line items.billingAddress
- AddressDraft - OptionalshippingMethod
- ResourceIdentifier of a ShippingMethod - OptionalexternalTaxRateForShippingMethod
- ExternalTaxRateDraft - Optional
An external tax rate can be set for theshippingMethod
if the cart has theExternal
TaxMode.custom
- CustomFieldsDraft - Optional
The custom fields.locale
- String conforming to IETF language tag - Optional
Must be one of the languages supported for this project.deleteDaysAfterLastModification
- Number - Optional
The cart will be deleted automatically if it hasn't been modified for the specified amount of days. If not set, the default value configured in the Project is used.
If a ChangeSubscription for carts exists, aResourceDeleted
notification will be sent.shippingRateInput
- ShippingRateInputDraft - Optional
The shippingRateInput is used as an input to select a ShippingRatePriceTier.
Based on the definition of ShippingRateInputType. If CartClassificationType is defined, it must be ClassificationShippingRateInput. If CartScoreType is defined, it must be ScoreShippingRateInput. Otherwise it can not bet set.origin
- CartOrigin - Optional
The default origin isCustomer
.itemShippingAddresses
- Array of AddresseDrafts - Optional
Contains addresses for carts with multiple shipping addresses. Each address must contain a key which is unique in this cart. Line items will use these keys to reference the addresses under theirshippingDetails
. The addresses captured here are not used to determine eligible shipping methods or the applicable tax rate. Only the cart'sshippingAddress
is used for this.discountCodes
- Array of Strings - Optional
Thecode
of existing DiscountCodes.
ReplicaCartDraft
Body to create a new cart by replicating an existing cart or order.
LineItem
A line item is a snapshot of a product variant at the time it was added to the cart. The snapshot is created from the ProductProjection as follows:
- The current projection is used.
- If the cart is bound to a Store
- For Stores with active Product Selections BETA Product must be included by at least one of the active selections.
- all LocalizedStrings are filtered according to the locales defined in the store.
- all Prices are filtered according to the product distribution channels defined in the store. Prices without channel are included.
- all ProductVariantAvailabilities are filtered according to the inventory supply channels defined in the store. Inventory entries without channel are included.
Since a product variant may change at any time, the ProductVariant data is copied into the field variant
. The relation to the current ProductProjection is kept but the line item will not automatically update if the product variant changes. On the cart, the line item can be updated manually.
The productSlug
refers to the current version of the product. It can be used to link to the product.
If the product has been deleted, the line item remains but refers to a non-existent product and the productSlug
is left empty.
Please also note that creating an order is impossible if the product or product variant a line item relates to has been deleted.
id
- String
The unique ID of this LineItem.productId
- StringproductKey
- String - Optional
User-defined unique identifier for the Product. Only present on Line Items in a Cart when thekey
is available on that specific Product at the time the Line Item is created or updated on the Cart. On Order resources this field is only present when thekey
is available on the specific Product at the time the Order is created from the Cart.
This field is in general not present on Carts that had no updates until 3 December 2021 and on Orders created before this date.name
- LocalizedString
The product name.productSlug
- LocalizedString - Optional
The slug of a product is inserted on the fly. It can therefore be used to link to the product detail page of the product. It is empty if the product has been deleted.
The slug is also empty if the cart or order is retrieved via Reference Expansion or is a snapshot in a Message.productType
- Reference to a ProductType - Optionalvariant
- ProductVariant
The variant data is saved when the variant is added to the cart, and not updated automatically. It can manually be updated with the Recalculate update action.price
- Price
The price of a line item is selected from the prices array of the product variant. If thevariant
field hasn't been updated, the price may not correspond to a price invariant.prices
.taxedPrice
- TaxedItemPrice - Optional
Set once thetaxRate
is set.totalPrice
- CentPrecisionMoney
The total price of this line item. If the line item is discounted, then thetotalPrice
is the DiscountedLineItemPriceForQuantity multiplied byquantity
. Otherwise the total price is the product price multiplied by thequantity
.totalPrice
may or may not include the taxes: it depends on the taxRate.includedInPrice property.quantity
- Number
The amount of a LineItem in the cart. Must be a positive integer.addedAt
- DateTime - Optional
When the line item was added to the cart. Optional for backwards compatibility reasons only.state
- Array of ItemStatetaxRate
-TaxRate - Optional
Will be set automatically in thePlatform
TaxMode once the shipping address is set is set. For theExternal
tax mode the tax rate has to be set explicitly with the ExternalTaxRateDraft.supplyChannel
- Reference to a Channel - Optional
The supply channel identifies the inventory entries that should be reserved. The Channel must have theInventorySupply
ChannelRoleEnum. If the cart is bound to a Store withsupplyChannels
set, the channel has to match one of the store's supply channels.distributionChannel
- Reference to a Channel - Optional
The distribution channel is used to select a ProductPrice. The Channel hasProductDistribution
ChannelRoleEnum If the cart is bound to a Store withdistributionChannels
set, the channel has to match one of the store's distribution channels.discountedPricePerQuantity
- Array of DiscountedLineItemPriceForQuantitypriceMode
- LineItemPriceModelineItemMode
- LineItemModecustom
- CustomFields - OptionalshippingDetails
- ItemShippingDetails - Optional
Container for line item specific address(es).lastModifiedAt
- DateTime - Optional
The date when the LineItem was last modified by one of the following actions: setLineItemShippingDetails, addLineItem, removeLineItem, or changeLineItemQuantity. Optional only for backwards compatible reasons. When the LineItem is createdlastModifiedAt
is set toaddedAt
.
LineItem fields that can be used in query predicates: productId
, name
, quantity
,
variant
, price
, discountedPricePerQuantity
.
LineItem Price selection
The price of a LineItem is selected from the prices array of the product variant based on several conditions:
selection based on the distribution channel, the currency, the country and the customer group
The selection of the price is based on the provided
distributionChannel
and on the currency, country, and the customer group of the cart. If a price with an exact match cannot be found, wildcards (all countries, all channels, all CustomerGroups) are used.
The list below defines how the price is selected. If a price could not be found in one step the rule in the next step will be applied until a price could be found. The priority order for the selection of the price is customer group > channel > country (customer group has the highest priority and country the lowest).
The price for a specific currency is determined in the following order:- Find a price for the country, customer group and channel.
- Find a price for the customer group and channel for all countries.
- Find a price for the customer group and country for all channels.
- Find a price for the customer group for all channels and all countries.
- Find a price for the country and channel for all customer groups.
- Find a price for the channel for all customer groups and all countries.
- Find a price for the country for all customer groups and all channels.
- Find a price for all customer groups, all channels and all countries.
selection based on the validity period
For all of the price selection steps, the prices with a validity period are checked before the prices without any validity period.
If a currently valid price is found, it is used first.tier price selection based on the quantity
If the product Price has some tier prices, the tier price valid for the line item quantity is selected.
If no tier price can be used, the base Price is used.
LineItemDraft Product Variant identification
To specify which Product Variant is used for the LineItemDraft the variant can be identified either by
- the combination of its product ID and its variant ID, or by
- its SKU.
Choose one of the options below:
Identification by IDs
productId
- String - Required
ID of an existing Product.variantId
- Number - Optional
ID of an existing ProductVariant in the product. If not given, the master variant is used.
Identification by SKU
sku
- String - Required
SKU of an existing ProductVariant.
LineItemDraft
- LineItemDraft Product Variant identification - Required
quantity
- Number - Optional - Defaults to1
The amount of aLineItem
in the cart. Must be a positive integer.supplyChannel
- ResourceIdentifier of a Channel - Optional
By providing supply channel information, you can unique identify inventory entries that should be reserved. The Channel must have theInventorySupply
ChannelRoleEnumdistributionChannel
- ResourceIdentifier of a Channel - Optional
The channel is used to select a ProductPrice. The Channel must have theProductDistribution
ChannelRoleEnum If the cart is bound to a Store withdistributionChannels
set, the channel has to match one of the store's distribution channels.externalTaxRate
- ExternalTaxRateDraft - Optional
An external tax rate can be set if the cart has theExternal
TaxMode.externalPrice
- Money - Optional
Sets the line itemprice
to the given value and sets the line itempriceMode
toExternalPrice
LineItemPriceMode.externalTotalPrice
- ExternalLineItemTotalPrice - Optional
Sets the line itemprice
andtotalPrice
to the given values and sets the line itempriceMode
toExternalTotal
LineItemPriceMode.custom
- CustomFieldsDraft - Optional
The custom fields.shippingDetails
- ItemShippingDetailsDraft - Optional
Container for line item specific address(es).addedAt
- DateTime - Optional
When the line item was added to the cart. Defaults to the current date and time.
The logic to select the price is described in LineItem Price selection.
CustomLineItem
A custom line item is a generic item that can be added to the cart but is not bound to a product. You can use it for discounts (negative money), vouchers, complex cart rules, additional services or fees. You control the lifecycle of this item.
id
- String
The unique ID of this CustomLineItem.name
- LocalizedString
The name of this CustomLineItem.money
- TypedMoney
The cost to add to the cart. The amount can be negative.taxedPrice
- TaxedItemPrice - Optional
Set once thetaxRate
is set.totalPrice
- CentPrecisionMoney
The total price of this custom line item. If custom line item is discounted, then thetotalPrice
would be the discounted custom line item price multiplied byquantity
. Otherwise a total price is just amoney
multiplied by thequantity
.totalPrice
may or may not include the taxes: it depends on the taxRate.includedInPrice property.slug
- String
A unique String in the cart to identify this CustomLineItem.quantity
- Number
The amount of a CustomLineItem in the cart. Must be a positive integer.state
- Array of ItemStatetaxCategory
- Reference to a TaxCategory - OptionaltaxRate
- TaxRate - Optional
Will be set automatically in thePlatform
TaxMode once the shipping address is set is set. For theExternal
tax mode the tax rate has to be set explicitly with the ExternalTaxRateDraft.discountedPricePerQuantity
- Array of DiscountedLineItemPriceForQuantitycustom
- CustomFields - OptionalshippingDetails
- ItemShippingDetails - Optional
Container for custom line item specific address(es).
CustomLineItem fields that can be used in query predicates: slug
, name
, quantity
,
money
, state
, discountedPricePerQuantity
.
CustomLineItemDraft
name
- LocalizedStringquantity
- Number - Optional - Defaults to1
The amount of a CustomLineItem in the Cart. Must be a positive integer.money
- Money
The cost to add to the cart. The amount can be negative.slug
- StringtaxCategory
- ResourceIdentifier of a TaxCategory - Required only forPlatform
TaxMode
The given tax category will be used to select a tax rate when a cart has the TaxModePlatform
.externalTaxRate
- ExternalTaxRateDraft - Optional
An external tax rate can be set if the cart has theExternal
TaxMode.custom
- CustomFieldsDraft - Optional
The custom fields.shippingDetails
- ItemShippingDetailsDraft - Optional
Container for custom line item specific address(es).
ExternalTaxRateDraft
name
- Stringamount
- Number - Optional
Percentage in the range of [0..1]. Must be supplied if nosubRates
are specified. IfsubRates
are specified then theamount
can be omitted or it must be the sum of the amounts of allsubRates
.includedInPrice
- Boolean - Whentrue
, the line item price is considered the gross price and theamount
is applied to calculate the net price. When set tofalse
, the line item price will be considered the net price and theamount
will be applied to calculate the gross price. See example of calculation below. The default value forincludedInPrice
isfalse
.country
- String
A two-digit country code as per ISO 3166-1 alpha-2.state
- String - Optional
The state in the countrysubRates
- Array of SubRate - Optional BETA
For countries (for example the US) where the total tax is a combination of multiple taxes (for example state and local taxes).
The following example shows the impact of includedInPrice
in the cart calculation. The cart has taxMode
HalfEven and taxCalculationMode
is LineItemLevel.
Line Item | Product Variant A | Product Variant B | Shipping |
---|---|---|---|
Line Item: Price | $15 | $25 | $5 |
Quantity | 10 | 5 | --- |
External Tax Rate: includedInPrice | false | true | false |
External Tax Rate: amount | 0.19 | 0.15 | 0.15 |
Taxed Item Price: totalNet | $150 | $108.70 | $5 |
Taxed Item Price: totalGross | $178.5 | $125 | $5.75 |
Calculation formula | 15 x 10 (1 + 0.19) | 25 x 5 / (1+ 0.15) | 5 x (1 + 0.15) |
As seen, when includedInPrice
is true
, the tax is calculated in a top-down manner. When includedInPrice
is false
, the tax is calculated in a bottom-up manner.
ExternalTaxAmountDraft
ExternalTaxAmountDraft cannot be used in LineItemDraft or CustomLineItemDraft. It can only be set using the Update Actions for Carts (namely, Set LineItem TaxAmount, Set CustomLineItem TaxAmount, or Set ShippingMethod TaxAmount) or OrderEdits (namely, Set LineItem TaxAmount, Set CustomLineItem TaxAmount, or Set ShippingMethod TaxAmount).
totalGross
- Money
The total gross amount of the item (totalNet + taxes).taxRate
- ExternalTaxRateDraft
This information gets automatically removed by the platform whenever some changes on the Cart or Order Edit are made that have a financial impact. For example, when the application of a Cart Discount reduces the line item price, the previously set total gross price becomes invalid and the recalculated total gross price needs to be set again with an ExternalTaxAmountDraft by another update action.
TaxedPrice
totalNet
- CentPrecisionMoneytotalGross
- CentPrecisionMoneytaxPortions
- Array of TaxPortion
TaxedPrice fields that can be used in query predicates: totalNet
, totalGross
.
TaxedItemPrice
totalNet
- CentPrecisionMoneytotalGross
- CentPrecisionMoney
TaxedItemPrice fields can not be used in query predicates.
TaxPortion
Represents the portions that sum up to the totalGross
field of a TaxedPrice. The portions are calculated from the TaxRates.
If a tax rate has SubRates, they are used and can be identified by name.
Tax portions from line items that have the same rate
and name
will be accumulated to the same tax portion.
name
- String - Optionalrate
- Number
A number in the range [0..1]amount
- CentPrecisionMoney
CartState
InventoryMode
Values of the InventoryMode enumeration:
TrackOnly
Orders are tracked on inventory. That means, ordering a LineItem will decrement the available quantity on the respective InventoryEntry.
Creating an order will succeed even if the line item's available quantity is zero or negative. But creating an order will fail with an OutOfStock error if no matching inventory entry exists for a line item.ReserveOnOrder
Creating an order will fail with an OutOfStock error if an unavailable line item exists. However, the following exceptions apply:- When any line item's respective InventoryEntry has the
restockableInDays
value set (including0
), then these line items will not cause an error- This is caused when the
availableQuantity
is insufficient for the ordered line item quantity (theavailableQuantity
is still updated).
- This is caused when the
Note: Line items in the cart are only reserved for the duration of the ordering transaction.
- When any line item's respective InventoryEntry has the
None
Adding items to cart and ordering is independent of inventory. No inventory checks or modifications. This is the default mode for a new cart.
TaxMode
Values of the TaxMode enumeration:
Platform
The tax rates are selected by the platform from the TaxCategories based on the cart shipping address. ThetotalNet
andtotalGross
as well as thetaxPortions
fields are calculated by the platform according to thetaxRoundingMode
.External
The tax rates are set externally per ExternalTaxRateDraft. A cart with this tax mode can only be ordered if all line items, all custom line items and the shipping method have an external tax rate set. ThetotalNet
andtotalGross
as well as thetaxPortions
fields are calculated by the platform according to thetaxRoundingMode
.ExternalAmount
The tax amounts and the tax rates as well as the tax portions are set externally per ExternalTaxAmountDraft. A cart with this tax mode can only be ordered if the cart itself and all line items, all custom line items and the shipping method have an external tax amount and rate set. Furthermore, update actions on Carts relevant to prices require external recalculation of the total gross. Hence, the ExternalTaxAmount is removed in these cases and requires you to reset them with the appropriate Update Action: Set LineItem TaxAmount, Set CustomLineItem TaxAmount, or Set ShippingMethod TaxAmount.Disabled
No taxes are added to the cart.
RoundingMode
The rounding mode specifies how the platform should round monetary values.
The values of the RoundingMode enumeration:
HalfEven
- Round half to even
Default rounding mode as used in IEEE 754 computing functions and operators.HalfUp
- Round half upHalfDown
- Round half down
Examples how decimal values are rounded:
Value to round | HalfUp | HalfDown | HalfEven |
---|---|---|---|
23.5 | 24 | 23 | 24 |
24.5 | 25 | 24 | 24 |
25.5 | 26 | 25 | 26 |
TaxCalculationMode
The tax calculation mode specifies how the platform performs calculation of taxes.
The values of the TaxCalculationMode enumeration:
LineItemLevel
- Default
This calculation mode calculates the taxes after the unit price is multiplied with the quantity. For example($1.08 * 3 = $3.24) * 1.19 = $3.8556 -> $3.86 rounded
UnitPriceLevel
This calculation mode calculates the taxes on the unit price before multiplying with the quantity. For example($1.08 * 1.19 = $1.2852 -> $1.29 rounded) * 3 = $3.87
The combination of UnitPriceLevel
and LineItemPriceMode ExternalTotal
is not supported.
The API will reject the request with an error message if this combination is used.
Due to the principle of rounding at every calculation step, this slight difference in when to apply the tax can end up having a considerable effect on the cart total. In the following example, we assume that tax of 19% is included in the price for all line items, that the rounding mode is half even and that the price precision is two decimals.
LineItem # | Quantity | Unit Price | Line Item Total, Net ( LineItemLevel) | Line Item Total, Net (UnitPriceLevel) | Line Item Total, Gross |
---|---|---|---|---|---|
1 | 1 | $1.00 | $0.84 | $0.84 | $1.00 |
2 | 10 | $1.08 | $9.08 | $9.10 | $10.80 |
3 | 10 | $108.08 | $908.24 | $908.20 | $1080.80 |
4 | 1 | $2.00 | $1.68 | $1.68 | $2.00 |
5 | 50 | $0.01 | $0.42 | $0.50 | $0.50 |
6 | 1 | $4.90 | $4.12 | $4.12 | $4.90 |
Cart Total, Net (LineItemLevel) | Cart Total, Net (UnitPriceLevel) | Cart Total, Gross | |||
$924.38 | $924.44 | $1100.00 |
As seen with this example, as long as a line item has quantity of 1, the two modes have no impact on the total net value of a line item (see Line Item #1, 4, and 6).
However, as soon as quantity is more than 1, the two modes calculate the total net value of a line item with a difference of several cents (see Line Item #2, 3, and 5).
Depending on the specific line item values, the chosen mode can give a greater or lesser net value (see line item #2 compared to #3). Accumulated in the cart total,
the difference amounts to 6 cents. The connection to rounding is especially clear with Line Item #5. Due to rounding after applying tax to 0.01 and multiplying with
quantity 50 upon that, the net value when using UnitPriceLevel
ends up being equal to the gross value. With LineItemLevel
, where quantity multiplication is performed as a first
calculation step, the rounding occurs to a greater value and net value ends up being $0.42.
LineItemPriceMode
Values of the LineItemPriceMode enumeration:
Platform
The price is selected form the product variant. This is the default mode.ExternalPrice
The line item price was set externally. Cart discounts can apply to line items with this price mode. All update actions that change the quantity of a line item with this price mode require theexternalPrice
field to be given.ExternalTotal
The line item price with the total was set externally. Cart discounts are deactivated for the line items with this price mode. Although a line item with this price mode has bothprice
andtotalPrice
externally set, onlytotalPrice
will be used to calculate the total price of a cart. All update actions that change the quantity of a line item with this price mode can set the new price with theexternalTotal
field. If theexternalTotal
field is not given in an update action that changes line item quantity then the external price is unset and the price mode is set back toPlatform
.
LineItemMode
Values of the LineItemMode enumeration:
Standard
The line item was added during cart creation or with the update action addLineItem. Its quantity can be changed without restrictions.GiftLineItem
The line item was added automatically, because a discount has added a free gift to the cart. The quantity can not be increased, and it won't be merged when the same product variant is added. If the gift is removed, an entry is added to therefusedGifts
array and the discount won't be applied again to the cart. The price can not be changed externally. All other updates, such as the ones related to custom fields, can be used.
ShippingInfo
shippingMethodName
- Stringprice
- CentPrecisionMoney
Determined based on the ShippingRate and its tiered prices, and either the sum of LineItem prices or theshippingRateInput
field.shippingRate
- ShippingRate
The shipping rate used to determine the price.taxedPrice
- TaxedItemPrice - Optional
Set once thetaxRate
is set.taxRate
- TaxRate - Optional
Will be set automatically in thePlatform
TaxMode once the shipping address is set is set. For theExternal
tax mode the tax rate has to be set explicitly with the ExternalTaxRateDraft.taxCategory
- Reference to a TaxCategory - OptionalshippingMethod
- Reference to a ShippingMethod - Optional
Not set if custom shipping method is used.deliveries
- Array of Delivery
Deliveries are compilations of information on how the articles are being delivered to the customers.discountedPrice
- DiscountedLineItemPrice - OptionalshippingMethodState
- ShippingMethodState
Indicates whether the ShippingMethod referenced in this ShippingInfo is allowed for the cart or not.
DiscountCodeInfo
discountCode
- Reference to a DiscountCodestate
- DiscountCodeState - Optional
DiscountCodeState
Values of the DiscountCodeState
enumeration:
NotActive
The discount code is not active or it does not contain any active cart discounts.NotValid
The discount code is not valid or it does not contain any valid cart discounts. Validity is determined based on thevalidFrom
andvalidUntil
dates.DoesNotMatchCart
The discount code is active and it contains at least one active and valid CartDiscount. But its cart predicate does not match the cart or none of the contained active discount's cart predicates match the cartMatchesCart
The discount code is active and it contains at least one active and valid CartDiscount. The discount code cartPredicate matches the cart and at least one of the contained active discount's cart predicates matches the cart.MaxApplicationReached
maxApplications or maxApplicationsPerCustomer for discountCode has been reached.ApplicationStoppedByPreviousDiscount
The discount code is active and none of the discounts were applied because the discount application was stopped by one discount that has the StackingMode ofStopAfterThisDiscount
defined.
ShippingMethodState
Values of the ShippingMethodState
enumeration:
DoesNotMatchCart
The ShippingMethodpredicate
does not match the cart. Ordering this cart will fail with errorShippingMethodDoesNotMatchCart
.MatchesCart
Either there is nopredicate
defined for the ShippingMethod or the givenpredicate
matches the cart.
DiscountedLineItemPriceForQuantity
quantity
- Number - RequireddiscountedPrice
- DiscountedLineItemPrice - Required
DiscountedLineItemPrice
value
- TypedMoneyincludedDiscounts
- Array of DiscountedLineItemPortion
DiscountedLineItemPortion
discount
- Reference to a CartDiscountdiscountedAmount
- TypedMoney
ExternalLineItemTotalPrice
price
- Money - RequiredtotalPrice
- CentPrecisionMoneyDraft - Required
ShippingRateInput
ClassificationShippingRateInput
type
- String -"Classification"
key
- Stringlabel
- LocalizedString
ScoreShippingRateInput
type
- String -"Score"
score
- Number
ShippingRateInputDraft
Based on the definition of ShippingRateInputType, only one of the following is allowed.
It is not possible to set a value for the shippingRateInput
on the cart if CartValue
is selected as ShippingRateInputType.
ClassificationShippingRateInput
type
- String -"Classification"
key
- String
ScoreShippingRateInput
type
- String -"Score"
score
- Number
ItemShippingDetails
If multiple shipping addresses are needed for a cart, ItemShippingDetails
contains the information where the individual items should be sent to. If needed, it is possible to set different addresses per sub-quantity of a line item.
If a quantity in targets
is updated to be 0, the target will automatically be removed from a (custom) line item.
targets
- Array of ItemShippingTarget
Used to map what sub-quantity should be shipped to which address.
Duplicate address keys are not allowed.valid
- Booleantrue
if the quantity of the (custom) line item is equal to the sum of the sub-quantities intargets
,false
otherwise.
A cart cannot be ordered when the value isfalse
. The error InvalidItemShippingDetails will be triggered.
ItemShippingDetailsDraft
Draft object for ItemShippingDetails.
targets
- Array of ItemShippingTargets
Used to capture one or more (custom) line item specific shipping addresses. By specifying sub-quantities, it is possible to set multiple shipping addresses for one line item.
A cart can have shippingDetails
where the targets
sum does not match the quantity of the line item or custom line item.
For the order creation and order updates the targets
sum must match the quantity.
ItemShippingTarget
Each item shipping target determines the address (as a reference to an address in itemShippingAddresses
) and the quantity that should be shipped to this address. Should multiple shipping addresses be needed for one (custom) line item, sub-quantities are specified. Thus, an array of addresses and sub-quantities is stored per (custom) line item. Upon order creation, the sum of sub-quantities must add up to the total quantity of the (custom) line item.
addressKey
- String
The key of the address in the cart'sitemShippingAddresses
quantity
- Number
The quantity of items that should go to the address with the specifiedaddressKey
.
Only positive values are allowed. Using0
as quantity is also possible in a draft object, but the element will not be present in the resulting ItemShippingDetails.
CartOrigin
Values of the CartOrigin enumeration:
Customer
The cart was created by the customer. This is the default value.Merchant
The cart was created by the merchant on behalf of the customer.
Get a Cart
Get a Cart by ID
Endpoint: /{projectKey}/carts/{id}
Method: GET
OAuth 2.0 Scopes: view_orders:{projectKey}
Response Representation: Cart
The cart may not contain up-to-date prices, discounts etc. If you want to ensure they're up-to-date, send an Update request with the Recalculate update action instead.
Get a Cart by Key
Endpoint: /{projectKey}/carts/key={key}
Method: GET
OAuth 2.0 Scopes: view_orders:{projectKey}
Response Representation: Cart
Get a cart by its key
.
The cart may not contain up-to-date prices, discounts etc. If you want to ensure they're up-to-date, send an Update request with the Recalculate update action instead.
Get a Cart in a Store by ID
Endpoint: /{projectKey}/in-store/key={storeKey}/carts/{id}
Method: GET
OAuth 2.0 Scopes: view_orders:{projectKey}
, view_orders:{projectKey}:{storeKey}
Response Representation: Cart
Returns a cart by its ID from a specific Store. The {storeKey}
path parameter maps to a Store's key
.
If the cart exists in the commercetools project but does not have the store
field, or the store
field references a different store, this method returns a ResourceNotFound error.
The cart may not contain up-to-date prices, discounts etc. If you want to ensure they're up-to-date, send an Update request with the Recalculate update action instead.
Get a Cart in a Store by Key
Endpoint: /{projectKey}/in-store/key={storeKey}/carts/key={key}
Method: GET
OAuth 2.0 Scopes: view_orders:{projectKey}
, view_orders:{projectKey}:{storeKey}
Response Representation: Cart
Returns a cart by its key
from a specific Store. The {storeKey}
path parameter maps to a Store's key
.
If the cart exists in the commercetools project but does not have the store
field, or the store
field references a different store, this method returns a ResourceNotFound error.
The cart may not contain up-to-date prices, discounts etc. If you want to ensure they're up-to-date, send an Update request with the Recalculate update action instead.
Get a Cart by Customer ID
Endpoint: /{projectKey}/carts/customer-id={id}
Method: GET
OAuth 2.0 Scopes: view_orders:{projectKey}
Response Representation: Cart
Retrieves the active cart of the customer that has been modified most recently. It does not consider carts with CartOrigin Merchant. If no active cart exists, a 404 Not Found error is returned.
The cart may not contain up-to-date prices, discounts etc. If you want to ensure they're up-to-date, send an Update request with the Recalculate update action.
Get a Cart in a Store by Customer ID
Endpoint: /{projectKey}/in-store/key={storeKey}/carts/customer-id={id}
Method: GET
OAuth 2.0 Scopes: view_orders:{projectKey}
, view_orders:{projectKey}:{storeKey}
Response Representation: Cart
Retrieves the active cart of the customer that has been modified most recently in a specific Store. The {storeKey}
path parameter maps to a Store's key
.
If the cart exists in the commercetools project but does not have the store
field, or the store
field references a different store, this method returns a ResourceNotFound error.
The cart may not contain up-to-date prices, discounts etc. If you want to ensure they're up-to-date, send an Update request with the Recalculate update action.
Query Carts
Query Carts
Endpoint: /{projectKey}/carts
Method: GET
OAuth 2.0 Scopes: view_orders:{projectKey}
Response Representation: PagedQueryResult with results
containing an array of Cart
Query Parameters:
where
- Query Predicate - Optionalsort
- Sort - Optionalexpand
- Expansion - Optionallimit
- Number - Optionaloffset
- Number - Optional
Query Carts in a Store
Endpoint: /{projectKey}/in-store/key={storeKey}/carts
Method: GET
OAuth 2.0 Scopes: view_orders:{projectKey}
, view_orders:{projectKey}:{storeKey}
Response Representation: PagedQueryResult with results
containing an array of Cart
Query Parameters:
where
- Query Predicate - Optionalsort
- Sort - Optionalexpand
- Expansion - Optionallimit
- Number - Optionaloffset
- Number - Optional
Queries carts in a specific Store. The {storeKey}
path parameter maps to a Store's key
.
Create a Cart
Create a Cart
Endpoint: /{projectKey}/carts
Method: POST
OAuth 2.0 Scopes: manage_orders:{projectKey}
Request Representation: CartDraft
Response Representation: Cart
Creating a cart can fail with an InvalidOperation if the referenced shipping method in the CartDraft has a predicate which does not match the cart.
Create a Cart in a Store
Endpoint: /{projectKey}/in-store/key={storeKey}/carts
Method: POST
OAuth 2.0 Scopes: manage_orders:{projectKey}
, manage_orders:{projectKey}:{storeKey}
Request Representation: CartDraft
Response Representation: Cart
Creates a cart in the store specified by {storeKey}
. The {storeKey}
path parameter maps to a Store's key
.
When using this endpoint the cart's store
field is always set to the store specified in the path parameter.
Creating a cart can fail with an InvalidOperation if the referenced shipping method in the CartDraft has a predicate which does not match the cart.
Update a Cart
After all update actions have been performed, the cart will also:
- Remove any line items that are invalid (due to removed products, product variants, or prices)
- Update any line item
price
fields if the result of the price selection has changed because of a product update - Update the ShippingInfo, in particular the
price
andshippingMethodState
fields - Update the discounts, which may affect the
totalPrice
fields of (custom) line items and thediscountedPrice
field of the shipping info - Update the
totalPrice
field of the cart - Update the tax rates, in particular the
taxedPrice
fields - Update the
productKey
on line items
If you want to perform the updates mentioned above without additional update actions, you can send a request with only the Recalculate update action.
To update the product data saved in the line items, use the Recalculate update action with updateProductData
set to true
.
Update a Cart by ID
Endpoint: /{projectKey}/carts/{id}
Method: POST
OAuth 2.0 Scopes: manage_orders:{projectKey}
Response Representation: Cart
Fields:
version
- Number - Required
The expected version of the cart on which the changes should be applied. If the expected version does not match the actual version, a 409 Conflict will be returned.actions
- Array of UpdateAction - Required
The list of update actions to be performed on the cart.
Update a Cart by Key
Endpoint: /{projectKey}/carts/key={key}
Method: POST
OAuth 2.0 Scopes: manage_orders:{projectKey}
Response Representation: Cart
Fields:
version
- Number - Required
The expected version of the cart on which the changes should be applied. If the expected version does not match the actual version, a 409 Conflict will be returned.actions
- Array of UpdateAction - Required
The list of update actions to be performed on the cart.
Updates the cart by its key
.
Update a Cart in a Store by ID
Endpoint: /{projectKey}/in-store/key={storeKey}/carts/{id}
Method: POST
OAuth 2.0 Scopes: manage_orders:{projectKey}
, manage_orders:{projectKey}:{storeKey}
Response Representation: Cart
Fields:
version
- Number - Required
The expected version of the cart on which the changes should be applied. If the expected version does not match the actual version, a 409 Conflict will be returned.actions
- Array of UpdateAction - Required
The list of update actions to be performed on the cart.
Updates a cart in the store specified by {storeKey}
. The {storeKey}
path parameter maps to a Store's key
.
If the cart exists in the commercetools project but does not have the store
field, or the store
field references a different store, this method returns a ResourceNotFound error.
Update a Cart in a Store by Key
Endpoint: /{projectKey}/in-store/key={storeKey}/carts/key={key}
Method: POST
OAuth 2.0 Scopes: manage_orders:{projectKey}
, manage_orders:{projectKey}:{storeKey}
Response Representation: Cart
Fields:
version
- Number - Required
The expected version of the cart on which the changes should be applied. If the expected version does not match the actual version, a 409 Conflict will be returned.actions
- Array of UpdateAction - Required
The list of update actions to be performed on the cart.
Updates a cart in the store specified by {storeKey}
and Cart key
.
If the cart exists in the commercetools project but does not have the store
field, or the store
field references a different store, this method returns a ResourceNotFound error.
Update actions
Set Key
action
- String -"setKey"
key
- String - Optional
Ifkey
is absent ornull
, the existing key, if any, will be removed.
UpdateAction on line item
Add LineItem
Adds a product variant in the given quantity to the cart.
If the cart already contains a line item for the same product variant with the same LineItemMode, custom fields, supply, and distribution channel, then only the quantity of the existing LineItem is increased.
If shippingDetails
are set, they will be merged, meaning all addresses will be present afterwards and, for address keys present in both shipping details, the quantity will be summed up.
A new line item will always be added when the externalPrice
or the externalTotalPrice
is set in this update action.
The LineItem price is set as described in LineItem Price selection.
action
- String -"addLineItem"
- LineItemDraft - Required
Specific Error Codes:
Remove LineItem
Decreases the quantity of the given LineItem. The LineItem price is updated as described in LineItem Price selection.
action
- String -"removeLineItem"
lineItemId
- String - Required
ID of an existing LineItem in the cart.quantity
- Number - Optional If the quantity is absent or the line item quantity drops to less than1
, the line item is removed from the cart.externalPrice
- Money - Optional
Sets the line itemprice
to the given value when decreasing the quantity of a line item with theExternalPrice
LineItemPriceModepriceMode
.externalTotalPrice
- ExternalLineItemTotalPrice - Optional
Sets the line itemprice
andtotalPrice
to the given values when decreasing the quantity of a line item with theExternalTotal
LineItemPriceModepriceMode
.shippingDetailsToRemove
- ItemShippingDetailsDraft - Optional
Container for line item specific address(es) that are to be removed.
Change LineItem Quantity
Sets the quantity of the given LineItem.
If quantity is 0
, the line item is removed from the cart.
The LineItem price is updated as described in LineItem Price selection.
ChangeLineItemQuantity does not support changing the shipping details when multiple shipping addresses are set for one line item. RemoveLineItem and AddLineItem support this, but not ChangeLineItem.
This is the case because it is not possible to deduct how the distribution of sub-quantities should be adapted in accordance with the overall change in the line item quantity.
Thus, the shippingDetails
field will be kept in its current state to avoid data loss.
Use SetLineItemShippingDetails in combination with this update action in one cart update command to change the line item quantity and shipping details together.
action
- String -"changeLineItemQuantity"
lineItemId
- String - Required
ID of an existing LineItem in the cart.quantity
- Number - RequiredexternalPrice
- Money - Optional
Sets the line itemprice
to the given value when changing the quantity of a line item with theExternalPrice
LineItemPriceModepriceMode
.externalTotalPrice
- ExternalLineItemTotalPrice - Optional
Sets the line itemprice
andtotalPrice
to the given values when changing the quantity of a line item with theExternalTotal
LineItemPriceModepriceMode
.
Set LineItem TaxRate
A line item tax rate can be set if the cart has the External
TaxMode.
action
- String -"setLineItemTaxRate"
lineItemId
- StringexternalTaxRate
- ExternalTaxRateDraft - Optional
Set LineItem TaxAmount
A line item tax amount can be set if the cart has the ExternalAmount
TaxMode.
action
- String -"setLineItemTaxAmount"
lineItemId
- StringexternalTaxAmount
- ExternalTaxAmountDraft - Optional
Set LineItem Price
Sets the price
of a line item and changes the priceMode
of the line item to ExternalPrice
LineItemPriceMode.
If the price mode of the line item is ExternalPrice
and no externalPrice
is given, the external price is unset
and the priceMode
is set to Platform
.
action
- String -"setLineItemPrice"
lineItemId
- StringexternalPrice
- Money - Optional
Set LineItem TotalPrice
Sets the totalPrice
and price
of a line item and changes the priceMode
of the line item to ExternalTotal
LineItemPriceMode.
If the price mode of the line item is ExternalTotal
and no externalTotalPrice
is given, the external price is unset
and the priceMode
is set to Platform
.
action
- String -"setLineItemTotalPrice"
lineItemId
- StringexternalTotalPrice
- ExternalLineItemTotalPrice - Optional
Set LineItem DistributionChannel
Sets the distribution channel of the given LineItem.
The LineItem price is updated as described in LineItem Price selection.
action
- String -"setLineItemDistributionChannel"
lineItemId
- String - Required
ID of an existing LineItem in the cart.distributionChannel
- ResourceIdentifier of a Channel - Optional
If present a Reference to the channel will be set for the LineItem specified bylineItemId
. If not present the current Reference to a distribution channel will be removed from the LineItem specified bylineItemId
. The Channel must have theProductDistribution
ChannelRoleEnum
Set LineItem SupplyChannel
Sets the supply channel of the given LineItem.
action
- String -"setLineItemSupplyChannel"
lineItemId
- String - Required
ID of an existing LineItem in the cart.supplyChannel
- ResourceIdentifier of a Channel - Optional
If present a Reference to the channel will be set for the LineItem specified bylineItemId
. If not present the current Reference to a supply channel will be removed from the LineItem specified bylineItemId
. The Channel must have theInventorySupply
ChannelRoleEnum. Performing this action has no impact on inventory that should be reserved.
Set LineItem Custom Type
This action sets, overwrites, or removes the custom type and fields for an existing LineItem.
action
- String -"setLineItemCustomType"
type
- ResourceIdentifier of a Type - Optional
If set, the custom type is set to this new value.
If absent, the custom type and any existing CustomFields are removed at the same time.lineItemId
- Stringfields
- A valid JSON object, based on the FieldDefinitions of the Type - Optional
If set, the custom fields are set to this new value.
Set LineItem CustomField
This action sets, overwrites, or removes any existing custom field for an existing LineItem.
action
- String -"setLineItemCustomField"
lineItemId
- Stringname
- String - Requiredvalue
- Value - Optional
Ifvalue
is absent ornull
, this field will be removed if it exists. Trying to remove a field that does not exist will fail with an InvalidOperation error. Ifvalue
is provided, set thevalue
of the field defined by thename
.
Apply DeltaToLineItemShippingDetailsTargets
Increases or decreases the shipping details, the amount of items going to which address, for a line item. See SetLineItemShippingDetails to override the shipping details.
action
- String -"applyDeltaToLineItemShippingDetailsTargets"
lineItemId
- String
The ID of the line item that is to be updated.targetsDelta
- Array of ItemShippingTarget
Using positive quantities will increase the amount of items which should go to an address, and negative quantities decrease the amount.
Set LineItemShippingDetails
Sets the ItemShippingDetails for a line item.
action
- String -"setLineItemShippingDetails"
lineItemId
- String
The ID of the line item that is to be updated.shippingDetails
- ItemShippingDetailsDraft - Optional
The new shipping details for the line item.
UpdateAction on custom line item
Add CustomLineItem
Adds a CustomLineItem to the cart.
If the cart already contains a CustomLineItem with the same slug, name, money, tax category, state, and custom fields, then only the quantity of the existing custom line item is increased.
If shippingDetails
are set, they will be merged, meaning all addresses will be present afterwards and, for address keys present in both shipping details, the quantity will be summed up.
If the cart already contains a custom line item with the same slug that is otherwise not identical, an InvalidOperation error is returned.
action
- String -"addCustomLineItem"
name
- LocalizedStringquantity
- Number - Optional - Defaults to1
money
- Moneyslug
- StringtaxCategory
- ResourceIdentifier to a TaxCategory - Required only forPlatform
TaxMode
The given tax category will be used to select a tax rate when a cart has the tax modePlatform
.externalTaxRate
- ExternalTaxRateDraft - Optional
An external tax rate can be set if the cart has theExternal
TaxMode.custom
- CustomFieldsDraft - Optional
The custom fields.shippingDetails
- ItemShippingDetailsDraft - Optional
Container for custom line item specific address(es).
Specific Error Codes:
Remove CustomLineItem
Removes the custom CustomLineItem from the cart.
Removing a custom line item does not support specifying a quantity, unlike the removal of line items. It's not possible to partially remove shippingDetails
using this update action. See Change CustomLineItem Quantity for that.
action
- String -"removeCustomLineItem"
customLineItemId
- String - Required
ID of an existing CustomLineItem in the cart.
Change CustomLineItem Quantity
Sets the quantity of the given CustomLineItem.
ChangeCustomLineItemQuantity does not support changing the shipping details when multiple shipping addresses are set for one custom line item. AddCustomLineItem support this.
This is the case because it is not possible to deduct how the distribution of sub-quantities should be adapted in accordance with the overall change in the custom line item quantity.
Thus, the shippingDetails
field will be kept in its current state to avoid data loss.
Use SetCustomLineItemShippingDetails in combination with this update action in one cart update command to change the custom line item quantity and shipping details together.
action
- String -"changeCustomLineItemQuantity"
customLineItemId
- String - Required
ID of an existing CustomLineItem in the cart.quantity
- Number - Required
The new quantity being a value >= 0. If quantity is0
, the custom line item will be removed from the cart.
Change CustomLineItem Money
Sets the money of the given CustomLineItem.
action
- String -"changeCustomLineItemMoney"
customLineItemId
- String - Required
ID of an existing CustomLineItem in the cart.money
- Money - Required
The new money.
Set CustomLineItem Custom Type
This action sets, overwrites, or removes the custom type and fields for an existing CustomLineItem.
action
- String -"setCustomLineItemCustomType"
type
- ResourceIdentifier to a Type - Optional
If set, the custom type is set to this new value.
If absent, the custom type and any existing CustomFields are removed at the same time.customLineItemId
- Stringfields
- A valid JSON object, based on the FieldDefinitions of the Type - Optional
If set, the custom fields are set to this new value.
Set CustomLineItem CustomField
This action sets, overwrites, or removes any existing custom field for an existing CustomLineItem.
action
- String -"setCustomLineItemCustomField"
customLineItemId
- Stringname
- String - Requiredvalue
- Value - Optional
Ifvalue
is absent ornull
, this field will be removed if it exists. Trying to remove a field that does not exist will fail with an InvalidOperation error. Ifvalue
is provided, set thevalue
of the field defined by thename
.
Set CustomLineItem TaxRate
A custom line item tax rate can be set if the cart has the External
TaxMode.
action
- String -"setCustomLineItemTaxRate"
customLineItemId
- StringexternalTaxRate
- ExternalTaxRateDraft - Optional
Set CustomLineItem TaxAmount
A custom line item tax amount can be set if the cart has the ExternalAmount
TaxMode.
action
- String -"setCustomLineItemTaxAmount"
customLineItemId
- StringexternalTaxAmount
- ExternalTaxAmountDraft - Optional
Apply DeltaToCustomLineItemShippingDetailsTargets
Increases or decreases the shipping details, the amount of items going to which address, for a line item.
action
- String -"applyDeltaToCustomLineItemShippingDetailsTargets"
customLineItemId
- String
The ID of the custom line item that is to be updated.targetsDelta
- Array of ItemShippingTarget
Using positive quantities will increase the amount of items which should go to an address, and negative quantities decrease the amount.
Set CustomLineItemShippingDetails
Sets the ItemShippingDetails for a custom line item.
action
- String -"setCustomLineItemShippingDetails"
customLineItemId
- String
The ID of the custom line item that is to be updated.shippingDetails
- ItemShippingDetailsDraft - Optional
The new shipping details for the custom line item.
Set Customer Email
action
- String -"setCustomerEmail"
email
- String - Optional
Set Shipping Address
Sets the shipping address of the cart. Setting the shipping address also sets the TaxRate of the line items
and calculates the TaxedPrice. If the address is not provided, the shipping address is unset, the taxedPrice
is unset
and the taxRates
are unset in all line items.
action
- String -"setShippingAddress"
address
- AddressDraft - Optional
Extended flexibility on taxRates
selection is possible when countryTaxRateFallbackEnabled project setting
is set to true
, which allows shipping to states not explicitly covered inside a country. For more information, see changeCountryTaxRateFallbackEnabled.
Specific Error Codes:
- MissingTaxRateForCountry
You could changeCountryTaxRateFallbackEnabled to allow extended tax rate selection.
Set Billing Address
action
- String -"setBillingAddress"
address
- AddressDraft - Optional
Set Country
Sets the country of the cart. When the country is set, the LineItem prices are updated.
action
- String -"setCountry"
country
- String - Optional
A two-digit country code as per ISO 3166-1 alpha-2.
Set ShippingMethod
Sets the ShippingMethod. Prerequisite: The cart must contain a shipping address. This update action can fail with an InvalidOperation if the referenced shipping method has a predicate which does not match the cart.
action
- String -"setShippingMethod"
shippingMethod
- ResourceIdentifier to a ShippingMethod - OptionalexternalTaxRate
- ExternalTaxRateDraft - Optional
An external tax rate can be set if the cart has theExternal
TaxMode.
Set Custom ShippingMethod
Sets a custom shipping method (independent of the ShippingMethods defined in the project). The custom shipping method can be unset with the setShippingMethod
action without the shippingMethod
. Prerequisite: The cart must contain a shipping address.
action
- String -"setCustomShippingMethod"
shippingMethodName
- String - RequiredshippingRate
- ShippingRateDraft - Required
The shipping rate used to determine the price.taxCategory
- ResourceIdentifier to a TaxCategory - Optional
The given tax category will be used to select a tax rate when a cart has the TaxModePlatform
.externalTaxRate
- ExternalTaxRateDraft - Optional
An external tax rate can be set if the cart has theExternal
TaxMode.
Add DiscountCode
Adds a DiscountCode to the cart to enable the related CartDiscounts.
action
- String -"addDiscountCode"
code
- String - Required
Thecode
of an existing DiscountCode.
The number of discount codes in a cart is limited to 10.
Specific Error Codes:
Remove DiscountCode
Removes a discount code from the cart.
action
- String -"removeDiscountCode"
discountCode
- Reference to a DiscountCode - Required
Set Customer Group
Sets the customer group of the cart. The LineItem prices will be updated according to the customer group.
This action cannot be used if a customer is assigned to the cart. In that case the platform will automatically select the customer group the respective customer is assigned to.
action
- String -"setCustomerGroup"
customerGroup
- ResourceIdentifier to a CustomerGroup - Optional
Set Custom Type
This action sets, overwrites, or removes any existing custom type and fields for an existing cart.
action
- String -"setCustomType"
type
- ResourceIdentifier to a Type - Optional
If set, the custom type is set to this new value.
If absent, the custom type and any existing custom fields are removed.fields
- A valid JSON object, based on the FieldDefinitions of the Type - Optional
If set, the custom fields are set to this new value.
Set CustomField
This action sets, overwrites, or removes any existing custom field for an existing cart.
action
- String -"setCustomField"
name
- String - Requiredvalue
- Value - Optional
Ifvalue
is absent ornull
, this field will be removed if it exists. Trying to remove a field that does not exist will fail with an InvalidOperation error. Ifvalue
is provided, set thevalue
of the field defined by thename
.
Set Shipping Address Custom Type
This action sets, overwrites, or removes any existing custom type and fields for an existing shippingAddress
.
action
- String -"setShippingAddressCustomType"
type
- ResourceIdentifier to a Type - Optional
If set, the custom type is set to this new value.
If absent, the custom type and any existing custom fields are removed.fields
- A valid JSON object, based on the FieldDefinitions of the Type - Optional
If set, the custom fields are set to this new value.
Set Shipping Address CustomField
This action sets, overwrites, or removes any existing custom field for an existing shippingAddress
.
action
- String -"setShippingAddressCustomField"
name
- String - Required
The name of the Custom Field to setvalue
- Value - Optional
Specifies the format of the value of the Custom Field defined byname
. Ifvalue
is absent ornull
, the field specified byname
, if it exists, is removed. Trying to remove a field that does not exist will fail with an InvalidOperation error.
Set Billing Address Custom Type
This action sets, overwrites, or removes any existing custom type and fields for an existing billingAddress
.
action
- String -"setBillingAddressCustomType"
type
- ResourceIdentifier to a Type - Optional
If set, the custom type is set to this new value. If absent, the custom type and any existing custom fields are removed.fields
- A valid JSON object, based on the FieldDefinitions of the Type - Optional
If set, the custom fields are set to this new value.
Set Billing Address CustomField
This action sets, overwrites, or removes any existing custom field for an existing billingAddress
.
action
- String -"setBillingAddressCustomField"
name
- String - Required
The name of the Custom Field to setvalue
- Value - Optional
Specifies the format of the value of the Custom Field defined byname
. Ifvalue
is absent ornull
, the field specified byname
, if it exists, is removed. Trying to remove a field that does not exist will fail with an InvalidOperation error.
Set ItemShipping Address Custom Type
This action sets, overwrites, or removes any existing custom type and fields for an existing itemShippingAddress
.
action
- String -"setItemShippingAddressCustomType"
addressKey
- String - Requiredtype
- ResourceIdentifier to a Type - Optional
If set, the custom type is set to this new value.
If absent, the custom type and any existing custom fields are removed.fields
- A valid JSON object, based on the FieldDefinitions of the Type - Optional
If set, the custom fields are set to this new value.
Set ItemShipping Address CustomField
This action sets, overwrites, or removes any existing custom field for an existing itemShippingAddress
.
action
- String -"setItemShippingAddressCustomField"
addressKey
- String - Requiredname
- String - Required
The name of the Custom Field to setvalue
- Value - Optional
Specifies the format of the value of the Custom Field defined byname
. Ifvalue
is absent ornull
, the field specified byname
, if it exists, is removed. Trying to remove a field that does not exist will fail with an InvalidOperation error.
Set Delivery Address Custom Type
This action sets, overwrites, or removes any existing custom type and fields for an existing address
in a Delivery.
action
- String -"setDeliveryAddressCustomType"
deliveryId
- String - Requiredtype
- ResourceIdentifier to a Type - Optional
If set, the custom type is set to this new value.
If absent, the custom type and any existing custom fields are removed.fields
- A valid JSON object, based on the FieldDefinitions of the Type - Optional
If set, the custom fields are set to this new value.
Set Delivery Address CustomField
This action sets, overwrites, or removes any existing custom field for an existing address
in a Delivery.
action
- String -"setDeliveryAddressCustomField"
deliveryId
- String - Requiredname
- String - Required
The name of the Custom Field to setvalue
- Value - Optional
Specifies the format of the value of the Custom Field defined byname
. Ifvalue
is absent ornull
, the field specified byname
, if it exists, is removed. Trying to remove a field that does not exist will fail with an InvalidOperation error.
Set ShippingMethod TaxAmount
A shipping method tax amount can be set if the cart has the ExternalAmount
TaxMode.
action
- String -"setShippingMethodTaxAmount"
externalTaxAmount
- ExternalTaxAmountDraft - Optional
Set ShippingMethod TaxRate
A shipping method tax rate can be set if the cart has the External
TaxMode.
action
- String -"setShippingMethodTaxRate"
externalTaxRate
- ExternalTaxRateDraft - Optional
Change TaxMode
Changes the TaxMode of a cart. When a tax mode is changed from External
to Platform
or Disabled
,
all previously set external tax rates will be removed. When changing the tax mode to Platform
, line items,
custom line items and shipping method require a tax category with a tax rate for the given shipping address.
action
- String -"changeTaxMode"
taxMode
- TaxMode
Change Tax RoundingMode
Changes the tax RoundingMode of a cart. When changing the tax rounding mode, the taxes are recalculated.
action
- String -"changeTaxRoundingMode"
taxRoundingMode
- RoundingMode
Set ShippingRateInput
The shippingRateInput
is used as an input to select a ShippingRatePriceTier. If no matching tier can be found, or the input is not set, the default price is used.
action
- String -"setShippingRateInput"
shippingRateInput
- ShippingRateInputDraft - Optional
Based on the definition of ShippingRateInputType. If CartClassification is defined, it must be ClassificationShippingRateInput. If CartScore is defined, it must be ScoreShippingRateInput. Otherwise it can not bet set.
Change TaxCalculationMode
Changes the TaxCalculationMode of a cart. When changing the tax calculation mode, the taxes are recalculated.
action
- String -"changeTaxCalculationMode"
taxCalculationMode
- TaxCalculationMode
Add Shopping List
Adds all LineItems of a ShoppingList to the cart.
action
- String -"addShoppingList"
shoppingList
- ResourceIdentifier of a ShoppingListsupplyChannel
- ResourceIdentifier of a Channel - Optional
If present a Reference to the channel will be set for all LineItems that are added to the cart.
The channel must have theInventorySupply
channelRoleEnum.distributionChannel
- ResourceIdentifier of a Channel - Optional
If present a Reference to the channel will be set for all LineItems that are added to the cart.
The Channel must have theProductDistribution
ChannelRoleEnum
Set Customer ID
Sets the customer ID of the cart. When the customer ID is set, the LineItem prices are updated.
action
- String -"setCustomerId"
customerId
- String - Optional
If set, a customer with the given ID must exist in the project.
Specific Error Codes:
Set Anonymous ID
Sets the anonymous ID of the cart.
action
- String -"setAnonymousId"
anonymousId
- String - Optional
If not set, any existing anonymous ID will be removed.
Recalculate
This update action has two use cases:
Updating the product data that is saved in line items
Updating prices, discounts etc. as done on every update, but without sending additional update actions
action
- String -"recalculate"
updateProductData
- Boolean - Optional, defaults tofalse
If set totrue
, the line item product data (name
,variant
andproductType
) will also be updated. If set tofalse
, only the prices and tax rates of the line item will be updated. The updated price of a line item may not correspond to a price invariant.prices
anymore.
Add Payment
This action adds a payment to the PaymentInfo. The payment must not be assigned to another Order or active Cart yet.
Remove Payment
This action removes a payment from the PaymentInfo.
Set Cart Total Tax
The total tax amount of the cart can be set if it has the ExternalAmount
TaxMode.
action
- String -"setCartTotalTax"
externalTotalGross
- Money
The total gross amount of the cart (totalNet + taxes).externalTaxPortions
- Array of TaxPortion - Optional
Set Locale
Sets the locale. Must be one of the languages supported for this Project.
action
- String -"setLocale"
locale
- String conforming to IETF language tag - Optional
Set DeleteDaysAfterLastModification
Sets deleteDaysAfterLastModification
. The cart will be deleted automatically if it hasn't been modified for the specified amount of days. If a ChangeSubscription for carts exists, a ResourceDeleted
notification will be sent.
action
- String -"setDeleteDaysAfterLastModification"
deleteDaysAfterLastModification
- Number - Optional
Add ItemShippingAddress
Add an address to the itemShippingAddresses
array.
action
- String -"addItemShippingAddress"
address
- AddressDraft
The address must have a key that is unique in this cart/order.
Remove ItemShippingAddress
Removes an address from the itemShippingAddresses
array. An address can only be removed if it is not referenced in any ItemShippingTarget.
action
- String -"removeItemShippingAddress"
addressKey
- String
The key of the address that is to be removed
Update ItemShippingAddress
Updates an address in the itemShippingAddresses
array.
action
- String -"updateItemShippingAddress"
address
- AddressDraft
The address which is to replace the address with the key already present in the array
Overview of update actions for Cart, Order and OrderEdit
Update Action | Cart | direct Order | OrderEdit |
---|---|---|---|
setKey | ✓ | ||
setCustomerEmail | ✓ | ✓ | ✓ |
setShippingAddress | ✓ | ✓ | ✓ |
setBillingAddress | ✓ | ✓ | ✓ |
setCountry | ✓ | - | ✓ |
recalculate | ✓ | - | - |
setShippingMethod | ✓ | - | ✓ |
setCustomShippingMethod | ✓ | - | ✓ |
addDiscountCode | ✓ | - | ✓ |
removeDiscountCode | ✓ | - | ✓ |
setCustomerId | ✓ | ✓ | ✓ |
setAnonymousId | ✓ | - | - |
setCustomerGroup | ✓ | - | ✓ |
setCustomType | ✓ | ✓ | ✓ |
setCustomField | ✓ | ✓ | ✓ |
addPayment | ✓ | ✓ | ✓ |
removePayment | ✓ | ✓ | ✓ |
setShippingMethodTaxRate | ✓ | - | ✓ |
setShippingMethodTaxAmount | ✓ | - | ✓ |
setCartTotalTax | ✓ | - | - |
setOrderTotalTax | - | - | ✓ |
changeTaxMode | ✓ | - | ✓ |
setLocale | ✓ | ✓ | ✓ |
changeTaxRoundingMode | ✓ | - | ✓ |
setShippingRateInput | ✓ | - | ✓ |
changeTaxCalculationMode | ✓ | - | ✓ |
addShoppingList | ✓ | - | ✓ |
setDeleteDaysAfterLastModification | ✓ | - | - |
addItemShippingAddress | ✓ | ✓ | ✓ |
removeItemShippingAddress | ✓ | ✓ | ✓ |
updateItemShippingAddress | ✓ | ✓ | ✓ |
setShippingAddressAndShippingMethod | - | - | ✓ |
setShippingAddressAndCustomShippingMethod | - | - | ✓ |
LineItem update actions | |||
applyDeltaToLineItemShippingDetailsTargets | ✓ | - | - |
setLineItemShippingDetails | ✓ | ✓ | ✓ |
addLineItem | ✓ | - | ✓ |
removeLineItem | ✓ | - | ✓ |
changeLineItemQuantity | ✓ | - | ✓ |
setLineItemCustomType | ✓ | ✓ | ✓ |
setLineItemCustomField | ✓ | ✓ | ✓ |
setShippingAddressCustomType | ✓ | ✓ | ✓ |
setShippingAddressCustomField | ✓ | ✓ | ✓ |
setBillingAddressCustomType | ✓ | ✓ | ✓ |
setBillingAddressCustomField | ✓ | ✓ | ✓ |
setItemShippingAddressCustomType | ✓ | ✓ | ✓ |
setItemShippingAddressCustomField | ✓ | ✓ | ✓ |
setDeliveryAddressCustomType | ✓ | ✓ | ✓ |
setDeliveryAddressCustomField | ✓ | ✓ | ✓ |
setDeliveryCustomType | - | ✓ | ✓ |
setDeliveryCustomField | - | ✓ | ✓ |
setParcelCustomType | - | ✓ | ✓ |
setParcelCustomField | - | ✓ | ✓ |
setReturnItemCustomType | - | ✓ | ✓ |
setReturnItemCustomField | - | ✓ | ✓ |
setLineItemTaxRate | ✓ | - | ✓ |
setLineItemTaxAmount | ✓ | - | ✓ |
setLineItemTotalPrice | ✓ | - | ✓ |
setLineItemPrice | ✓ | - | ✓ |
setLineItemDistributionChannel | ✓ | - | ✓ |
CustomLineItem update actions | |||
applyDeltaToCustomLineItemShippingDetailsTargets | ✓ | - | - |
setCustomLineItemShippingDetails | ✓ | - | - |
addCustomLineItem | ✓ | - | ✓ |
removeCustomLineItem | ✓ | - | ✓ |
setCustomLineItemCustomType | ✓ | ✓ | ✓ |
setCustomLineItemCustomField | ✓ | ✓ | ✓ |
setCustomLineItemTaxAmount | ✓ | - | ✓ |
setCustomLineItemTaxRate | ✓ | - | ✓ |
changeCustomLineItemQuantity | ✓ | - | ✓ |
changeCustomLineItemMoney | ✓ | - | ✓ |
Replicate an existing cart or order to a new cart
Creating a new cart by replicating an existing cart or order can be useful in case a customer wants to cancel a recent order to make some changes, or if a previous order should be ordered again.
The replica will attempt to preserve customer information, line items and custom line items, custom fields, discount codes, as well as other settings of the cart or order. If any of the line items have become invalid, for example due to removed products or prices, those items are removed from the new cart. If the customer has switched to another customer group, the new cart contains the new group.
The replica has up-to-date tax rates, prices, and line item product data and is in Active
CartState.
The new cart does not contain payments or deliveries. The state of line items and custom line items is reset to the initial state.
Replicate a Cart
Endpoint: /{projectKey}/carts/replicate
Method: POST
OAuth 2.0 Scopes: manage_orders:{projectKey}
Request Representation: ReplicaCartDraft
Response Representation: Cart
The replica will not be bound to any store.
Replicate a Cart in a Store
Endpoint: /{projectKey}/in-store/key={storeKey}/carts/replicate
Method: POST
OAuth 2.0 Scopes: manage_orders:{projectKey}
, manage_orders:{projectKey}:{storeKey}
Request Representation: ReplicaCartDraft
Response Representation: Cart
The replica will be bound to the same store.
Delete a Cart
Delete a Cart by ID
Endpoint: /{projectKey}/carts/{id}
Method: DELETE
OAuth 2.0 Scopes: manage_orders:{projectKey}
Response Representation: Cart
Query parameters:
version
- Number - RequireddataErasure
- Boolean - Optional, defaults tofalse
Removes a Cart.
Delete a Cart by Key
Endpoint: /{projectKey}/carts/key={key}
Method: DELETE
OAuth 2.0 Scopes: manage_orders:{projectKey}
Response Representation: Cart
Query parameters:
version
- Number - RequireddataErasure
- Boolean - Optional, defaults tofalse
Delete a Cart in a Store by ID
Endpoint: /{projectKey}/in-store/key={storeKey}/carts/{id}
Method: DELETE
OAuth 2.0 Scopes: manage_orders:{projectKey}
, manage_orders:{projectKey}:{storeKey}
Response Representation: Cart
Query parameters:
version
- Number - RequireddataErasure
- Boolean - Optional, defaults tofalse
Removes a Cart in the store specified by {storeKey}
. The {storeKey}
path parameter maps to a Store's key
.
If the cart exists in the commercetools project but does not have the store
field, or the store
field references a different store, this method returns a ResourceNotFound error.
Delete a Cart in a Store by Key
Endpoint: /{projectKey}/in-store/key={storeKey}/carts/key={key}
Method: DELETE
OAuth 2.0 Scopes: manage_orders:{projectKey}
, manage_orders:{projectKey}:{storeKey}
Response Representation: Cart
Query parameters:
version
- Number - RequireddataErasure
- Boolean - Optional, defaults tofalse
Removes a Cart in the store specified by {storeKey}
and Cart key
.
The {storeKey}
path parameter maps to a Store's key
.
If the cart exists in the commercetools project but does not have the store
field, or the store
field references a different store, this method returns a ResourceNotFound error.