Migrating an amount off shipping script
Two classes in the generator library are one word apart and inverted. On a $30 rate, one leaves the shopper paying $25 and the other leaves them paying $5, and the bodies are almost the same ternary.
RicostruitoIt subtracted a fixed sum from every delivery rate, never taking it below free.
Incollalo in Recupero Script e guarda cosa ricostruisce
- Copia il Ruby con il pulsante accanto a ogni Script di questa pagina.
- Nell'admin di Shopify apri Stackable, poi Strumenti, poi Recupero Script.
- Incollalo lì, leggi cosa dichiara di costruire lo strumento e confrontalo con le impostazioni di questa pagina.
Recupero Script è nel piano Pro. Non viene pubblicato nulla finché non dichiari quanto scontava il vecchio Script e le due cifre non coincidono al centesimo.
Lo Script
RicostruitoCoppia rischiosa D4. Questo file e il suo gemello sembrano quasi identici e si comportano in modo diverso, quindi leggili entrambi prima di decidere quale hai.
# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP
class FixedDiscount
def initialize(amount, message)
@amount = Money.new(cents: 100) * amount
@message = message
end
def apply(rate)
rate_discount = rate.price - @amount < Money.zero ? rate.price : @amount
rate.apply_discount(rate_discount, { message: @message })
end
end
CAMPAIGNS = [
ShippingDiscount.new(:all, nil, nil, FixedDiscount.new(5, "$5 off shipping")),
].freeze
CAMPAIGNS.each do |campaign|
campaign.run(Input.shipping_rates, Input.cart)
end
Output.shipping_rates = Input.shipping_ratesRiconosciuto come Shipping discount e ricostruito come offerta di tipo free_shipping. Queste sono le vere chiavi di configurazione con cui l'offerta viene salvata, così puoi confrontare la tua ricostruzione campo per campo.
| Impostazione | Valore | Chiave di configurazione |
|---|---|---|
| Offer type | free_shipping | type |
| Counting | per_cart | counting |
| Recurrence | once | recurrence |
| Tier 1 | min spend $0.00 -> $5.00 off each | tiers[0] |
| Target scope | all | target.scope |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Confirm which products this applies to. We could not read product targeting from the script.
- This discounts every shipping rate at checkout, not one named rate.
Creato sul nostro negozio demo pubblico, Meridian Goods, così ogni prezzo qui si può riprodurre invece di doverci credere sulla parola. Lo sconto qui sotto è quello che lo stesso motore che gira al checkout calcola per questo esatto carrello.
| Articolo | Qtà | Prezzo unit. |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotale | $14.00 | |
| Consegna, di norma $6.90 | $1.90 | |
| Totale | $14.00 | |
Nessun accesso, oppure accesso come cliente senza tag.
This rebuild only changes shipping. We price shipping against a sample rate rather than the rate your shopper saw, so there is no figure here we could honestly compare. Publishing records that the amount was not checked.
This rule carries no condition at all, so it fires on any cart holding anything and there is no quiet cart to build. The negative check is an empty cart, which the app runs for you. That is correct behaviour, not a failure.
Due file che sembrano uguali
Ogni coppia qui sotto è la stessa forma di Script scritta in due modi. Cambiano una o due righe e fanno cose diverse, quindi leggile entrambe prima di decidere quale hai.
Coppia insidiosa D4
Shipping fixed amount off (D4)
RicostruitoRicostruito come offerta free_shipping.
Risparmio di spedizione sul suo carrello: $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")),Shipping fixed price (D4)
Non ancora supportatoNon ricostruito. 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")),Domande frequenti
- Will Stackable rebuild this script?
- Yes. Every spelling on this page is rebuilt today as a free_shipping offer, and the cart above is the one that proves it.
- What cart proves it works?
- 1 x Braided USB-C Cable at $14.00. The engine takes $5.00 off, and checkout charges $14.00 plus $1.90 delivery.
- What will I have to check before publishing?
- Confirm which products this applies to. We could not read product targeting from the script. This discounts every shipping rate at checkout, not one named rate.
Forme di Script correlate
Every delivery rate rewritten to one price rather than reduced by an amount.
A share taken off every delivery rate at checkout.
Delivery drops to free once the cart is worth enough.
Incolla il tuo Script e guardalo ricostruito
La ricostruzione viene confrontata con l'importo che il tuo vecchio Script applicava, prima che tu possa pubblicarla.