Line Item

From Shopify Wiki

Jump to: navigation, search

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.

You are most likely to see line items used in the following theme and email templates:



Contents

line_item.id

Returns the id of this line item.

Note: this is a number, not a string. In cart.liquid, it is the same as the variant ID. line_item.variant.id will give you the same value in a more verbose form.

Note: in email templates, use line_item.variant_id or line_item.variant.id. line_item.id is some number that corresponds to an internal id that is not very useful. We will fix this. --Caroline Schnapp 21:34, 12 December 2011 (UTC)

line_item.variant

Returns the product variant of this line item.

line_item.product

Returns the product of this line_item.

Example for getting 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, e.g. "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 Baloon 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.line_price

Returns the combined price of all the items in this line_item. This is quantity times line_item.price.

line_item.tax

Returns the tax that is applicable for this line_item.

line_item.quantity

Returns how many items are represented by this line_item.

line_item.grams

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

line_item.sku

Returns the SKU of the item's product variant.

line_item.vendor

Returns the vendor of this line item.

line_item.product.options

Returns the options of this product as an array, e.g.

['Size', 'Color']

line_item.product.options.first

Returns the first option title of this line item

line_item.product.options.last

Returns the last option title of this line item

line_item.variant.option1

Returns the actual value of line_item.product.options.first for this line item

line_item.variant.options.last

Returns the actual value of line_item.product.options.last for this line item

line_item.variant.options[i]

Returns the actual value of line_item.product.options[i] for this line item, where i is a zero-based index.

line_item.requires_shipping

Returns true if the line item shippable or false if it is a service or a digital good. This must be set on the product details page for each variant. Image:/upload/e/e0/New.gif

line_item.variant.taxable

Returns true if the line item is taxable or false if it is not. This must be set on the product details page for each variant. Image:/upload/e/e0/New.gif

line_item.variant_id

Returns the variant id of the line item. Same as line_item.variant.id. Image:/upload/e/e0/New.gif

line_item.product_id

Returns the product id of the line item. Same as line_item.product.id. Image:/upload/e/e0/New.gif