Keeping split cart lines
4 min read
By default, FastStore merges cart lines that share the same SKU, seller, attachments, and services into a single line. This is the right behavior for most stores. However, some stores need each unit of a product to remain a separate line in the cart, for example, when shoppers choose different assembly options (such as installation or extended warranty) for each unit, or when each unit must be handled as its own line in an ERP integration.
The
preserveCartLines flag makes FastStore respect the lines that your store split in Checkout, instead of merging them again.FastStore doesn't split lines on its own. Adding a product with quantity2still creates a single line, whether or notpreserveCartLinesis used. The split must be done in Checkout.
Default behavior and behavior with the flag
Consider a shopper who buys 2 units of the same refrigerator. Before the shopper chooses services for each unit, your store splits the line in Checkout using the split item endpoint, resulting in
[refrigerator x1, refrigerator x1].preserveCartLines: false (default) | preserveCartLines: true | |
|---|---|---|
| Minicart | Shows one line with quantity 2. | Shows two lines with quantity 1 each. |
| Checkout | On the next cart validation, FastStore sends the merged quantity, and Checkout undoes the split. | The split is kept after the cart is validated and the page is reloaded. |
| Editing or removing a line | Because lines share the same ID, the action may affect the wrong line. | The action affects only the selected line. |
The behavior of stores that don't enable the flag remains unchanged. This is because Checkout may also return several lines of the same SKU due to promotions, so the flag is opt-in. Without it, FastStore keeps merging those lines.
Assembly options are added to the cart as child items of a product line, and thepreserveCartLinesflag handles them. Services stored inbundleItemsfollow a different mechanism and don't require the flag.
Before you begin
- Update your store to FastStore
4.10.3or a later version. To do so, follow Updating the CLI package version. - Make sure your store splits items in Checkout. FastStore only preserves lines that already exist as separate lines in the Order Form.
Instructions
Step 1 - Enable preserveCartLines
- Open your
discovery.config.jsfile. - In the
apiobject, setpreserveCartLinestotrue.
Step 2 - Test the cart behavior locally
Before deploying, test the flag locally, as it changes how cart lines are matched with Checkout.
- In the terminal, run the following command to start the local server:
_10yarn dev
- Create a cart with two units of the same SKU and call
POST /api/checkout/pub/orderForm/{orderFormId}/items/{itemUniqueId}/splitwith a body that divides the item into lines of quantity1, for example,[{"quantity": 1}, {"quantity": 1}]. - Open your store with the cart's
checkout.vtex.comcookie and open the minicart. It should show two lines, and Checkout should keep two lines after you reload the page. - Increase the quantity of one line. Only that line changes in Checkout.
- Remove one line. Only that line is removed, and its services (if any) stay on the correct unit.
If your store uses assembly options, also confirm the following:
- The cart stays stable when the same SKU appears with and without a service.
- The minicart matches the Checkout cart line by line.
- The cart keeps working when an assembly option SKU has Display on website turned off.
The default minicart doesn't display the assembly options of each line. The split lines follow the Checkout behavior, but you may need a custom component to present the services chosen for each unit.
If you find any issues, contact VTEX Support with the
orderFormId of the affected cart.Step 3 - Deploy the changes
- Commit the changes to your
discovery.config.jsfile. - Push the changes to the main branch of your repository.
This triggers a WebOps build. Once it completes, the
preserveCartLines flag will be active in your live store.