Carts and Orders overview

Ask about this Page
Copy for AI
View as Markdown

Learn how Carts hold what a customer wants to buy, how Orders record the purchase, and how both fit into checkout.

A purchase starts with what a customer wants to buy and ends with a record of what they bought. A Cart holds the items while the customer shops and goes through checkout. An Order records the purchase when the customer completes checkout, and a Payment records how the customer paid for it. A business uses Carts and Orders to let customers shop with or without an account, keep prices stable during checkout, create Orders from Carts and Quotes, and correct Orders after purchase. This area covers Carts, Line Items, Orders, and Payments, and how Orders are created and updated.

You can work with Carts and Orders in the Merchant Center or with the APIs:

Key concepts

Carts

A Cart holds the items a customer wants to buy. A Product Variant is called a Line Item once it is added to a Cart. A Cart can also hold Custom Line Items. During checkout, the Cart is ordered, which creates an Order. A Cart can belong to a signed-in Customer, to an anonymous visitor, and to a Store or a Business Unit.
A Cart that can be updated and ordered is in the Active state and is known as an active Cart. A Customer can have more than one active Cart. For the other states of a Cart, see Cart states.

For example, a customer adds a jacket and a scarf to a Cart in a webshop. When the customer checks out, the Cart is ordered and the business receives an Order for the two items.

Line Items

A Line Item is a snapshot of a Product Variant at the time it is added to a Cart. If the Product Variant changes later, the Line Item isn't updated automatically. The Product data of a Line Item is refreshed only in specific cases: when the Cart is recalculated with updated Product data, when a Cart update triggers a custom business logic check, or when a Customer signs in or Carts are merged with updated Product data requested. A Cart that contains Line Items that reference deleted Product Variants can't be used to create Orders.

For example, a customer adds a pair of shoes to a Cart. The business changes the Product's description the next day. The Line Item still shows the data from the time the customer added the shoes, unless the Cart is explicitly recalculated with updated Product data.

Custom Line Items

A Custom Line Item is a generic item that isn't associated with a Product Variant. A business uses it to sell services or virtual goods that don't need inventory tracking, such as additional fees or vouchers.

A business adds Custom Line Items to a Cart in the same way as Line Items. However, Line Item price selection doesn't apply to Custom Line Items. Instead, the business controls the price and taxes of the item. The monetary value of a Custom Line Item can be negative, so a business can use it for discounts that vouchers give. A business can also use Custom Line Items together with Cart Predicates to implement more complex Cart logic. The inventory mode of the Cart has no effect on Custom Line Items.

For example, a business adds a gift-wrapping fee to a Cart as a Custom Line Item, with its own price and tax.

Guest checkout

Guest checkout lets a visitor shop and check out without signing in or creating an account. The visitor shops in an anonymous session, and the visitor's items are held in an anonymous Cart. By default, an anonymous Cart is kept until it is merged with a Customer's Cart, or until its Cart lifetime ends.
When the visitor later signs up or signs in (see Customer authentication), the resources created in the anonymous session can be assigned to the Customer. If the storefront provides the anonymous ID of the session, all Carts, Orders, Shopping Lists, and Payments with that ID move to the Customer. If it provides only the anonymous Cart, only that Cart moves. A visitor can already have one or more active Carts in their account, even though they aren't signed in. If the visitor starts shopping with an anonymous Cart and later signs in, the default is to try to merge the items into the Customer's most recently modified active Cart. This process is called a Cart merge.

For example, a visitor adds a lamp to a Cart in the webshop without signing in. At checkout, the visitor signs in, and the lamp is in the visitor's Cart.

Global and Store-specific Customers

A Customer who is assigned to one or more Stores is a Store-specific Customer. A Store-specific Customer can only be associated with Carts and Orders in their assigned Stores. A global Customer isn't assigned to any Store and can be associated with Carts and Orders either in specific Stores or without a Store.

For example, a customer who registered in a Store for Germany can only shop in that Store, while a global Customer can shop in any Store.

For more information, see Global versus Store-specific Customers.

Frozen Carts

Freezing a Cart keeps its prices from changing. A business freezes a Cart during checkout to make sure the customer pays the price they saw in their Cart, even if prices or promotions change before the customer places the Order.

A business can freeze a Cart in two ways:

  • A soft freeze keeps the prices of the Line Items as they were. If the Price of a Line Item is deleted, the Line Item is removed from the Cart. New Cart Discounts aren't applied to the Cart. The Cart can still be ordered or unfrozen.
  • A hard freeze does everything a soft freeze does, and also keeps the Discounts, Discount Codes, and Shipping Method of the Cart fixed.

