Migrating a discount code pattern script
Worth knowing that Shopify Scripts had no regular expressions at all, so every one of these matched by hand with start_with or a substring check on the code.
Not supported yetIt matched any code beginning with a given prefix and applied one rule to all of them.
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
Not supported yetCODE_PREFIX = "STAFF-"
DISCOUNT_PERCENTAGE = 30
code = Input.cart.discount_code
unless code.nil?
if code.code.upcase.start_with?(CODE_PREFIX)
Input.cart.line_items.each do |line_item|
line_item.change_line_price(
line_item.line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0)),
message: "Staff discount"
)
end
end
end
Output.cart = Input.cartWe have not built this yet
Your Script matched a whole family of discount codes by prefix or wildcard. Our codes are exact, one at a time.
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.codePattern
There is no cart to test here, because nothing is built. Pasting this produces the message above and no campaign at all.
Common questions
- Will Stackable rebuild this script?
- No, and the reason is stated rather than hidden: Your Script matched a whole family of discount codes by prefix or wildcard. Our codes are exact, one at a time.
Related Script shapes
A code the shopper typed, turned away at checkout with a message.
Script logic that only ran when the shopper had typed a particular code.
Paste your Script and see it rebuilt
The rebuild is checked against the money your old Script charged before you can publish it.