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

From Spiffy Stores Knowledge Base

Line 17: Line 17:
 
Returns the unique internal id of the line item.
 
Returns the unique internal id of the line item.
  
This is normally only for internal usage.
+
This is normally only for internal usage and is only available for ''order'' line items.
  
 
== <code>line_item.cart_index</code> ==
 
== <code>line_item.cart_index</code> ==

Revision as of 12:48, 22 August 2018

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 and is only available for order line items.

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

Returns an array of properties that have been added to the line item when it was added to the cart, and are used to store custom information about that line item.

For more information, see the tutorial on Asking your customer for additional information.

As line_item.properties returns an array of elements, you will need to access each element of the array using a for loop.

<ul>
  {% for property in line_item.properties %}
    <li>{{ property.first }}: {{ property.last }}</li>
  {% endfor %}
</ul>

For example, you might have the following fields defined for your product:

Card Message: Thank you for all your help to set up my Spiffy Store.
Gift Wrapping: Yes

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.

line_item.url

Return the product page URL associated with this line item, including the variant parameter to enable direct linking to the selected variant.

{{ line_item.title | link_to: line_item.url }} =>

<a href="/products/cute-dog?variant=9876543">Cute Dog - Brown</a>

line_item.image

Return the image associated with the line item.

As a short-cut, we can apply the img_url filter directly to the line item, rather than using the line_item.image attribute.

{{ line_item.image | img_url: 'small' | img_tag }}

produces the same result as

{{ line_item | img_url: 'small' | img_tag }}