Migrating a script that set a fixed price per item
This is the single most expensive misreading in the whole migration. On an $80 item, "set it to $9.99" and "take $9.99 off" differ by $70.01, and the two files are one minus sign apart.
RebuiltIt replaced the price of every matching unit with one flat amount.
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
RebuiltDanger pair D1. This file and its partner look almost identical and behave differently, so read both before you decide which one you have.
FIXED_PRICE = Money.new(cents: 999)
Input.cart.line_items.each do |line_item|
next unless line_item.variant.product.product_type == "Clearance"
line_item.change_line_price(FIXED_PRICE * line_item.quantity, message: "Clearance $9.99 each")
end
Output.cart = Input.cartRecognised as Fixed price per item 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_variant | counting |
| Recurrence | repeat | recurrence |
| Tier 1 | min qty 1 -> $9.99 set price | tiers[0] |
| Target scope | product_types | target.scope |
| Target includes | Clearance | target.includeIds |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Your Script limited this to a tag, vendor, or product type. We carried that filter over, so confirm it selects the products you expect.
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.
- No Meridian Goods product carries the type Clearance. Set it on Aria Wireless Earbuds in Shopify before you build the cart, and on nothing else.
| Item | Qty | Unit price |
|---|---|---|
| Aria Wireless Earbuds | 1 | $79.00 |
| Subtotal | $79.00 | |
| Discount | -$69.01 | |
| Total | $9.99 | |
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 Aria Wireless Earbuds at $79.00 and the answer is fixed.
The discount is $69.01. The total the shopper paid is $9.99.
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.
- swap the cart for a single Braided USB-C Cable
| Item | Qty | Unit price |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotal | $14.00 | |
| Total | $14.00 | |
Signed out, or signed in as a customer with no tags.
Two files that look the same
Each pair below is one Script shape written two ways. They differ by a line or two and they do different things, so read both before deciding which one you have.
Danger pair D1
Fixed price per unit (D1)
RebuiltRebuilt as a volume offer.
Discount on its own cart: $69.01
FIXED_PRICE = Money.new(cents: 999)
line_item.change_line_price(FIXED_PRICE * line_item.quantity, message: "Clearance $9.99 each")Amount off per unit (D1)
RebuiltRebuilt as a volume offer.
Discount on its own cart: $9.99
DISCOUNT = Money.new(cents: 999)
new_price = line_item.line_price - (DISCOUNT * line_item.quantity)
line_item.change_line_price(new_price, message: "$9.99 off each")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 Aria Wireless Earbuds at $79.00. The engine takes $69.01 off, and checkout charges $9.99.
- What will I have to check before publishing?
- Your Script limited this to a tag, vendor, or product type. We carried that filter over, so confirm it selects the products you expect.
Related Script shapes
A flat sum taken off every unit, however many the shopper bought.
One lump sum off the whole cart, spread across the lines.
One percentage off the whole catalogue, with no condition attached.
Paste your Script and see it rebuilt
The rebuild is checked against the money your old Script charged before you can publish it.