Migrating a spend threshold amount off script
Two Money.new calls sit in this file and nothing about their syntax says which is the threshold and which is the reward. Whichever a naive reader takes first wins, and the two answers are $100 off and $15 off.
RebuiltIt took a fixed sum off the order once the cart subtotal reached a threshold.
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 D2. This file and its partner look almost identical and behave differently, so read both before you decide which one you have.
THRESHOLD = Money.new(cents: 10000)
REWARD = Money.new(cents: 1500)
if Input.cart.subtotal_price >= THRESHOLD
remaining = REWARD
Input.cart.line_items.each do |line_item|
break if remaining <= Money.zero
share = [line_item.line_price, remaining].min
line_item.change_line_price(line_item.line_price - share, message: "Spend $100, get $15 off")
remaining = remaining - share
end
end
Output.cart = Input.cartRecognised as Amount off the order and rebuilt as a spend_goal 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 | spend_goal | type |
| Counting | per_cart | counting |
| Recurrence | once | recurrence |
| Tier 1 | min spend $100.00 -> $15.00 off each | tiers[0] |
| Target scope | all | target.scope |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Confirm which products this applies to. We could not read product targeting from the script.
- A fixed amount off the order is spread across the items at checkout, so each line shows part of it rather than one line carrying the whole discount.
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 |
|---|---|---|
| Felt Laptop Sleeve | 2 | $38.00 |
| Impact Phone Case | 1 | $24.00 |
| Subtotal | $100.00 | |
| Discount | -$15.00 | |
| Total | $85.00 | |
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 4 of Walnut Desk Organizer at $26.00 and the answer is fixed.
The discount is $15.00. The total the shopper paid is $89.00.
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.
- drop to 1 of the same product, under what the rule needs
| Item | Qty | Unit price |
|---|---|---|
| Felt Laptop Sleeve | 1 | $38.00 |
| Subtotal | $38.00 | |
| Total | $38.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 D2
Spend threshold fixed amount (D2)
RebuiltRebuilt as a spend_goal offer.
Discount on its own cart: $15.00
REWARD = Money.new(cents: 1500)
remaining = REWARD
break if remaining <= Money.zero
share = [line_item.line_price, remaining].min
line_item.change_line_price(line_item.line_price - share, message: "Spend $100, get $15 off")
remaining = remaining - shareSpend threshold percentage (D2)
RebuiltRebuilt as a spend_goal offer.
Discount on its own cart: $15.00
line_item.change_line_price(line_item.line_price * (1.0 - (15 / 100.0)), message: "Spend $100, save 15%")Common questions
- Will Stackable rebuild this script?
- Yes. Every spelling on this page is rebuilt today as a spend_goal offer, and the cart above is the one that proves it.
- What cart proves it works?
- 2 x Felt Laptop Sleeve at $38.00 plus 1 x Impact Phone Case at $24.00. The engine takes $15.00 off, and checkout charges $85.00.
- What will I have to check before publishing?
- Confirm which products this applies to. We could not read product targeting from the script. A fixed amount off the order is spread across the items at checkout, so each line shows part of it rather than one line carrying the whole discount.
Related Script shapes
A percentage that unlocks once the cart is worth enough.
A threshold read from what was left after a code had already come off.
Paste your Script and see it rebuilt
The rebuild is checked against the money your old Script charged before you can publish it.