Liquid Template Variables - cart

From Spiffy Stores Knowledge Base

Revision as of 18:22, 11 September 2008 by Admin (talk | contribs) (→‎cart.note)

The liquid template variable cart has the following attributes:

cart.item_count

Returns the number of items currently in the shopping cart.

For example:

{% if cart.item_count == 0 %}
  Your shopping cart is empty!
{% else %}
  You have <a href="/cart">{{ cart.item_count }} {{ cart.item_count | pluralize: 'item', 'items' }}</a> in your cart
{% endif %} 

cart.items

Returns all the items in the shopping cart. Each item is a Line Item.

For example:

<ul>
{% for item in cart.items %}
   <li>{{ item.title }}</li>
{% endfor %}
</ul>

cart.total_price

Returns the total price of all items in the shopping cart.

For example:

The total of your cart is: {{ cart.total_price | money }}

cart.total_weight

Returns the total weight of all items in the shopping cart.

Weight is always returned as grams. Use weight or weight_with_unit filter to display the actual weight in your preferred unit system.

The total of your cart is: {{ cart.total_weight | weight_with_unit }}

cart.note

You have the option of adding a note field to your checkout template. This may be used to collect information from the customer on any special requests they have for the order.

This is used by defining an input field named “note” in the form that submits to ”/cart” in cart.liquid.

For example:

<p>
  <label for="notes">Extra notes or special instructions</label>
  <input type="text" id="notes" name="note" size="60" value="{{ cart.note }}" />
</p>

Please note that you can also activate an "Additional Checkout Comments" field during checkout to collect similar information. This option can be enabled through the "Preferences" -> "Checkout & Payment" options. This option may be simpler to implement as it does not require any theme template customization to enable.

cart.attributes