A frozen Cart isn't merged when a Customer signs in. If a Discount must be removed or a Tax Rate must change, ordering the frozen Cart fails.

For example, a customer starts the payment for a Cart, and the business starts a sale at the same time. The business froze the Cart at the start of the payment, so the customer still pays the price they saw.

Locked Carts

Locking a Cart blocks all updates to it. Freezing is different because it only blocks updates that affect the price of the Cart. A business locks a Cart for assisted selling, when a support agent needs exclusive access to a Cart while they work on it. Only applications that have been granted the permission to manage locked Carts can lock, update, or unlock a Cart.

In the Merchant Center, the edit mode of the Cart list locks the Cart to the Customer and releases it when the person editing leaves the edit mode.

For example, a customer calls support to get help with a Cart. The support agent locks the Cart so that nobody else, including the customer, changes it while the agent updates it.

Cart merge

A Cart merge combines an anonymous Cart with a Customer's existing active Cart, so that a visitor who signs in doesn't lose the items they selected. A merge can happen automatically during sign-up or sign-in with the internal OAuth service, or manually at any other time.

Two Carts are eligible for a merge when they use the same currency and belong to the same Store or Business Unit if either has one. If the anonymous Cart has Direct Discounts, both Carts must also use the same setting for whether Direct Discounts can be used together with Cart Discounts.

Items that match in both Carts are merged using the higher quantity of the two. Other items are added as separate items. The merge works in one of two modes. The default is to merge the anonymous Cart into the Customer's most recently modified active Cart. The other mode is to use the anonymous Cart as the Customer's new active Cart without merging items.

After a merge, the anonymous Cart keeps its content and is marked as merged. Carts that are no longer active aren't deleted and remain available for inspection, but they may be read-only depending on their state. See Cart states.

For example, a visitor adds a lamp to an anonymous Cart, then signs in to an account that already has a Cart with a rug. Merging the Carts gives the customer one Cart with the lamp and the rug.

Cart lifetime

A Cart is kept as it was the last time someone performed actions on it. It contains Line Items and Custom Line Items with the Prices that were valid at the time of the last Cart update, and Cart Discounts that were active at that time. Reading a Cart doesn't refresh its prices. Only updating the Cart does.

By default, a Cart is deleted 90 days after its last change. A business can change this period in the Project settings and for individual Carts. Changing the setting in the Project doesn't change existing Carts. Carts that were created from a Quote or a Recurring Order aren't deleted automatically.

For example, a customer leaves a Cart for three months without changing it. With the default setting, the Cart is deleted, and the customer starts a new Cart on the next visit.

Taxes

A Cart can't calculate taxes for its items until the shipping address is set. The Tax Rates come from the Tax Categories of the Products and the Shipping Methods in the Cart. A business can also use an external tax service to provide the Tax Rates or the tax amounts. Calculating taxes for each unit of an item or for the whole Line Item can differ by a few cents. For how a Tax Rate is chosen for a shipping address, see Tax Rate selection by shipping address.

For example, a Cart for a customer in Germany shows the German VAT only after the customer enters the shipping address.

Price precision and rounding

Prices can be stored in cent precision or high precision. When a Cart calculates the net, gross, and tax amounts, it rounds them. Relative Discounts round in favor of the customer: half-way amounts round down.

For example, when a relative Discount results in an amount that lies exactly half-way between two cents, the Cart rounds down, which is better for the customer.

Cash or denomination rounding

In some countries, prices must be rounded to the nearest 5 or 10 units, because smaller coin denominations were withdrawn from circulation. For example:

  • In Hungary, offline cash payments are rounded to the nearest 5 forints, while online prices can use any amount.
  • In Switzerland, both offline and online prices are rounded to the nearest 5 centimes. Amounts ending in 1, 2, 6, or 7 round down, and amounts ending in 3, 4, 8, or 9 round up. For example, CHF 10.42 is rounded to CHF 10.40, and CHF 10.43 is rounded to CHF 10.45.
To enable cash rounding for a currency in your Project, contact the commercetools support team. A Cart applies cash rounding to its total. If a Product Discount affects a price, the rounding also shows in the discounted Price. It doesn't apply cash rounding to the results of Cart Discounts. Cash rounding is different from the rounding setting that decides how halves are rounded.

Inventory

