Vai al contenuto
Esempi di Script

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.

Ricostruito
Cosa faceva lo Script

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

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.

Fixed total discount cart (D7)

Ricostruito

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

Il Ruby originale

# 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.cart
In cosa si trasforma

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

Ogni impostazione, nel dettaglio
ImpostazioneValoreChiave di configurazione
Offer typespend_goaltype
Countingper_cartcounting
Recurrenceoncerecurrence
Tier 1min spend $0.00 -> $5.00 off eachtiers[0]
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.
Ti verrà comunicato
  • 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.
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 Cable1$14.00
Subtotale$14.00
Sconto-$5.00
Totale$9.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 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.

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.

Fixed total discount cart (D10)

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

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.cart
In cosa si trasforma

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

Ogni impostazione, nel dettaglio
ImpostazioneValoreChiave di configurazione
Offer typespend_goaltype
Countingper_cartcounting
Recurrenceoncerecurrence
Tier 1min spend $0.00 -> $100.00 off eachtiers[0]
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.
Ti verrà comunicato
  • 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.
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 Cable1$14.00
Subtotale$14.00
Sconto-$14.00
Totale$0.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 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.

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 D7

Fixed total discount cart (D7)

Ricostruito

Ricostruito come offerta spend_goal.

Sconto sul suo carrello: $5.00

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

E altre 3 righe diverse, sulla sua pagina.

Leggi Amount off the order

Amount off per unit (D7)

Ricostruito

Ricostruito come offerta volume.

Sconto sul suo carrello: $5.00

Righe che cambiano
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),
Leggi Amount off each item

Coppia insidiosa D10

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

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

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

Amount off each item

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

Capped percentage discount

A percentage with a ceiling on it, so a large cart never gave away more than a set maximum.

Fixed price per item

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.

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.