đšCart Layouts
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:
See the full Cart & Checkout folder structure here:
đŗCart and Checkout Folder Structurewrapper.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:
Empty the Cart
<button onclick="s_e_cart_empty(true)">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>
Reference
The following reference shows how to output useful data about your Cart as a whole:
Field Name | Liquid Tag |
---|---|
Total Quantity |
|
Shipping Price | |
Shipping Price Before Tax | |
Shipping Price Tax Amount | |
Total Item Price | |
Total Item Price before Tax | |
Total Item Tax Amount | |
Total Price Reduction (due to discounts) | |
Final Total Price before Tax | |
Final Total Tax Amount | |
Final Total Price |
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 cart layout will iterate in a loop, outputting the item.liquid file for each line in the customer's cart.
cart_id
Each line in the cart has a cart_id
accessible at {{this.cart_data.cart_id}}.
When modifying the cart with JS, this cart_id
will be needed.
Multiple lines in the cart may refer to the same product if a different combination of attributes is selected.
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:
The s_e_cart_remove
function can be used to remove a line from the cart.
If the cart has several lines containing the same product, but with different attributes, only the targeted line and its attributes will be removed.
In this example, the function is called when a button is clicked and Liquid is used to pass the cart ID into the function:
item.liquid
You can optionally pass in a callback function to the third argument to be called after the row has been removed from the cart. In order for this to work, you need to set reload
(the first argument) to false
.
item.liquid
JavaScript
Increasing the Quantity of a Product in the Cart:
See the full Article on updating Product quantities here.
item.liquid
wrapper.liquid
Note that, after updating this input field, the User will also have to click the "Update Cart" button. Following the link above will lead to a more detailed article.
Outputting the Attributes the User chose for this item:
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 add a "max" attribute to the quantity input:
Items added to a Cart in Siteglide are not reserved. It is possible for two or more customers to add the last product in stock to their cart at once.
Last updated