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.
Redirect to one-page checkout
Use the following code to redirect to the one-page checkout:
{{ "http://www.example.com/checkout/onepage/"|magento_ddl_serialised_cart(cart) }}
Redirect to cart with page refresh
To redirect to the cart and refresh the page, use this code. This ensures the cart page reloads the correct cart template:
{{ "http://www.example.com/checkout/cart/"|magento_ddl_serialised_cart(cart,true) }}
Add extra items to cart rebuild
To add extra items to the cart rebuild, 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}]}) }}
Cart with only extra items
To have a cart with only extra items, supply 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}]}) }}
Add configurable products
Include configurable options in your product when adding configurable products:
{"extra_items":[{"prid": 61173, "opt": {"configurable_options":{'176': '85'}}, "qty": 1}]}
Add bundle or custom options
Add bundle or custom options (as defined in Magento) in a similar way:
{"extra_items":[{"prid": 61173, "opt": {"bundle_options":{'176': '85'}}, "qty": 1}]}
{"extra_items":[{"prid": 61173, "opt": {"custom_options":{'176': '85'}}, "qty": 1}]}
Find the configurable, bundle, or custom options of your products in the Magento admin panel, or 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.
Redirect to one-page checkout
Use the following code to redirect to the one-page checkout:
{{ "http://www.example.com/cartrebuild/"|magento_ddl_serialised_cart(cart) }}
Redirect to cart with page refresh
To redirect to the cart and refresh the page, use this code. This ensures the cart page reloads the correct cart template:
{{ "http://www.example.com/cartrebuild/"|magento_ddl_serialised_cart(cart,true) }}
Add extra items to cart rebuild
To add extra items to the cart rebuild, use the following format:
{{ "http://www.example.com/cartrebuild/"|magento_ddl_serialised_cart(cart,true,{"extra_items":[{"prid":501, "qty": 2}, {"prid":513, "qty": 3}]}) }}
Cart with only extra items
To have a cart with only extra items, supply 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}]}) }}
Add configurable products
Include configurable options in your product when adding configurable products:
{"extra_items":[{"prid": 61173, "opt": {"configurable_options":{'176': '85'}}, "qty": 1}]}
Add bundle or custom options
Add bundle or custom options (as defined by Adobe) in a similar way:
{"extra_items":[{"prid": 61173, "opt": {"bundle_options":{'176': '85'}}, "qty": 1}]}
{"extra_items":[{"prid": 61173, "opt": {"custom_options":{'176': '85'}}, "qty": 1}]}
Find the configurable, bundle, or custom options for your products in the Magento admin panel, or in Fresh Relevance by expanding the Reports drop-down menu and going to All Reports > System Data > Products.
Add SKU-level product variants
To add a SKU-level product variant to the rebuilt cart, use 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, it uses the product ID as normal:
{{ "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.
Default behavior
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) }}
Redirect to checkout
The second parameter lets you send the user to the checkout page instead of the cart. This option removes any existing items in the cart, presenting the user with a checkout containing only the products passed:
{{ "http://www.example.com"|shopify_serialised_cart(cart, true) }}
Clear cart before redirect
The third parameter specifies whether to clear the cart before sending the user to the cart. This only applies if the second parameter is set to false:
{{ "http://www.example.com"|shopify_serialised_cart(cart, false, true) }}
This only applies if the second parameter is set to false):
Pass extra query string parameters
The fourth parameter lets you pass extra query string parameters to the resulting URL. This is useful when using the checkout version, as you can pass 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.
Simple cart permalink
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 is useful for aggregating quantities of the same variant ID. However, it does not support setting Shopify options, such as personalized choices:
{{ "http://www.example.com"|shopify_serialised_cart(cart, simple=True}
Advanced - serialize the cart and add to a query string - custom method
If the above formats do not work for your ecommerce system, you can create a custom URL. Here's an example that creates a return-to-cart URL in this format:
http://example.com/qty1=2&dbid1=12345&qty2=1&dbid2=23456
Jinja2 script
Use the following Jinja2 script to build the custom URL:
{# 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) }}