Skip to content
Scripts examples

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.

Rebuilt
What the Script did

It took a fixed sum off the order once the cart subtotal reached a threshold.

Run it against your own store

Paste it into Scripts rescue and watch what it rebuilds

  1. Copy the Ruby with the button beside any Script on this page.
  2. In your Shopify admin, open Stackable, then Tools, then Scripts rescue.
  3. 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

Rebuilt

Danger pair D2. This file and its partner look almost identical and behave differently, so read both before you decide which one you have.

The original Ruby

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.cart
What it becomes

Recognised 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.

Every setting, spelled out
SettingValueConfig key
Offer typespend_goaltype
Countingper_cartcounting
Recurrenceoncerecurrence
Tier 1min spend $100.00 -> $15.00 off eachtiers[0]
Target scopealltarget.scope
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
You will be asked to confirm
  • Confirm which products this applies to. We could not read product targeting from the script.
You will be told
  • 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.
The cart that proves it

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.

The cart that triggers this offer, and what it costs
ItemQtyUnit price
Felt Laptop Sleeve2$38.00
Impact Phone Case1$24.00
Subtotal$100.00
Discount-$15.00
Total$85.00

Signed out, or signed in as a customer with no tags.

The figure the tool checks you against

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.

The cart that must produce nothing
  • drop to 1 of the same product, under what the rule needs
The cart that must not trigger this offer
ItemQtyUnit price
Felt Laptop Sleeve1$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)

Rebuilt

Rebuilt as a spend_goal offer.

Discount on its own cart: $15.00

Lines that differ
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 - share
Read Spend threshold, amount off

Spend threshold percentage (D2)

Rebuilt

Rebuilt as a spend_goal offer.

Discount on its own cart: $15.00

Lines that differ
    line_item.change_line_price(line_item.line_price * (1.0 - (15 / 100.0)), message: "Spend $100, save 15%")
Read Spend threshold, percentage

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

Spend threshold, percentage

A percentage that unlocks once the cart is worth enough.

Discounted cart subtotal

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.

We use essential cookies to run this site, and, only with your permission, analytics cookies to understand traffic. Read our Cookie Policy.