Cart

This page details the template tags available to you when creating a Cart template.

Default templates

As with all Perch Add-ons, Shop comes with some default templates. Before editing any templates, please see the notes on editing templates to make sure your changes are safe when you next update the app.

Purpose Template
Cart display (master template) cart/cart.html
Order confirmation cart/cart_static.html

Creating your own templates

You can either edit the default cart.html or create your own. See page functions for how to include a different template.

The cart is namespaced with perch:shop so any template tags used should use this namespace. An exception is when dealing with the individual items in the cart. These are namespaced perch:cartitem.

Cart template tags

The following variables are exposed as tags. As an example if you want to display the total including tax, formatted with the symbol of the currency the customer is paying in you would use the tag:

<perch:shop id="grand_total_formatted">
Tag Description
product_count Number of unique products in the cart
item_count Number of individual items in the cart
shipping_id Shipping ID for the shipping method in use for the cart
shipping_method The name of the shipping method being used
shipping_weight The combined weight of items being shipped
shipping_tax Tax paid on selected shipping method, defaults to 0
shipping_tax_formatted Formatted value for shipping tax
shipping_tax_rate Rate used for shipping tax
shipping_with_tax Shipping charge with tax added
shipping_with_tax_formatted Shipping charge with tax added, formatted
shipping_without_tax Cost of shipping without tax
shipping_without_tax_formatted Cost of shipping without tax, formatted
total_items Total value of the items in the cart
total_items_formatted Total value of the items in the cart, formatted
total_items_tax The total tax amount on items in the cart
total_items_tax_formatted The total tax amount on items in the cart, formatted
total_shipping The total shipping amount
total_shipping_formatted The total shipping amount, formatted
total_shipping_tax The total tax amount on shipping
total_shipping_tax_formatted The total tax amount on shipping, formatted
total_items_with_shipping The total value of items and shipping combined
total_items_with_shipping_formatted The total value of items and shipping combined, formatted
total_tax The total amount of item and shipping tax combined
total_tax_formatted The total amount of item and shipping tax combined, formatted
total_discounts Total of discounts applied
total_discounts_formatted Total of discounts applied, formatted
total_items_discount The total value of discounts applied to items in the cart
total_items_discount_formatted The total value of discounts applied to items in the cart, formatted
total_items_tax_discount The total value of discounts applied to tax
total_items_tax_discount_formatted The total value of discounts applied to tax, formatted
total_items_discounted Total value of the items in the cart with discounts applied
total_items_discounted_formatted Total value of the items in the cart with discounts applied, formatted
total_items_discounted_with_tax Total value of the items in the cart with discounts and tax applied
total_items_discounted_with_tax_formatted Total value of the items in the cart with discounts and tax applied, formatted
total_shipping_discount Total value of discounts applied to shipping
total_shipping_discount_formatted Total value of discounts applied to shipping, formatted
total_shipping_tax_discount Total value of shipping with discounts applied
total_shipping_tax_discount_formatted Total value of shipping with discounts applied, formatted
total_tax_discount Total amount of discount applied to tax
total_tax_discount_formatted Total amount of discount applied to tax, formatted
total_discounts_with_tax Combined total of item, shipping and tax discounts
total_discounts_with_tax_formatted Combined total of item, shipping and tax discounts, formatted
grand_total Grand total - what your customer will pay
grand_total_formatted Grand total, formatted
shipping_weight Shipping weight
currency_id Currency ID for the currency used for this cart
currency_code Currency code
currency_name Currency name
currency_symbol Currency symbol

Cart Item tags

Tag Description
identifier The unique ID of this entry in the cart
id Alias for identifier
qty The quantity of this item in the cart
productID The unique ID of the product
is_variant True or false, if the item is a variant
variant_desc The variant description of the item, if it is a variant
sku The product SKU
title Title of the product
slug Product slug based on the title
brand The product brand (use with type="shop_brand"
category The product categories (use with perch:categories tags)
catalog_only True or false, if the product is available for online sale
requires_shipping True or false, requires physical shipping
weight The weight of the item
width The width of the item
height The height of the item
depth The depth of the item
price Item price (use with type="shop_currency_value")
sale_price Sale price (use with type="shop_currency_value")
trade_price Trade price (use with type="shop_currency_value")
on_sale True or false, if the item is currently discounted
tax_group The product’s tax group (use with type="shop_tax_group")
stock_level The number of items in stock
stock_status The current stock status (use with type="shop_stock_status")
max_in_cart The maximum allowable quantity of this item per cart
discount The amount of discount applied to the item
price_with_tax The price with tax included
price_with_tax_formatted The price with tax included, formatted
price_without_tax The price without tax
price_without_tax_formatted The price without tax, formatted
tax_discount The about of discount applied to the tax
tax_rate The rate at which tax has been calculated
total_tax The amount of tax
total_tax_formatted The amount of tax, formatted
total_with_tax The line total including tax
total_with_tax_formatted The line total including tax, formatted
total_without_tax The line total excluding tax
total_without_tax_formatted The line total excluding tax, formatted

Remove from cart buttons

You can add a “remove from cart” button to provide a simpler way for a customer to remove the item than setting the quantity to zero.

Within your <perch:cartitems> section:

<button type="submit" name="del:<perch:cartitem id="identifier">" value="1">
  Remove from cart
</button>

Clicking the button will submit the form, sending along with it the del:123 field. This causes item 123 to be removed from the cart. If doing this, it’s important to take account of the default action that occurs when a browser submits a form using the Enter key. What normally happens, is that the browser will submit the form as if the first submit button in the form had been clicked. If your “remove from cart” button appears as the first submit button, pressing Enter will remove the first item from the cart. Your customer might find this to be surprising.

To account for this behaviour, it’s a good idea to make sure that the first button is a standard update button. Usefully, it doesn’t even need to be visible - you can hide it. Something like:

<perch:input type="submit" value="Update" hidden="true" aria-hidden="true">