> For the complete documentation index, see [llms.txt](https://headless.intelligems.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://headless.intelligems.io/usage/update-atc-events/shopify-plus-+-scripts.md).

# Shopify Plus + Scripts

{% hint style="info" %}
Shopify is deprecating Checkout Scripts! Intelligems highly recommends using functions instead.
{% endhint %}

## Add `useIgCart()`

* Use the [`useIgCart()`](/reference/hooks/cart-and-checkout-hooks.md#useigcart) hook if your site uses the Storefront **Cart** API.
* Wrap ATC calls with the `wrapCustomAttributes` function returned by `useIgCart` when you need line item properties (for example, shipping tests).

## Add Intelligems Script to `checkout.liquid`

The Intelligems script may be found under *settings* at [app.intelligems.io](https://app.intelligems.io). Copy this script tag and add it to the header of `checkout.liquid`.

## Add Intelligems Checkout Script to Script Editor

Add the following script to your Script Editor app as a line item discount.

{% code overflow="wrap" %}

```ruby
class Intelligems
  def initialize(discount_property = '_igp', allow_free = false)
    @volume_discount_property = '_igvd'
    @volume_discount_message_property = '_igvd_message'
    @depreciated_property = '_igLineItemDiscount'
    @discount_property = discount_property
    @allow_free = allow_free
  end

  def discount_product(line_item)
    ig_price = Money.new(cents: line_item.properties[@discount_property])

    discount = line_item.line_price - ig_price
    if discount > Money.zero
      discount *= line_item.quantity
      line_item.change_line_price(line_item.line_price - discount, message: 'Discount')
    end

  end

  def depreciated_discount_product(line_item)
    discount = Money.new(cents: line_item.properties[@depreciated_property])
    discount *= line_item.quantity

    if @allow_free or discount < line_item.line_price
      line_item.change_line_price(line_item.line_price - discount, message: 'Intelligems')
    end
  end

  def volume_discount(line_item)
    discount = Money.new(cents: line_item.properties[@volume_discount_property])
    discount *= line_item.quantity

    if discount < line_item.line_price
      message = line_item.properties[@volume_discount_message_property]
      line_item.change_line_price(line_item.line_price - discount, message: message)
    end
  end

  def run(cart)
    cart.line_items.each do |line_item|
      if !line_item.properties[@discount_property].nil? && !line_item.properties[@discount_property].empty?
        discount_product(line_item)
      elsif !line_item.properties[@volume_discount_property].nil? && !line_item.properties[@volume_discount_property].empty?
        volume_discount(line_item)
      elsif !line_item.properties[@depreciated_property].nil? && !line_item.properties[@depreciated_property].empty?
             depreciated_discount_product(line_item)
      end
    end
  end
end

intelligems = Intelligems.new()
intelligems.run(Input.cart)

Output.cart = Input.cart
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://headless.intelligems.io/usage/update-atc-events/shopify-plus-+-scripts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
