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.
Stöds inte änIt rewrote every delivery rate to one flat price.
Klistra in det i Scripts-räddning och se vad som byggs
- Kopiera Ruby-koden med knappen bredvid vilket Script som helst på sidan.
- Öppna Stackable i Shopify-adminen, sedan Verktyg, sedan Scripts-räddning.
- Klistra in det där, läs vad verktyget säger att det ska bygga och jämför med inställningarna på den här sidan.
Scripts-räddning ingår i Pro-planen. Ingenting publiceras förrän du anger vad ditt gamla Script gav i rabatt och båda beloppen stämmer på öret.
Detta Script
Stöds inte änRiskabelt par D4. Den här filen och dess motpart ser nästan likadana ut och beter sig olika, så läs båda innan du avgör vilken du har.
# 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.
Det här är vår lucka, inte Shopifys. Shopify tillåter det och vi har inte byggt det, så det finns inget att länka till här och inget att skylla på plattformen.
Orsaksnyckel: unsupported.shippingFixedPrice
Det finns ingen varukorg att testa här, eftersom ingenting byggs. Att klistra in det här ger meddelandet ovan och ingen kampanj alls.
Två filer som ser likadana ut
Varje par nedan är samma Script-form skriven på två sätt. De skiljer sig åt på en eller två rader och gör olika saker, så läs båda innan du avgör vilken du har.
Farligt par D4
Shipping fixed price (D4)
Stöds inte änByggs inte om. 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)
OmbyggtByggs om till ett free_shipping-erbjudande.
Fraktbesparing i sin egen varukorg: $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")),Vanliga frågor
- 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.
Besläktade Script-former
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.
Klistra in ditt Script och se det byggas om
Ombyggnaden stäms av mot beloppet som ditt gamla Script tog ut innan du kan publicera den.