Skip to content
Scripts examples

Migrating an exclude sale items script

The same intent, often the same comment in the merchant’s own file, and two completely different answers depending on how the markdown was detected. Getting the pair backwards either refuses something we support or leaks margin on every clearance line.

Rebuilt
What the Script did

It skipped any line whose product was already marked down.

Merchants wrote this 2 different ways, and they do not all mean the same thing. Each spelling is below with its own cart and its own numbers.

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.

Exclude sale items tag proxy (D8)

Rebuilt

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

The original Ruby

DISCOUNT_PERCENTAGE = 10

Input.cart.line_items.each do |line_item|
  next if line_item.variant.product.tags.include?("sale")
  new_price = line_item.original_line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0))
  line_item.change_line_price(new_price, message: "10% off full-price items")
end

Output.cart = Input.cart
What it becomes

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

Every setting, spelled out
SettingValueConfig key
Offer typevolumetype
Countingper_productcounting
Recurrenceoncerecurrence
Tier 1min qty 1 -> 10% offtiers[0]
Target scopealltarget.scope
Target excludessaletarget.excludeIds
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
You will be asked to confirm
  • Your Script limited this to a tag, vendor, or product type. We carried that filter over, so confirm it selects the products you expect.
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.

  • Targeting excludes sale. No Meridian Goods product carries those, so every product stays eligible and the exclusion is proved by the campaign settings, not by the cart.
The cart that triggers this offer, and what it costs
ItemQtyUnit price
Braided USB-C Cable1$14.00
Subtotal$14.00
Discount-$1.40
Total$12.60

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 1 of Braided USB-C Cable at $14.00 and the answer is fixed.

The discount is $1.40. The total the shopper paid is $12.60.

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
  • swap the cart for a single Ceramic Travel Mug
The cart that must not trigger this offer
ItemQtyUnit price
Ceramic Travel Mug1$22.00
Subtotal$22.00
Total$22.00

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

Exclude sale items compare at (D8)

Not supported yet

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

The original Ruby

DISCOUNT_PERCENTAGE = 10

Input.cart.line_items.each do |line_item|
  next if line_item.variant.compare_at_price && line_item.variant.compare_at_price > line_item.variant.price
  new_price = line_item.original_line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0))
  line_item.change_line_price(new_price, message: "10% off full-price items")
end

Output.cart = Input.cart
What happens to this one

We have not built this yet

Your Script skipped items that were already marked down. Shopify does give us the sale price, but our checkout query is already at Shopify's cost limit, so we cannot ask for it today. Exclude those products by hand and we can rebuild the rest.

This is our gap, not Shopify's. Shopify permits it and we have not built it, so there is nothing here to link to and nothing to blame the platform for.

Reason key: unsupported.compareAtExclusion

There is no cart to test here, because nothing is built. Pasting this produces the message above and no campaign at all.

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 D8

Exclude sale items tag proxy (D8)

Rebuilt

Rebuilt as a volume offer.

Discount on its own cart: $1.40

Lines that differ
  next if line_item.variant.product.tags.include?("sale")
Read Exclude sale items

Exclude sale items compare at (D8)

Not supported yet

Not rebuilt. We have not built this yet

Lines that differ
  next if line_item.variant.compare_at_price && line_item.variant.compare_at_price > line_item.variant.price
Read Exclude sale items

Common questions

Will Stackable rebuild this script?
It depends on how yours is written. 1 of the 2 spellings on this page are rebuilt today; the rest are refused with a reason. Compare your file against the Ruby above.
What cart proves it works?
1 x Braided USB-C Cable at $14.00. The engine takes $1.40 off, and checkout charges $12.60.
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.
What happens to the part you cannot rebuild?
We have not built this yet. Your Script skipped items that were already marked down. Shopify does give us the sale price, but our checkout query is already at Shopify's cost limit, so we cannot ask for it today. Exclude those products by hand and we can rebuild the rest.

Related Script shapes

Scoped to a tag or vendor

A discount limited to products carrying one tag, vendor or type.

Exclude gift cards

Gift cards left out of a discount that would otherwise have hit them.

Line item property

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.

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