Migrating a flat rate shipping script
Setting a rate TO a price and taking an amount OFF a rate need different information: the second needs only the discount, the first needs the rate’s own cost. That difference is the whole entry.
Not supported yetIt rewrote every delivery rate to one flat price.
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 yetDanger pair D4. This file and its partner look almost identical and behave differently, so read both before you decide which one you have.
# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP
class FixedPriceDiscount
def initialize(amount, message)
@amount = Money.new(cents: 100) * amount
@message = message
end
def apply(rate)
rate_discount = @amount > rate.price ? rate.price : rate.price - @amount
rate.apply_discount(rate_discount, { message: @message })
end
end
CAMPAIGNS = [
ShippingDiscount.new(:all, nil, nil, FixedPriceDiscount.new(5, "Flat rate shipping $5")),
].freeze
CAMPAIGNS.each do |campaign|
campaign.run(Input.shipping_rates, Input.cart)
end
Output.shipping_rates = Input.shipping_ratesWe have not built this yet
Your Script set shipping to a fixed price. We can take an amount or a percentage off shipping, but setting a rate to a price needs the rate's own cost, which we do not read yet.
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.shippingFixedPrice
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 D4
Shipping fixed price (D4)
Not supported yetNot rebuilt. We have not built this yet
class FixedPriceDiscount
rate_discount = @amount > rate.price ? rate.price : rate.price - @amount
ShippingDiscount.new(:all, nil, nil, FixedPriceDiscount.new(5, "Flat rate shipping $5")),Shipping fixed amount off (D4)
RebuiltRebuilt as a free_shipping offer.
Delivery saving on its own cart: $5.00
class FixedDiscount
rate_discount = rate.price - @amount < Money.zero ? rate.price : @amount
ShippingDiscount.new(:all, nil, nil, FixedDiscount.new(5, "$5 off shipping")),Common questions
- Will Stackable rebuild this script?
- No, and the reason is stated rather than hidden: Your Script set shipping to a fixed price. We can take an amount or a percentage off shipping, but setting a rate to a price needs the rate's own cost, which we do not read yet.
Related Script shapes
A flat sum off the delivery charge, floored at free.
A share taken off every delivery rate at checkout.
Delivery drops to free once the cart is worth enough.
Paste your Script and see it rebuilt
The rebuild is checked against the money your old Script charged before you can publish it.