Skip to main content
All CollectionsIntegrationsEcommerce
Rebuild customer carts on your ecommerce store
Rebuild customer carts on your ecommerce store

Integrate with your ecommerce store and rebuild carts for customers returning on different devices.

Updated over a week ago

As standard, links back to the cart only reinstate the cart contents (cart rebuild) if the ecommerce system recognizes the shopper and has recorded their cart. This persistent cart is common ecommerce system functionality, using a cookie to identify the shopper.

However, it does rely on them returning to your website on the same device they were previously using while shopping. This limitation can be overcome by integrating with your ecommerce store to pass the cart contents through the URL.


Supported ecommerce stores

We provide built in support for:

  • Magento
    โ€‹When the extension is installed.

  • Shopify

If you have another ecommerce store you want to integrate with, contact our support team.


Basic - serialize the cart and add to a query string - standard method

You can use this method to create a URL that passes the product and IDs back to your system, which lets you re-create the cart contents if the user visits your store again using a different device.

Example call:

{{ "http://www.example.com/basket/"|add_serialised_cart(format, parameter, key, cart) }}

This call adds the current cart to a URL as a JSON encoded query string parameter.

Parameters:

Parameter

Values

Usage

format

json

JSON format only.

parameter

For example, cart

Query string parameter to use to hold serialised value.

key

For example, sku

Name within the serialised object to store the product ID under.

If, in this example the product URL is http://www.example.com/basket/,

{{ "http://www.example.com/basket/"|add_serialised_cart("json", "cart", "sku", cart) }}

The output would be:

http://www.example.com/basket/?cart=%5B%7B%22sku%22%3A+%22123978%22%2C+%22qty%22%3A+2%7D%2C+%7B%22sku%22%3A+%225456545%22%2C+%22qty%22%3A+1%7D%5D

Once URL decoded, this is:

http://www.example.com/basket/?cart=[{"sku": "123978", "qty": 2}, {"sku": "5456545", "qty": 1}]

Magento 1 DDL

The Fresh Relevance extension provides a helper function that formats a query string, which enables cart rebuild in Magento 1.

To have this functionality enabled, contact your account manager or our support team.

In this example, if you would like to redirect to the one-page checkout, then you should use this:

{{  "http://www.example.com/checkout/onepage/"|magento_ddl_serialised_cart(cart) }}

If you want to redirect to the cart, then it is recommended you add in an extra parameter which refreshes the page. This is because of templating in Magento, as the cart page needs to reload the correct cart template in order to display the cart correctly:

{{ "http://www.example.com/checkout/cart/"|magento_ddl_serialised_cart(cart,true) }} 

Additionally if you want to add extra items to the cart rebuild you can use the following format:

{{ "http://www.example.com/checkout/cart/"|magento_ddl_serialised_cart(cart,true,{"extra_items":[{"prid":501, "qty": 2}, {"prid":513, "qty": 3}]}) }}

Alternatively, you can use this to only have a cart of extra items, by supplying false instead of the cart:

{{ "http://www.example.com/checkout/cart/"|magento_ddl_serialised_cart(false,true,{"extra_items":[{"prid":501, "qty": 2}, {"prid":513, "qty": 3}]}) }}

If you are adding configurable products, ensure you include the configurable options in your product, for example:

{"extra_items":[{"prid": 61173, "opt": {"configurable_options":{'176': '85'}}, "qty": 1}]}

You can also add bundle or custom options (as defined in Magento) in a similar way, for example:

{"extra_items":[{"prid": 61173, "opt": {"bundle_options":{'176': '85'}}, "qty": 1}]} 
{"extra_items":[{"prid": 61173, "opt": {"custom_options":{'176': '85'}}, "qty": 1}]}

You can find the configurable/bundle/custom options of your products in the Magento admin panel, or alternatively in Fresh Relevance by going to Reports > All Reports > System Data > Products.


Magento 2 DDL

The Fresh Relevance extension provides a helper function that will format a query string enabling Cart Rebuild in Magento 2.

To have this functionality enabled, contact your account manager or our support team.

In this example, if you want to redirect to the one-page checkout, you should use this:

{{ "http://www.example.com/cartrebuild/"|magento_ddl_serialised_cart(cart) }}

