Zum Inhalt springen
Script-Beispiele

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.

Nachgebaut
Was das Script gemacht hat

It applied the discount only when the signed-in customer carried one of the listed tags.

Händler haben das auf 2 verschiedene Arten geschrieben, und sie bedeuten nicht alle dasselbe. Jede Schreibweise steht unten mit eigenem Warenkorb und eigenen Zahlen.

Im eigenen Shop ausprobieren

Fügen Sie es in die Scripts-Rettung ein und sehen Sie, was daraus wird

  1. Kopieren Sie das Ruby mit der Schaltfläche neben jedem Script auf dieser Seite.
  2. Öffnen Sie im Shopify-Adminbereich Stackable, dann Tools, dann Scripts-Rettung.
  3. Fügen Sie es dort ein, lesen Sie, was das Tool bauen will, und vergleichen Sie das mit den Einstellungen auf dieser Seite.

Die Scripts-Rettung gehört zum Pro-Tarif. Nichts wird veröffentlicht, bevor Sie angeben, was Ihr altes Script berechnet hat, und beide Zahlen auf den Cent genau übereinstimmen.

Customer tag gate, set intersection

Nachgebaut
Das ursprüngliche Ruby

CUSTOMER_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.cart
Was daraus wird

Erkannt als Percentage off und neu aufgebaut als Angebot vom Typ volume. Das sind die echten Konfigurationsschlüssel, mit denen das Angebot gespeichert wird, sodass Sie Ihren eigenen Nachbau Feld für Feld damit abgleichen können.

Jede Einstellung im Detail
EinstellungWertKonfigurationsschlüssel
Offer typevolumetype
Countingper_productcounting
Recurrenceoncerecurrence
Tier 1min qty 1 -> 25% offtiers[0]
Target scopealltarget.scope
Customer scopetagscustomerTarget.scope
Customer tagsvip, wholesalecustomerTarget.ids
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
Sie werden um Bestätigung gebeten
  • 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.
Sie werden darauf hingewiesen
  • 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.
Der Warenkorb, der es belegt

Aufgebaut in unserem öffentlichen Demo-Shop Meridian Goods, damit sich jeder Preis hier nachrechnen lässt und nicht geglaubt werden muss. Der Rabatt unten ist das, was dieselbe Engine, die im Checkout läuft, für genau diesen Warenkorb berechnet.

Der Warenkorb, der dieses Angebot auslöst, und was es kostet
ArtikelMengeEinzelpreis
Braided USB-C Cable1$14.00
Zwischensumme$14.00
Rabatt-$3.50
Summe$10.50

Angemeldet als Kunde mit dem Tag vip, wholesale.

Die Zahl, an der das Tool Sie misst

Vor dem Veröffentlichen fragt das Tool, was Ihr altes Script mit einem Warenkorb gemacht hat, den Sie bereits haben. Stellen Sie ihn auf 1 von Braided USB-C Cable zu $14.00 ein, dann steht die Antwort fest.

Der Rabatt beträgt $3.50. Der Betrag, den der Käufer gezahlt hat, ist $10.50.

Der Vergleich ist exakt, bis auf die kleinste Einheit Ihrer Währung. Ein Cent daneben und das Veröffentlichen bleibt gesperrt, genau darum geht es bei diesem Schritt.

Der Warenkorb, der nichts auslösen darf
  • take the same cart, but sign in as the customer with no tags
Der Warenkorb, der dieses Angebot nicht auslösen darf
ArtikelMengeEinzelpreis
Braided USB-C Cable1$14.00
Zwischensumme$14.00
Summe$14.00

Nicht angemeldet oder als Kunde ohne Tags angemeldet.

Customer tag gate, broken include

Einfügen prüfen
Das ursprüngliche Ruby

TAGS_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.cart
Was mit diesem hier passiert

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.

Ihr Script ist wahrscheinlich in Ordnung. Die Kopie, die beim Tool ankommt, ist es nicht, und es wird aus einer beschädigten Datei keine Preise erraten.

Grundschlüssel: input.notAScript

Hier gibt es keinen Warenkorb zum Testen, weil nichts gebaut wird. Das Einfügen erzeugt die obige Meldung und überhaupt keine Kampagne.

Häufige Fragen

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.

Verwandte Script-Formen

First order discount

A discount for shoppers with no order history, or with enough of it.

First time customer, cheapest item

A new-customer gate wrapped around a cheapest-item reward.

Lifetime spend discount

A reward for customers who had spent enough over their lifetime.

Fügen Sie Ihr Script ein und sehen Sie den Nachbau

Der Nachbau wird mit dem Betrag abgeglichen, den Ihr altes Script berechnet hat, bevor Sie ihn veröffentlichen können.

Wir verwenden essenzielle Cookies für den Betrieb dieser Website und, nur mit Ihrer Erlaubnis, Analyse-Cookies, um den Traffic zu verstehen. Lesen Sie unsere Cookie-Richtlinie.