For details on managing inventory, including inventory modes, quantity enforcement, and consistency guarantees, see Inventory modes in the Inventory overview.

Shopping Lists

A Shopping List is a list of items that a customer wants to keep for later, such as a wishlist. It can hold Products and items that the customer describes in free text. A customer can add the Products of a Shopping List to a Cart; items described in free text aren't added. When a visitor signs up or signs in after shopping in an anonymous session, the Shopping Lists of that session move to the Customer.

For example, a customer saves three pairs of shoes in a Shopping List, then later adds the pair they chose to a Cart.

Orders

An Order is a snapshot of a transaction between a customer and a business. It serves as a durable record of the transaction. It includes details such as the selected items, prices, customer information, the shipping address and billing address, selected Shipping Methods, payment information, and Order state. An Order doesn't manage the full post-purchase lifecycle, such as fulfillment, returns, or refunds, but it is the foundation on which those processes can be built or integrated.

For example, when a customer completes checkout, the business receives an Order with the items, prices, addresses, and payment information of the purchase.

Create an Order

A business creates an Order in one of three ways: from a Cart, from a Quote, or by using Order Import.

Learn how to implement a custom checkout flow in the self-paced Implement a custom checkout module.

From a Cart

Creating an Order from a Cart is the most common method. A business uses it for typical customer purchases during checkout. The Order receives a copy of the following information from the Cart:

  • Line Items and Custom Line Items, with their prices and any associated Custom Fields
  • Shipping and billing addresses
  • Customer information
  • The Custom Fields of the Cart
  • The selected Shipping Method
  • Payment information
  • Discount Codes
  • Direct Discounts, and whether they can be used together with Cart Discounts
  • Tax settings
  • The inventory mode
  • The origin of the Cart: a customer, a merchant, a Quote, or a Recurring Order
  • Free gift items that the customer removed
  • A reference to the Cart
  • Any associated Store or Business Unit

For example, a customer pays for a Cart in the webshop, and the business receives an Order that contains the same items, prices, and addresses as the Cart.

From a Quote

Creating an Order from a Quote uses the agreed terms of a Quote. A business uses it in B2B scenarios or when prices are negotiated. The Order includes the negotiated prices, quantities, and any other conditions in the Quote. A Quote can only create an Order while it is pending and hasn't passed its validity date. For what Quotes are and how they move through negotiation, see the Quotes overview.

For example, a buyer agrees to a Quote for 200 chairs at a negotiated price, and the business creates an Order from the pending Quote.

Using Order Import

Order Import lets a business import existing Orders from external systems or other Projects. A business uses it to migrate from a legacy system or to consolidate Orders from different sources. Order Import requires all Order data, and the data must follow the Order data model.

Update an Order

An Order is a legally binding purchase agreement between the business and the customer. A business should therefore consider changes to it carefully.

A business can update an Order in two ways: with a direct update or with an Order Edit. The option depends on whether the change affects the financial terms of the purchase agreement. For how to choose, see Direct update or Order Edit.

Shipping addresses, including the country and state, identify the applicable Shipping Methods and shipping rates of an Order. A business can update a shipping address with a direct update or with an Order Edit. However, Shipping Methods and shipping rates are only reevaluated when the change is made with an Order Edit.

For example, a customer entered a wrong street name. The business corrects the shipping address so that the goods reach the customer.

Non-financial changes

A business uses a direct update to change an Order when no financial change occurs. For example, changes to:

  • The Order number, state, or locale
  • The customer's email address or billing address
  • Shipping information, such as addresses, that doesn't require recalculation of the Shipping Method and shipping rates
  • Payment information
  • Deliveries and returns
  • Any other change that doesn't affect the Order total

Financial changes

A business uses an Order Edit when an update to an Order results in a financial change. For example, changes to:

  • Line Items and Custom Line Items, such as their quantity
  • Shipping information, such as addresses, that requires recalculation of the Shipping Method and shipping rates
  • Discounts
  • Any other change that affects the Order total

An Order Edit is a staging area for changes. A business can preview what the Order looks like with the changes before it applies them, and the Order Edit keeps an audit trail of the amendment. Once applied, any additional changes need a new Order Edit. In the same Order Edit, a business can also change non-financial properties. For example, it can update a customer's email address together with changes that affect the total price.

Payments

A Payment holds information about the Payment Service Provider (PSP), the payment method used, any related transactions, and the current state of the Payment. An external PSP carries out the actual financial process. The PSP connects to commercetools through PSP-specific integrations.
If a business uses Checkout as its checkout solution, it can request the PSP to perform actions throughout the financial process, such as payment capture, refund, and authorization cancellation.

