Migrating a spend threshold amount off script
Two Money.new calls sit in this file and nothing about their syntax says which is the threshold and which is the reward. Whichever a naive reader takes first wins, and the two answers are $100 off and $15 off.
RicostruitoIt took a fixed sum off the order once the cart subtotal reached a threshold.
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 D2. Questo file e il suo gemello sembrano quasi identici e si comportano in modo diverso, quindi leggili entrambi prima di decidere quale hai.
THRESHOLD = Money.new(cents: 10000)
REWARD = Money.new(cents: 1500)
if Input.cart.subtotal_price >= THRESHOLD
remaining = REWARD
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: "Spend $100, get $15 off")
remaining = remaining - share
end
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 $100.00 -> $15.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. |
|---|---|---|
| Felt Laptop Sleeve | 2 | $38.00 |
| Impact Phone Case | 1 | $24.00 |
| Subtotale | $100.00 | |
| Sconto | -$15.00 | |
| Totale | $85.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 4 di Walnut Desk Organizer a $26.00 e la risposta è fissata.
Lo sconto è $15.00. Il totale pagato dal cliente è $89.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.
- drop to 1 of the same product, under what the rule needs
| Articolo | Qtà | Prezzo unit. |
|---|---|---|
| Felt Laptop Sleeve | 1 | $38.00 |
| Subtotale | $38.00 | |
| Totale | $38.00 | |
Nessun accesso, oppure accesso come cliente senza tag.
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 D2
Spend threshold fixed amount (D2)
RicostruitoRicostruito come offerta spend_goal.
Sconto sul suo carrello: $15.00
REWARD = Money.new(cents: 1500)
remaining = REWARD
break if remaining <= Money.zero
share = [line_item.line_price, remaining].min
line_item.change_line_price(line_item.line_price - share, message: "Spend $100, get $15 off")
remaining = remaining - shareSpend threshold percentage (D2)
RicostruitoRicostruito come offerta spend_goal.
Sconto sul suo carrello: $15.00
line_item.change_line_price(line_item.line_price * (1.0 - (15 / 100.0)), message: "Spend $100, save 15%")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?
- 2 x Felt Laptop Sleeve at $38.00 plus 1 x Impact Phone Case at $24.00. The engine takes $15.00 off, and checkout charges $85.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 percentage that unlocks once the cart is worth enough.
A threshold read from what was left after a code had already come off.
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.