Difference between revisions of "Liquid Template Variables - line item"

From Spiffy Stores Knowledge Base

Line 18: Line 18:
  
 
This is normally only for internal usage.
 
This is normally only for internal usage.
 +
 +
== <code>line_item.cart_index</code> ==
 +
 +
Returns a unique cart index number for the line item. This index number allows you to refer to a specific line item in the cart, even when there are other line items for the same variation.
 +
 +
This variable is used in the <code>cart.liquid</code> template instead of <code>line_item.variant.id</code> that was previously used. The change is necessary as the cart now supports unique line items so that items with custom notes attached are added as unique line items. Obviously they all have the same value for <code>line_item.variant.id</code>, so this new index is used instead.
  
 
== <code>line_item.variant</code> ==
 
== <code>line_item.variant</code> ==

Revision as of 11:28, 24 June 2011

A line item represents a single line in the shopping cart.

There is one line item for each distinct product variant being purchased, regardless of the quantity of that variant in the cart. It is important to include the line item's quantity whenever displaying the item to the user. Line items can be accessed from any theme or email template which makes a cart or order object available.

Line items used in the following theme and email templates:

  • cart.liquid
  • Order Confirmation
  • New Order Notification
  • New Order Notification (mobile)
  • Shipping confirmation
  • Shipping update
  • Additional Content & Scripts

line_item.id

Returns the unique internal id of the line item.

This is normally only for internal usage.

line_item.cart_index

Returns a unique cart index number for the line item. This index number allows you to refer to a specific line item in the cart, even when there are other line items for the same variation.

This variable is used in the cart.liquid template instead of line_item.variant.id that was previously used. The change is necessary as the cart now supports unique line items so that items with custom notes attached are added as unique line items. Obviously they all have the same value for line_item.variant.id, so this new index is used instead.

line_item.variant

Returns the product variant for this line item.

line_item.product

Returns the product for this line_item.

For example, this code retrieves a line item's image:

{{ item.product.featured_image |  product_img_url | img_tag }}

line_item.title

Returns the title of this line item.

This is equal to the original product's title, for example, "Balloon Shirt". If the product has more than one variant, then the name of the variant will be appended to the title. So if the "Balloon Shirt" has two variants, "Medium" and "Large", then line_item.title will be "Balloon Shirt - Medium" or "Balloon Shirt - Large". If a "Yellow Flower Baseball Cap" product only has one variant called "Default" then its line_item.title would just be "Yellow Flower Baseball Cap".

line_item.price

Returns the single price of an item in this line item.

line_item.quantity

Returns the quantity of items are represented by this line item.

line_item.grams

Returns the total weight of the items described by this line item in grams. You can format this for viewing by using the weight_with_unit filter.

line_item.line_price

Returns the combined price of all the items in this line item. This is line_item.quantity times line_item.price less any discounts on the line item.

line_item.tax

Returns the tax that is applicable for this line item.

Currently, tax is not calculated on a line item basis, so the value returned here is always zero.

line_item.discount

Returns the total discount that has been applied to this line item. The discount is calculated from the Shopping Cart Discount rules.

line_item.sku

Returns the SKU of the item's product variant.

line_item.note

Returns the value of the custom note associated with this line item.

line_item.taxable

Returns true if the line item is taxable and false if the line item is tax free.