# Line item

A line_item represents a single line in the cart.

A `line_item` represents a single line in the cart. There is one line item in the cart for each distinct product variant. The `line_item` object is available in all Liquid templates through `cart.items`, in email notification templates through `line_items`, on the order status page of the checkout, and in apps such as order printers.

Money attributes such as prices and totals are returned in the customer's local (presentment) currency. Use a money filter to show the result as a money amount.

The `line_item` object has the following attributes:

## line_item.discount_allocations

Returns a list of all discount allocations, each with the discounted amount and a reference to the parent discount application. `line_item.discount_allocations` is available for line items in carts, checkouts, orders and draft orders.

## line_item.final_line_price

Returns the combined price of all items in the line item. This equals `line_item.final_price` times `line_item.quantity`.

## line_item.final_price

Returns the price of the line item including all line-level discounts.

## line_item.fulfillment

Returns the [fulfillment](https://developer.versacommerce.de/articles/liquid-objects-fulfillment) of the line item.

## line_item.fulfillment_service

Returns the fulfillment service of the line item's variant. Line items without a fulfillment service return `manual`.

## line_item.gift_card

Returns `true` if the line item's product is a gift card, `false` otherwise.

## line_item.grams

Returns the weight of the line item.

Use the [weight_with_unit](https://developer.versacommerce.de/articles/liquid-filters-additional-filters#weightwithunit) filter to format the weight.

## line_item.id

Returns the line item ID.

The ID depends on the context:

- [cart.items](https://developer.versacommerce.de/articles/liquid-objects-cart#cart-items) returns the ID of the line item's variant. This ID is not unique and can be shared by several items of the same variant.
- [checkout.line_items](https://developer.versacommerce.de/articles/liquid-objects-checkout#checkout-lineitems) returns a temporary unique hash generated for the checkout.
- [order.line_items](https://developer.versacommerce.de/articles/liquid-objects-order#order-lineitems) returns a unique integer ID.

## line_item.image

Returns the image of the line item.

You can apply the `image_url` filter directly to the line item instead of its image attribute. This creates a working image URL for any object with an image attribute (variant, product, article, collection), an image object or an image src. For line items this is useful because it returns the variant image, or the product image if there is no variant image.

The output is the same whether you use `image_url` on `line_item` or on `line_item.image`.

```liquid
{{ line_item.image | image_url: width: 100, height: 100 | image_tag: srcset: nil }}
{{ line_item | image_url: width: 100, height: 100 | image_tag: srcset: nil }}
```

```html
<img src="//cdn.versacommerce.de/s/files/1/0159/3350/products/hvt401_red.jpg?v=1398706734&width=100&height=100&crop=center" width="100" height="100">
<img src="//cdn.versacommerce.de/s/files/1/0159/3350/products/hvt401_red.jpg?v=1398706734&width=100&height=100&crop=center" width="100" height="100">
```

## line_item.key

Returns the line item key, a unique identifier for the line item. The key is built from the ID of the line item's variant and a hash of the line item's properties, even if the line item has no properties.

```liquid
{{ line_item.key }}
```

```text
17285644550:70ff98a797ed385f6ef25e6e974708ca
```

## line_item.line_level_discount_allocations

Returns a list of line-specific discount allocations, each with the discounted amount and a reference to the parent discount application.

## line_item.line_level_total_discount

Returns the total amount of all discounts applied to this line item. Discounts added to the cart as a whole are not included.

## line_item.message

Returns the discount message if a script applied a discount to the line item.

## line_item.options_with_values

Returns an array of the selected values from the item's [product options](https://developer.versacommerce.de/articles/liquid-objects-productoption).

Show the elements of `line_item.options_with_values` with a `for` loop. Each option is a key-value pair with `option.name` as the option and `option.value` as the option value.

Use `product.has_only_default_variant` to check whether the line item has only a default variant. If so, do not show variant information, because the product has no custom variant options.

```liquid
{% unless line_item.product.has_only_default_variant %}
  <ul>
    {% for option in line_item.options_with_values %}
      <li>{{ option.name }}: {{ option.value }}</li>
    {% endfor %}
  </ul>
{% endunless %}
```

```html
<ul>
  <li>Size: 42mm</li>
  <li>Color: Silver</li>
  <li>Material: Stainless Steel</li>
</ul>
```

## line_item.original_line_price

Returns the combined price of all items in the line before discounts. This equals `line_item.original_price` times `line_item.quantity`.

## line_item.original_price

Returns the original price of the line item before discounts.

## line_item.product

Returns the [product](https://developer.versacommerce.de/articles/liquid-objects-product) of the line item.

## line_item.product_id

Returns the ID of the line item's product.

## line_item.properties

Returns an array of custom information for an item added to the cart.

Use line item properties on product pages to collect customization information, for example engraving text.

Collect line item properties on the product page with an input in the [product form](https://developer.versacommerce.de/articles/liquid-tags-theme-tags#form). The input needs a `name` attribute with this syntax:

```text
properties[property-name]
```

For example, this input collects engraving text for a product:

```liquid
{% form 'product', product %}
  ...
  <label for="engravingText">Engraving</label>
  <input type="text" id="engravingText" name="properties[Engraving]">
  ...
{% endform %}
```

Start a property name with an underscore to hide it from customers at checkout, for example `properties[_hiddenPropertyName]`.

Output the properties by looping through `line_item.properties`:

```liquid
{% unless line_item.properties == empty %}
  <ul>
  {% for property in line_item.properties %}
    <li>{{ property.first }}: {{ property.last }}</li>
  {% endfor %}
  </ul>
{% endunless %}
```

```html
<ul>
  <li>Monogram: My dog is the cutest</li>
  <li>Gift wrap: Yes</li>
</ul>
```

## line_item.quantity

Returns the quantity of the line item.

## line_item.requires_shipping

Returns `true` if the line item's variant requires shipping, `false` otherwise.

## line_item.selling_plan_allocation

Returns a `selling_plan_allocation` object if the line item has a selling plan. VersaCommerce currently has no selling plans, so this value is empty.

## line_item.sku

Returns the SKU (stock keeping unit) of the line item's variant.

## line_item.successfully_fulfilled_quantity

Returns the quantity of the line item that was fulfilled successfully.

## line_item.taxable

Returns `true` if taxes are charged on the line item's variant, `false` otherwise.

## line_item.title

Returns the title of the line item. `line_item.title` combines the line item's `product.title` and `variant.title`, separated by a hyphen.

```liquid
{{ line_item.title }}
```

```text
Balloon Shirt - M
```

To output only the product title or the variant title, use the `title` of the respective object.

```liquid
Product title: {{ line_item.product.title }}
Variant title: {{ line_item.variant.title }}
```

```text
Product title: Balloon Shirt
Variant title: M
```

## line_item.unit_price

Returns the unit price of the line item. The price reflects all discounts applied to the line item.

## line_item.unit_price_measurement

Returns a [unit_price_measurement object](https://developer.versacommerce.de/articles/liquid-objects-unitpricemeasurement) for the line item.

## line_item.url

Returns the relative URL of the line item's variant. The relative URL does not include the root URL of your shop.

## line_item.url_to_remove

Returns a URL that removes the line item from the cart. Only available for cart line items.

## line_item.variant

Returns the [variant](https://developer.versacommerce.de/articles/liquid-objects-variant) of the line item.

## line_item.variant_id

Returns the ID of the line item's variant.

## line_item.vendor

Returns the vendor of the line item's product.


## More properties

VersaCommerce also provides these properties on the `line_item` object:

| Properties | Returns |
|---|---|
| `instructions`, `options`, `extra_price`, `tax_rate`, `tax_lines`, `errors`, `error_message` | Editing flags, stored options, price adjustments, tax and validation state |
