Migrating a customer tag discount script
Nine independent sources write this the same way, and one very common variant is simply broken: it asks whether an array of tags is an ELEMENT of another array, which is never true, so the discount never fired for anyone.
RicostruitoIt applied the discount only when the signed-in customer carried one of the listed tags.
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.
Customer tag gate, set intersection
RicostruitoCUSTOMER_TAGS = ["vip", "wholesale"]
DISCOUNT_PERCENTAGE = 25
customer = Input.cart.customer
unless customer.nil?
if !(CUSTOMER_TAGS & customer.tags.map(&:downcase)).empty?
Input.cart.line_items.each do |line_item|
next if line_item.variant.product.gift_card?
line_item.change_line_price(
line_item.line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0)),
message: "Member pricing"
)
end
end
end
Output.cart = Input.cartRiconosciuto come Percentage off e ricostruito come offerta di tipo volume. 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 | volume | type |
| Counting | per_product | counting |
| Recurrence | once | recurrence |
| Tier 1 | min qty 1 -> 25% off | tiers[0] |
| Target scope | all | target.scope |
| Customer scope | tags | customerTarget.scope |
| Customer tags | vip, wholesale | customerTarget.ids |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- This script only applied to tagged customers. Set customer eligibility in the builder before publishing.
- Your Script skipped gift cards. We cannot detect gift cards yet, so exclude them by hand in targeting before publishing.
- Confirm which products this applies to. We could not read product targeting from the script.
- Shopify matches customer tags exactly, including capital letters, while your Script lowercased them. Check the spelling of the tag before you publish.
- Your Script skipped gift cards and we cannot detect them, so gift cards are discounted unless you exclude them in targeting.
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 | -$3.50 | |
| Totale | $10.50 | |
Accesso effettuato come cliente con tag vip, wholesale.
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 è $3.50. Il totale pagato dal cliente è $10.50.
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.
- take the same cart, but sign in as the customer with no tags
| Articolo | Qtà | Prezzo unit. |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotale | $14.00 | |
| Totale | $14.00 | |
Nessun accesso, oppure accesso come cliente senza tag.
Customer tag gate, broken include
Controlla il testoTAGS_NEEDED = ["vip", "wholesale"]
Input.cart.line_items.each do |line_item|
next unless TAGS_NEEDED.include?(line_item.variant.product.tags)
line_item.change_line_price(line_item.line_price * 0.8, message: "20% off")
end
Output.cart = Input.cartWe could not read this copy of your Script
This does not look like a Shopify Script. Paste the Ruby from the Script Editor, starting with the settings at the top of the file.
Il tuo Script probabilmente va benissimo. Quello che non va è la copia che arriva allo strumento, e da un file danneggiato non tirerà a indovinare i prezzi.
Chiave del motivo: input.notAScript
Qui non c'è nessun carrello da testare, perché non viene creato nulla. Incollando questo compare il messaggio qui sopra e nessuna campagna.
Domande frequenti
- Will Stackable rebuild this script?
- It depends on how yours is written. 1 of the 2 spellings on this page are rebuilt today; the rest are refused with a reason. Compare your file against the Ruby above.
- What cart proves it works?
- 1 x Braided USB-C Cable at $14.00. The engine takes $3.50 off, and checkout charges $10.50.
- What will I have to check before publishing?
- This script only applied to tagged customers. Set customer eligibility in the builder before publishing. Your Script skipped gift cards. We cannot detect gift cards yet, so exclude them by hand in targeting before publishing. Confirm which products this applies to. We could not read product targeting from the script. Shopify matches customer tags exactly, including capital letters, while your Script lowercased them. Check the spelling of the tag before you publish. Your Script skipped gift cards and we cannot detect them, so gift cards are discounted unless you exclude them in targeting.
- What happens to the part you cannot rebuild?
- We could not read this copy of your Script. This does not look like a Shopify Script. Paste the Ruby from the Script Editor, starting with the settings at the top of the file.
Forme di Script correlate
A discount for shoppers with no order history, or with enough of it.
A new-customer gate wrapped around a cheapest-item reward.
A reward for customers who had spent enough over their lifetime.
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.