Migrating an exclude gift cards script
This line rarely arrives on its own. It sits inside somebody else’s script as one guard among several, which is exactly why it gets dropped, and why discounting a gift card is a merchant support ticket rather than a rounding error.
RebuiltIt skipped any line whose product was a gift card.
Paste it into Scripts rescue and watch what it rebuilds
- Copy the Ruby with the button beside any Script on this page.
- In your Shopify admin, open Stackable, then Tools, then Scripts rescue.
- Paste it there, read what the tool says it will build, and compare that with the settings on this page.
Scripts rescue is on the Pro plan. Nothing is published until you tell it what your old Script charged and the two figures match to the cent.
The Script
RebuiltDISCOUNT_PERCENTAGE = 15
Input.cart.line_items.each do |line_item|
next if line_item.variant.product.gift_card?
line_item.change_line_price(
line_item.line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0)),
message: "15% off"
)
end
Output.cart = Input.cartRecognised as Percentage off and rebuilt as a volume offer. These are the real configuration keys the offer is saved with, so you can check your own rebuild against them field by field.
| Setting | Value | Config key |
|---|---|---|
| Offer type | volume | type |
| Counting | per_product | counting |
| Recurrence | once | recurrence |
| Tier 1 | min qty 1 -> 15% off | tiers[0] |
| Target scope | all | target.scope |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Your Script skipped gift cards. We cannot detect gift cards yet, so exclude them by hand in targeting before publishing.
- Confirm which products this applies to. We could not read product targeting from the script.
- Your Script skipped gift cards and we cannot detect them, so gift cards are discounted unless you exclude them in targeting.
Built on our public demo store, Meridian Goods, so every price here can be reproduced rather than taken on trust. The discount below is what the same engine that runs at checkout computes for this exact cart.
| Item | Qty | Unit price |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotal | $14.00 | |
| Discount | -$2.10 | |
| Total | $11.90 | |
Signed out, or signed in as a customer with no tags.
Before publishing, the tool asks what your old Script did to a cart you already have. Set it to 1 of Braided USB-C Cable at $14.00 and the answer is fixed.
The discount is $2.10. The total the shopper paid is $11.90.
The comparison is exact, down to the smallest unit of your currency. One cent out and publishing stays shut, which is the whole point of the step.
This rule carries no condition at all, so it fires on any cart holding anything and there is no quiet cart to build. The negative check is an empty cart, which the app runs for you. That is correct behaviour, not a failure.
Common questions
- Will Stackable rebuild this script?
- Yes. Every spelling on this page is rebuilt today as a volume offer, and the cart above is the one that proves it.
- What cart proves it works?
- 1 x Braided USB-C Cable at $14.00. The engine takes $2.10 off, and checkout charges $11.90.
- What will I have to check before publishing?
- Your Script skipped gift cards. We cannot detect gift cards yet, so exclude them by hand in targeting before publishing. Confirm which products this applies to. We could not read product targeting from the script. Your Script skipped gift cards and we cannot detect them, so gift cards are discounted unless you exclude them in targeting.
Related Script shapes
A discount limited to products carrying one tag, vendor or type.
Already-marked-down products protected from a second discount.
A discount keyed on a property attached to one cart line.
Paste your Script and see it rebuilt
The rebuild is checked against the money your old Script charged before you can publish it.