For example, a customer pays with a credit card at checkout. The Payment holds the PSP, the payment method, and the transactions for the card payment.

Payment Methods

A Payment Method holds the PSP information and the actual payment method that a customer used, such as a credit card or a direct debit. A business uses a Payment Method to connect with external PSPs.

For example, a customer's saved credit card is a Payment Method that the customer can use again for later purchases.

How the concepts relate

The following diagram shows how Carts, Orders, and Payments relate to each other and to the people and places they belong to.

A Customer or an anonymous visitor has Carts, and a Cart holds Line Items. A customer can add the Products of a Shopping List to a Cart. When the Cart is ordered, it becomes an Order, and a pending Quote can also be used to create an Order. A Payment records how the customer pays for an Order. A Cart and its Order can belong to a Store or a Business Unit.

Lifecycle and states

Cart states

The following diagram shows the states of a Cart.

An active Cart can be updated and ordered, and a Customer can have more than one active Cart. A frozen Cart blocks updates that affect prices, and it can still be ordered or unfrozen. A Cart is merged when a visitor's anonymous Cart is merged into a Customer's Cart at sign-in, and an ordered Cart was used to create an Order. No further operations are allowed on a merged or an ordered Cart.

Order, shipment, and payment states

An Order has a state, a shipment state, and a payment state. They describe different parts of the Order, and a business sets and uses them to track the Order. A new Order is open by default, and an Order can be confirmed, complete, or cancelled. A shipment can be, for example, ready, shipped, or delivered, and a payment can be, for example, pending, paid, or credit owed.

For example, a new Order is open, the customer has paid, and the goods are ready to ship. The order state is open, the payment state is paid, and the shipment state is ready.

Selection and precedence rules

Tax Rate selection by shipping address

A Cart selects the Tax Rate of an item by comparing the shipping address with the countries and states of the Tax Rates in the Tax Category of the item. A Tax Rate applies in the following cases:

  • The country of the shipping address and the country of the Tax Rate are the same, and neither has a state.
  • The countries are the same, and the state of the shipping address and the state of the Tax Rate are the same.
A Tax Rate doesn't apply when the countries differ. It also doesn't apply when only one of them has a state, or when both have a state and the states differ. An exception applies if the Project's country Tax Rate fallback setting is enabled: when no Tax Rate covers the state of the shipping address, a country-only Tax Rate is used instead. See Tax Category for details. If a sub-unit of a country is used only for shipping, record it as a region in the address and not as a state, so that it doesn't affect the Tax Rate selection.

For example, a Tax Category has a Tax Rate for Germany without a state. A shipping address in Germany without a state gets that Tax Rate. A shipping address in Germany with a state doesn't, unless the Tax Rate is also set for that state.

Direct update or Order Edit

The following diagram shows how to choose between a direct update and an Order Edit to change an Order.

A direct update changes only the Order. It doesn't recalculate taxes, and it doesn't change the Cart that the Order was created from. If a change affects the Order total, or taxes or shipping rates must be recalculated, an Order Edit is the only option. An Order Edit also gives the business an audit trail of the amendment.

Common scenarios

A guest shopper signs in at checkout

A visitor adds items to a Cart without an account. At checkout, the visitor signs in to an existing account that already has an active Cart. The business decides whether the visitor's items move into the existing Cart or replace it. By default, the items of the anonymous Cart are merged into the Customer's most recently modified active Cart if the two Carts are eligible. Orders, Shopping Lists, and Payments of the anonymous session also move to the Customer if the storefront provides the anonymous ID. See Guest checkout, Cart merge, and Cart assignment at sign-in.

Keep the price stable during payment

A business wants the customer to pay the price they saw in their Cart, even if a sale starts while the customer pays. The business freezes the Cart when the payment starts. A soft freeze keeps the prices, and a hard freeze also keeps Discounts, Discount Codes, and the Shipping Method fixed. The business then creates the Order from the frozen Cart. See Frozen Carts and Create an Order.

Correct a shipping address after purchase

A customer notices a mistake in the shipping address after the purchase. If the change doesn't affect taxes or shipping rates, the business uses a direct update to correct the address, and the Cart isn't changed. If the new address requires different taxes or shipping rates, the business uses an Order Edit, previews the changes, applies them, and keeps an audit trail. See Update an Order and Direct update or Order Edit.