Vai al contenuto
Esempi di Script

Migrating a capped percentage discount script

Common on high-value carts and the one place where getting it wrong is wrong in both directions at once: read the cap as the discount and you give $50 flat, drop the cap and you give an uncapped quarter of the cart.

Ricostruito
Cosa faceva lo Script

It worked out a percentage of the cart and then refused to take off more than a stated maximum.

Provalo sul tuo negozio

Incollalo in Recupero Script e guarda cosa ricostruisce

  1. Copia il Ruby con il pulsante accanto a ogni Script di questa pagina.
  2. Nell'admin di Shopify apri Stackable, poi Strumenti, poi Recupero Script.
  3. 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

Ricostruito

Coppia 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.

Il Ruby originale

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

Input.cart.line_items.each do |line_item|
  line_price_float = Float((line_item.line_price.cents / 100).to_s)
  percentage = 1 - (((line_price_float / cart_subtotal_float) * total_discount) / line_price_float)
  line_item.change_line_price(line_item.line_price * percentage, message: "25% off, up to $50")
end

Output.cart = Input.cart
In cosa si trasforma

Riconosciuto come Spend threshold discount 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.

Ogni impostazione, nel dettaglio
ImpostazioneValoreChiave di configurazione
Offer typespend_goaltype
Countingper_cartcounting
Recurrenceoncerecurrence
Tier 1min spend $0.00 -> 25% offtiers[0]
Target scopealltarget.scope
Maximum discount$50.00maxDiscountAmount
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
Ti verrà chiesta una conferma
  • Confirm which products this applies to. We could not read product targeting from the script.
Ti verrà comunicato
  • The maximum applies to the whole order and is shared across the discounted items. If your Script capped each line on its own, that gave more away than this does.
Il carrello che lo dimostra

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.

Il carrello che attiva questa offerta, e quanto costa
ArticoloQtàPrezzo unit.
Canvas Belt Bag1$42.00
Aria Wireless Earbuds2$79.00
Subtotale$200.00
Sconto-$50.00
Totale$150.00

Nessun accesso, oppure accesso come cliente senza tag.

La cifra con cui lo strumento ti confronta

Prima della pubblicazione, lo strumento chiede cosa faceva il tuo vecchio Script a un carrello che hai già. Impostalo su 8 di Walnut Desk Organizer a $26.00 e la risposta è fissata.

Lo sconto è $50.00. Il totale pagato dal cliente è $158.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.

Il carrello che non deve produrre nulla

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 D10

Capped percentage discount (D10)

Ricostruito

Ricostruito come offerta spend_goal.

Sconto sul suo carrello: $50.00

Righe che cambiano
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.

Leggi Capped percentage discount

Fixed total discount cart (D10)

Ricostruito

Ricostruito come offerta spend_goal.

Sconto sul suo carrello: $14.00

Righe che cambiano
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 - share
Leggi Amount off the order

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 Canvas Belt Bag at $42.00 plus 2 x Aria Wireless Earbuds at $79.00. The engine takes $50.00 off, and checkout charges $150.00.
What will I have to check before publishing?
Confirm which products this applies to. We could not read product targeting from the script. The maximum applies to the whole order and is shared across the discounted items. If your Script capped each line on its own, that gave more away than this does.

Forme di Script correlate

Amount off the order

One lump sum off the whole cart, spread across the lines.

Fixed price per item

Everything in the clearance line repriced to one round number per unit.

Amount off each item

A flat sum taken off every unit, however many the shopper bought.

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.

Utilizziamo cookie essenziali per il funzionamento del sito e, solo con il Suo consenso, cookie di analisi per comprendere il traffico. Legga la nostra Informativa sui Cookie.