Prerequisites

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

Folder Structure

Cart layouts are stored in the following structure.

layouts
  modules
    module_14
      product
        name_of_my_cart_layout
          list
            wrapper.liquid
            item.liquid


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.

wrapper.liquid

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' -%}

It should also contain the controls required for the Cart as a whole. You can add the following buttons:

Empty the Cart

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

Update the Cart

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

Link to the Checkout Page

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 Items in Cart
Liquid Tag: {{context.exports.cart_total_quantity.data}}

Field Name: Total Price as an Integer
Liquid Tag: {{context.exports.cart_total_price.data}}

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: {{context.exports.cart_currency.data}}

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.

item.liquid

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:

<input type="number" name="quantity" min="1" value="{{this.cart_data.quantity}}" onchange="s_e_cart_update_quantity(event.target.value,{{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 this.inventory.id != 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(event.target.value,{{this.cart_data.cart_id}},'{{context.authenticity_token}}')" />

Related Docs and Reference

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

Did this answer your question?