Vai al contenuto
Esempi di Script

Migrating a buy one get one free script

Shopify shipped this as a starter template, so it is everywhere. The line that matters divides the quantity by the paid units PLUS the free one, which is what makes a nine-unit cart earn two free instead of three.

Ricostruito
Cosa faceva lo Script

It split the free units off each complete set and repriced them to zero.

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

BUY = 3
GET = 1

Input.cart.line_items.each do |line_item|
  sets = line_item.quantity / (BUY + GET)
  free_count = sets * GET
  next if free_count == 0
  discounted = line_item.split(take: free_count)
  discounted.change_line_price(Money.zero, message: "Buy 3 get 1 free")
  Input.cart.line_items << discounted
end

Output.cart = Input.cart
In cosa si trasforma

Riconosciuto come Buy X, get Y e ricostruito come offerta di tipo bxgy. 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 typebxgytype
Countingper_groupcounting
Recurrencerepeatrecurrence
Tier 1min qty 3 -> free itemtiers[0]
Buy quantity3bxgy.buyQty
Get quantity1bxgy.getQty
Get selectionsame_itembxgy.getSelection
Reward on the get units100% offbxgy.getDiscountPct
Free units are additionaltruebxgy.freeUnitsAreAdditional
Target scopealltarget.scope
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.
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.
Braided USB-C Cable4$14.00
Subtotale$56.00
Sconto-$14.00
Totale$42.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 4 di Braided USB-C Cable a $14.00 e la risposta è fissata.

Lo sconto è $14.00. Il totale pagato dal cliente è $42.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
  • drop to 1 of the same product, under what the rule needs
Il carrello che non deve attivare questa offerta
ArticoloQtàPrezzo unit.
Braided USB-C Cable1$14.00
Subtotale$14.00
Totale$14.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 D3

Bogo same item free (D3)

Ricostruito

Ricostruito come offerta bxgy.

Sconto sul suo carrello: $14.00

Righe che cambiano
  sets = line_item.quantity / (BUY + GET)
Leggi Buy one get one free

Bogo inclusive basis (D3)

Ricostruito

Ricostruito come offerta bxgy.

Sconto sul suo carrello: $14.00

Righe che cambiano
  sets = line_item.quantity / BUY
Leggi Buy X get Y, inclusive

Domande frequenti

Will Stackable rebuild this script?
Yes. Every spelling on this page is rebuilt today as a bxgy offer, and the cart above is the one that proves it.
What cart proves it works?
4 x Braided USB-C Cable at $14.00. The engine takes $14.00 off, and checkout charges $42.00.
What will I have to check before publishing?
Confirm which products this applies to. We could not read product targeting from the script.

Forme di Script correlate

Buy X get Y, inclusive

The same buy-and-get offer, counted so the reward sits inside each set rather than beside it.

Limit the discounted units

The discount applied to the first few units only, with the rest at full price.

Percentage off the cheapest item

The least expensive thing in the cart discounted, once.

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.