If you want to redirect to the cart, then it is recommended you add an extra parameter which refreshes the page. This is due to templating in Magento, as the cart page needs to reload the correct cart template in order to display the cart correctly:

{{ "http://www.example.com/cartrebuild/"|magento_ddl_serialised_cart(cart,true) }} 

Additionally, you can add extra items to the cart rebuild by using following format:

{{ "http://www.example.com/cartrebuild/"|magento_ddl_serialised_cart(cart,true,{"extra_items":[{"prid":501, "qty": 2}, {"prid":513, "qty": 3}]}) }}

Alternatively, you can use this to only have a cart of extra items, by supplying false instead of the cart:

{{ "http://www.example.com/cartrebuild/"|magento_ddl_serialised_cart(false,true,{"extra_items":[{"prid":501, "qty": 2}, {"prid":513, "qty": 3}]}) }}

If you are adding configurable products, ensure you include the configurable options in your product, for example:

{"extra_items":[{"prid": 61173, "opt": {"configurable_options":{'176': '85'}}, "qty": 1}]}

You can also add bundle or custom options (as defined by Adobe) in a similar way, for example:

{"extra_items":[{"prid": 61173, "opt": {"bundle_options":{'176': '85'}}, "qty": 1}]}
{"extra_items":[{"prid": 61173, "opt": {"custom_options":{'176': '85'}}, "qty": 1}]}

You can find the configurable/bundle/custom options for your products in the Magento admin panel, or alternatively, in Fresh Relevance by expanding the Reports drop-down menu and go to All Reports > System Data > Products.

It is also possible to add a SKU-level product variant to the rebuilt cart using the use_vid flag. This adds a variant to the rebuilt cart if the product in the cart includes a variant ID (vid). If no vid exists then it uses the product ID as normal. For example:

{{ "http://www.example.com/checkout/cart/"|magento_ddl_serialised_cart(cart, true, {"use_vid": true}) }}

Shopify

Shopify has a helper function that formats a query string, which enables cart rebuild functionality.

By default, the filter produces a link to the cart, setting the quantities of the product variants in the cart passed to it. Any other products in the cart are unaffected:

{{ "http://www.example.com"|shopify_serialised_cart(cart) }}

The second parameter lets you choose to send the user to checkout page instead of the cart. This option removes any existing items in the cart - the user is presented with a checkout with only the products passed:

{{ "http://www.example.com"|shopify_serialised_cart(cart, true) }} 

The third parameter lets you specify whether to clear the cart prior to sending the user to the cart:

{{ "http://www.example.com"|shopify_serialised_cart(cart, false, true) }} 

This only applies if the second parameter is set to false):

The fourth parameter lets you pass any extra querystring parameters to the resulting URL. This can be particularly useful when using the checkout version, as you can pass on a discount code:

{{ "http://www.example.com"|shopify_serialised_cart(cart, true, false, {"discount": "MYCODE") }} 

Learn more about what can be passed to checkouts in this Shopify article.

There is a named option simple, which if set to True, produces a simple cart permalink that takes the user to the checkout page. This can be useful if you need to aggregate quantities of the same variant ID. However, the disadvantage of this is that it does not support the setting of shopify options, for example, personalised choices.

{{ "http://www.example.com"|shopify_serialised_cart(cart, simple=True}

Advanced - serialize the cart and add to a query string - custom method

If you need to build a custom URL for your ecommerce system and the above formats do not work for your system, it's possible to create a custom URL. Here's an example that create a return-to-cart URL in this format:

http://example.com/qty1=2&dbid1=12345&qty2=1&dbid2=23456

This is the Jinja2 script to use:

{# Create a dictionary  instead of a simple string variable to allow
us to modify it inside the loop and see the value outside. #}
{% set d_url = {} %}
{# Iterate round the products and build a dictionary of all the name/value pairs we want on the URL #}
{% for product in cart.p %}
{% if d_url.update({'qty' ~ loop.index:product.qty, 'dbid' ~ loop.index: product.prid}) %}
{% endif %}
{% endfor %}
{# Use a helper filter to format the dictionary into a query string. #}
{{ 'http://example.com' | set_query_parameters(d_url) }}

Did this answer your question?