-You have completed How to Create a Shopping Cart and Guest Checkout

Folder Structure

Cart layouts are stored in the following structure.


To create a new layout, right click on the product folder to add a folder with the name of your layout, then create the list folder and wrapper and liquid files inside it as shown.


The wrapper.liquid file should contain the code for the main section of code that wraps around the loop of Products in the Cart. It should include the following liquid to insert the loop of Products:

{%- include 'modules/siteglide_ecommerce/ecommerce/get/get_products', item_layout: 'item' -%}

Hiding the Cart when Empty

It's strongly recommended to hide the Cart using Liquid logic when it is empty. This logic can either go inside your wrapper.liquid file, or directly in the Page.

{% assign cart_parsed = context.session.cart | parse_json %}
{% if cart_parsed.size > 0 %}
<!-- Your Layout here -->
{% else %}
<!-- Message to say Cart is empty -->
{% endif %}

Empty the Cart

<button onclick="s_e_cart_empty(true)>Empty Cart</button>

Updating the Cart's Total 

See the full Article on updating the Cart's quantity here.

<button onclick="s_e_cart_update(true,'{{context.authenticity_token}}')>Update Cart</button>

You can also run this same function when a different JavaScript event is fired, for example, an onchange event on the quantity <select> element, or onload

Of course, this is just an ordinary link. It will need updating with the slug of your Checkout Page.

<a href="/checkout>Proceed to checkout</a>

The following reference shows how to output useful data about your Cart as a whole:

Field Name: Total
Liquid Tag: {{}}

Field Name: Total Price as an Integer
Liquid Tag: {{}}

Field Name: Total price of Products as a decimal
Liquid Tag: {% include 'ecommerce/price_total', format_type: 'formatted' -%}

Field Name: Cart Currency Symbol
Liquid Tag: {{}}

If you have added Product Attributes to the Products in the Siteglide Admin, you can also access the cart_product_attributes with the following liquid:

{{ context.exports.cart_product_attributes }}

Normally though, Attributes will be handled in the next step- the item.liquid file.


The item.liquid file should contain the code which is rendered for each iteration of the loop of Products. Building the Cart's item.liquid file is similar to building an item.liquid layout file for a Product List View. Learn more about the available fields here.

There are some additional points to bear in mind when creating a cart layout's item.liquid file:

Removing an individual Product from the Cart:

<button onclick="s_e_cart_remove(true,{{this.cart_data.cart_id}})></button>

Increasing the Quantity of a Product in the Cart:

See the full Article on updating Product quantities here.

<input type="number" name="quantity" min="1" value="{{this.cart_data.quantity}}" onchange="s_e_cart_update_quantity(,{{this.cart_data.cart_id}},'{{context.authenticity_token}}')/>

Note that, after updating this input field, the User will also have to click the "Update Cart" button, though this is covered in the wrapper.liquid file- as it covers the whole Page.

Outputting the Attributes the User chose for this item:

{% include 'ecommerce/cart_product_attributes' -%}

Controlling Inventory

In order to make sure Users do not increase the quantity of items in their Cart, when the Product is out of stock, you could use a liquid if  statement:

{% if != blank and this.inventory.quantity == '0' -%}
  <!-- Code here -->
{% endif %}

To improve this so that the User cannot increase the value by a greater number than is allowed by the stock level, you could add a "max" attribute to the quantity input:

<input type="number" name="quantity" min="1" max="{{this.inventory.quantity}}" value="{{this.cart_data.quantity}}" onchange="s_e_cart_update_quantity(,{{this.cart_data.cart_id}},'{{context.authenticity_token}}')" />

See the Product Layout Reference Doc for fields you can use throughout your Product Layouts.

Did this answer your question?