Webshop Cart Load URL
Creating a customized cart via URL. This article covers the cart loader functionality, which enables URL's that redirect users to a cart page loaded with a specific combination of products. Cart Load URLs works with all spectrum tenants (Nordics, VitaminExpress, Baerbel-Drexel and Purasana). Any Spectrum storefront that serves this route behaves the same; locale prefixes follow that shop’s URL rules.
URL
Format
A Cart Load URL enables sharing of pre-configured carts. They allow multiple products and/or a discount to be added to a cart via a single URL. Each product is specified using a structured URL format. The structure is as follows: /cart/load?products={product_identifier}:{quantity}:{interval}|{product_identifier}:{quantity}:{interval}
/cart/load?- This is the path that loads a cart from the URL.
products=- The selector which tell the system to search in the product object.
- Product Identifier
- Prefer the variant key (unique, Variants tab). SKU or product key also work; product key resolves to the master variant.
- Quantity (optional)
- The number of units of the product to be added to the cart.
- Interval (optional)
- The interval (in days) for recurring purchases or deliveries.
|(separator)- The symbol used as a separator between product and its quantity and interval indication.
If quantity is omitted, it defaults to 1. If interval is omitted, there is no interval. If an interval is given but is not on the variant, that line is skipped. See Subscription Variant. It is placed after the base URL of the website, when applicable with the locale specification. Some examples:
- https://www.baerbel-drexel.de/cart/load?products=
- https://www.vitaminexpress.org/de/cart/load?products=
- https://vitaminexpress.no/cart/load?products=
Requirements
There are two important aspects to keep in mind for Cart Load URLs to function: The Product variants need to be enabled in the Product selection page for the storefront of the URL you’re creating. The product variants need to be in stock in the locale of the URL you’re creating.
If for any of the product variant keys in the cart load URL there is not stock, or it is not enabled to the specified storefront, the user, upon clicking the URL will be redirected to an error page and promptly to an empty cart.
Unknown identifiers and invalid intervals are dropped. A toast appears only if adding to the cart fails. The shopper is then redirected to cart (or redirectUrl). Empty products and empty discountCode just redirects.
Variant keys
Products are individually specified in the Cart Load URL, it is best practice to use the product variant Keys from commercetools. These are always unique. They are found in the Variants tab of the product, or in the variant’s general overview page.
When adding multiple product variant keys, each consecutive one is separated with the vertical line / pipe character: | For instance, below is a Cart Load URL for three products, with the following variant keys:
0077a6ae-d177-474d-8c9d-7f07cd74b9660077a6ae-d177-474d-8c9d-7f07cd74b9663c25aea1-8d81-4093-8a24-1ad941797c52
Which in turn looks like this: /cart/load?products=0077a6ae-d177-474d-8c9d-7f07cd74b966|0077a6ae-d177-474d-8c9d-7f07cd74b966|3c25aea1-8d81-4093-8a24-1ad941797c52
Multiple units
Just as you would add different variants, if you want the cart to contain multiple units of the same variant, the product variant key must be listed twice, also being separated by the vertical line / pipe character: | Here is an example of a cart load URL with two units of the same product variant:
The variant key 0077a6ae-d177-474d-8c9d-7f07cd74b966 is listed twice here, ../load?products=0077a6ae-d177-474d-8c9d-7f07cd74b966|0077a6ae-d177-474d-8c9d-7f07cd74b966.. You can achieve the same with the quantity specification using :2 after the product key. You may chose the latter to limit the length of the URL.
Discount Code
A Cart Load URL can also be used to create a cart with an existing discount code, including or excluding products.
For a Cart Load URL with just a discount code, replace products with discountCode={*discount code*} in the URL: /cart/load?discountCode={*discount code*} For a Cart Load URL with products as well as a discount code, append the URL with &discountCode={*discount code*} in the URL: /cart/load?products={product}|{product}&discountCode={*discount code*} The discount code must be eligible for the products contained in the cart load URL.
See Create a Discount Code. The loader also reads:
discountCode— apply this code after products (existing codes on the cart are removed first). Invalid codes toast an error; the shopper is still redirected.redirectUrl— only if it starts with/(same-site path). Otherwise the cart page. Used by referral share links (redirectUrl=/).replaceCart— if true, create a new cart instead of adding to the current one.source,sourceIdentifier,totalPrice— tracking / price-mismatch analytics, not merchandising.
Subscription variants
Subscription Variants can also be added to a Cart load URL, there is however extra notation required after the variant key depending on the quantity and interval of the subscription variant. To determine this, navigate to the product in commercetools, select the product’s subscription variant, and take note of the specified amount in the SKU (this is typically also mentioned in the variant name, like below “2 x 90...”), and also the selected value in the Available in subscription intervals field.
From the below example we thus have the values for the quantity and interval; 2 x every 3 months. The interval notation should be in days instead of months, see the list below for the equivalent amount of days for every subscription interval option that can be selected in commercetools.
- 1 month - 28 days
- 2 months - 56 days
- 3 months - 84 days
- 4 months - 112 days
- 6 months - 168 days
- 147, 252, and 336 days when those keys are on the variant
Examples
Use Cases
- Preloading a cart with specific products via URL for marketing campaigns.
- Allowing content managers to generate and share cart links.
- Supporting quick order recreation for returning customers.
Below is an example of a Cart Load URL where there are two products variant keys, both with and interval and quantity. /cart/load?products=4b5507be-1740-43dd-85d6-e9bc12e14f42:2:168|de24fed6-a121-43fc-8724-f540d4916649:1:28|8e4d08f5-9a54-4ffa-b41e-e48ff2a3ef39 4b5507be-1740-43dd-85d6-e9bc12e14f42:2:168
- Product Identifier:
4b5507be-1740-43dd-85d6-e9bc12e14f42 - Quantity: 2
- Interval: 168 (should be available in list in CT)
de24fed6-a121-43fc-8724-f540d4916649:1:28
- Product Identifier:
de24fed6-a121-43fc-8724-f540d4916649 - Quantity: 1
- Interval: 28
8e4d08f5-9a54-4ffa-b41e-e48ff2a3ef39
- Product Identifier:
8e4d08f5-9a54-4ffa-b41e-e48ff2a3ef39 - Quantity: Not specified (defaults to 1)
- Interval: Not specified
Related articles and further reading
- Official commercetools documentation: https://docs.commercetools.com/merchant-center
- Products documentation: https://docs.commercetools.com/merchant-center/products
- Comprehensive discount documentation: https://docs.commercetools.com/merchant-center/discounts-overview
- Cart Discount documentation: https://docs.commercetools.com/api/projects/cartDiscounts
- Carts and Orders overview: https://docs.commercetools.com/api/carts-orders-overview#line-items-and-custom-line-items