website logo
⌘K
Introduction
PORTAL
Agency Whitelabelling
PAGES
Pages - Accessing Page Data
Pagination Layouts
Page Templates
FORMS
CATEGORIES
Filtering WebApps and Modules by Categories
Outputting Categories on WebApp / Module / eCommerce Layouts
Outputting Category Fields in any Location
Category Detail Layouts
FAQ - Categories
COMPANY INFORMATION
Company Information
SITE SEARCH
Site Search
PUBLIC API/ZAPIER
Zapier - Formatting arrays correctly
Public API/Zapier Changelog
MODULES
Module Marketplace
Building Custom Modules
Siteglide Modules
Front-end Submit Modules
DATA STRUCTURES
Creating WebApps from the CLI
Field Types
WEBAPPS
Front-end Submit WebApps
Layouts
Search and Filtering
Understanding Custom Field Names and IDs
FAQ - WebApps
CRM
User Details
User Secure Zones
Storing User's Favourite WebApp / Module Items
User's Form Submissions (Cases)
How Users Edit their Email and Password Front End
Editing a User's CRM record Front End with Custom Field Sets
CLI
Introducing Siteglide CLI
CLI Changelog
Secure Zones with CLI
Page Templates with Siteglide CLI
Pages with Siteglide CLI
Includes with Siteglide CLI
Managing Email Templates
Migrate - Manual Form setup
Migrate - Convert existing Forms
Liquid
Accessing Assets
Liquid Dot Notation
Using WebApp Collections- Tutorial
Using the current_user object with Secure Zones
Preventing Duplicate Content with Query Parameters- Canonical URL and Robots.txt
FAQ - Liquid
GraphQL
Tutorial Overview
About GraphQL
Tutorial 1- Your First Query
Tutorial 2 - Pagination
Tutorial 3 - Filtering the Results
Tutorial 3 - Answers to the First Filtering Challenge
Tutorial 4 - Advanced Filtering
Tutorial 4 - Challenge Answers
Tutorial 5 - Using Liquid to run GraphQL queries on your Site
Tutorial 6 - Variables
Tutorial 6 - Answers to the Variables Challenge
Tutorial 7 - Sorting
Tutorial 8 - Building a Liquid API GET Endpoint Page powered by GraphQL queries
Best Practice and Performance
Module/WebApp Caching
Getting Started with Liquid Caching - to Reduce Server Response time and Improve Performance
Includes
ecommerce/checkout_standard
Frequently Asked Questions
Using Liquid Logic to Check if a field exists, or is empty on the Front End
How do I learn more about Liquid?
How to setup a multi domain start page
Docs powered by archbee 

Cart Layouts

16min

How to customise the Shopping Cart Layout

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:

HTML
|
{%- 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.

HTML
|
{% 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.

JS
|
<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. 

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

Liquid Tag

Total Quantity

{{context.exports.cart_total_quantity.data}}

Shipping Price

{% include 'ecommerce/price_shipping', format_type: 'formatted' -%}

Shipping Price Before Tax

{% include 'ecommerce/price_shipping_before_tax', format_type: 'formatted' -%}

Shipping Price Tax Amount

{% include 'ecommerce/price_shipping_tax_amount', format_type: 'formatted' -%}

Total Item Price

{% include 'ecommerce/price_total_item_cost', format_type: 'formatted' -%}

Total Item Price Before Tax

{% include 'ecommerce/price_total_item_before_tax', format_type: 'formatted' -%}

Total Item Tax Amount

{% include 'ecommerce/price_total_item_tax_amount', format_type: 'formatted' -%}

Total Price Reduction (due to Discounts)

{% include 'ecommerce/price_total_reduction', format_type: 'formatted' -%}

Final Total Price Before Tax

{% include 'ecommerce/price_total_before_tax', format_type: 'formatted' -%}

Final Total Tax Amount

{% include 'ecommerce/price_total_tax_amount', format_type: 'formatted' -%}

Final Total Price

{% include 'ecommerce/price_total', format_type: 'formatted' -%}

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:

See the full Article on updating Product quantities here.

HTML
|
<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:

HTML
|
{% 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:

HTML
|
<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}}')"
/>




Updated 06 Apr 2023
Did this page help you?
Yes
No
PREVIOUS
Discount Codes Layout
NEXT
Customising the Add to Cart Button Component
Docs powered by archbee 
TABLE OF CONTENTS
Prerequisites
Folder Structure
wrapper.liquid
Hiding the Cart when Empty
Empty the Cart
Updating the Cart's Total 
Link to the Checkout Page
item.liquid
Removing an individual Product from the Cart:
Increasing the Quantity of a Product in the Cart:
Outputting the Attributes the User chose for this item:
Controlling Inventory