Migrating a fixed amount off the order script
Its per-item twin has the same constructor, the same literal and the same message string. On a ten-item cart one gives away $5 and the other gives away $50, so the pair is shown together deliberately.
RicostruitoIt reduced the cart total by one fixed sum, spread across the lines.
I merchant lo hanno scritto in 2 modi diversi, e non significano tutti la stessa cosa. Ogni variante è riportata sotto con il proprio carrello e i propri numeri.
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.
Fixed total discount cart (D7)
RicostruitoCoppia rischiosa D7. 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 FixedTotalDiscount
def initialize(amount, message, behaviour = :split)
@amount = Money.new(cents: 100) * amount
@message = message
@discount_applied = Money.zero
@behaviour = behaviour
end
def apply(line_item)
return unless @discount_applied < @amount
discount_to_apply = [(@amount - @discount_applied), line_item.line_price].min
line_item.change_line_price(line_item.line_price - discount_to_apply, message: @message)
@discount_applied += discount_to_apply
end
end
CAMPAIGNS = [
ConditionalDiscount.new(:all, nil, nil, nil, FixedTotalDiscount.new(5, "$5 off your order"), 0),
].freeze
CAMPAIGNS.each do |campaign|
campaign.run(Input.cart)
end
Output.cart = Input.cartRiconosciuto come Amount off the order e ricostruito come offerta di tipo spend_goal. 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 | spend_goal | 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.
- A fixed amount off the order is spread across the items at checkout, so each line shows part of it rather than one line carrying the whole discount.
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 | |
| Sconto | -$5.00 | |
| Totale | $9.00 | |
Nessun accesso, oppure accesso come cliente senza tag.
Prima della pubblicazione, lo strumento chiede cosa faceva il tuo vecchio Script a un carrello che hai già. Impostalo su 1 di Braided USB-C Cable a $14.00 e la risposta è fissata.
Lo sconto è $5.00. Il totale pagato dal cliente è $9.00.
Il confronto è esatto, fino alla più piccola unità della tua valuta. Un centesimo di scarto e la pubblicazione resta bloccata, che è tutto il senso di questo passaggio.
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.
Fixed total discount cart (D10)
RicostruitoCoppia rischiosa D10. Questo file e il suo gemello sembrano quasi identici e si comportano in modo diverso, quindi leggili entrambi prima di decidere quale hai.
MAX_DISCOUNT = Money.new(cents: 10000)
remaining = MAX_DISCOUNT
Input.cart.line_items.each do |line_item|
break if remaining <= Money.zero
share = [line_item.line_price, remaining].min
line_item.change_line_price(line_item.line_price - share, message: "$100 off your order")
remaining = remaining - share
end
Output.cart = Input.cartRiconosciuto come Amount off the order e ricostruito come offerta di tipo spend_goal. 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 | spend_goal | type |
| Counting | per_cart | counting |
| Recurrence | once | recurrence |
| Tier 1 | min spend $0.00 -> $100.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.
- A fixed amount off the order is spread across the items at checkout, so each line shows part of it rather than one line carrying the whole discount.
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 | |
| Sconto | -$14.00 | |
| Totale | $0.00 | |
Nessun accesso, oppure accesso come cliente senza tag.
Prima della pubblicazione, lo strumento chiede cosa faceva il tuo vecchio Script a un carrello che hai già. Impostalo su 1 di Braided USB-C Cable a $14.00 e la risposta è fissata.
Lo sconto è $14.00. Il totale pagato dal cliente è $0.00.
Il confronto è esatto, fino alla più piccola unità della tua valuta. Un centesimo di scarto e la pubblicazione resta bloccata, che è tutto il senso di questo passaggio.
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 D7
Fixed total discount cart (D7)
RicostruitoRicostruito come offerta spend_goal.
Sconto sul suo carrello: $5.00
class FixedTotalDiscount
def initialize(amount, message, behaviour = :split)
@discount_applied = Money.zero
@behaviour = behaviour
return unless @discount_applied < @amount
discount_to_apply = [(@amount - @discount_applied), line_item.line_price].minE altre 3 righe diverse, sulla sua pagina.
Amount off per unit (D7)
RicostruitoRicostruito come offerta volume.
Sconto sul suo carrello: $5.00
class FixedItemDiscount
def initialize(amount, message)
per_item_discount = @amount
discount_to_apply = [(per_item_discount * line_item.quantity), line_item.line_price].min
line_item.change_line_price([line_item.line_price - discount_to_apply, Money.zero].max, message: @message)
ConditionalDiscount.new(:all, nil, nil, nil, FixedItemDiscount.new(5, "$5 off each"), 0),Coppia insidiosa D10
Fixed total discount cart (D10)
RicostruitoRicostruito come offerta spend_goal.
Sconto sul suo carrello: $14.00
MAX_DISCOUNT = Money.new(cents: 10000)
remaining = MAX_DISCOUNT
break if remaining <= Money.zero
share = [line_item.line_price, remaining].min
line_item.change_line_price(line_item.line_price - share, message: "$100 off your order")
remaining = remaining - shareCapped percentage discount (D10)
RicostruitoRicostruito come offerta spend_goal.
Sconto sul suo carrello: $50.00
DISCOUNT_PERCENTAGE = 25
MAX_DISCOUNT = 50
cart_subtotal_float = Float((Input.cart.subtotal_price.cents / 100).to_s)
raw_discount = cart_subtotal_float * (DISCOUNT_PERCENTAGE / 100.0)
total_discount = [raw_discount, MAX_DISCOUNT].min
line_price_float = Float((line_item.line_price.cents / 100).to_s)E altre 2 righe diverse, sulla sua pagina.
Domande frequenti
- Will Stackable rebuild this script?
- Yes. Every spelling on this page is rebuilt today as a spend_goal 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 $9.00.
- What will I have to check before publishing?
- Confirm which products this applies to. We could not read product targeting from the script. A fixed amount off the order is spread across the items at checkout, so each line shows part of it rather than one line carrying the whole discount.
Forme di Script correlate
A flat sum taken off every unit, however many the shopper bought.
A percentage with a ceiling on it, so a large cart never gave away more than a set maximum.
Everything in the clearance line repriced to one round number per unit.
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.