Aller au contenu
Exemples de Scripts

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.

Reconstruit
Ce que faisait le Script

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

Les marchands ont écrit ceci de 2 façons différentes, et elles ne veulent pas toutes dire la même chose. Chaque variante figure ci-dessous avec son propre panier et ses propres chiffres.

Essayez-le sur votre propre boutique

Collez-le dans Sauvetage des Scripts et regardez ce qu'il reconstruit

  1. Copiez le Ruby avec le bouton placé à côté de chaque Script de cette page.
  2. Dans votre interface Shopify, ouvrez Stackable, puis Outils, puis Sauvetage des Scripts.
  3. Collez-le, lisez ce que l'outil annonce qu'il va construire et comparez-le aux réglages de cette page.

Sauvetage des Scripts fait partie du forfait Pro. Rien n'est publié tant que vous n'avez pas indiqué la remise de votre ancien Script et que les deux chiffres ne correspondent pas au centime près.

Customer tag gate, set intersection

Reconstruit
Le Ruby d'origine

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
Ce que cela devient

Reconnu comme Percentage off et reconstruit en offre de type volume. Voici les vraies clés de configuration avec lesquelles l'offre est enregistrée, pour que vous puissiez comparer votre propre reconstruction champ par champ.

Chaque réglage, en détail
RéglageValeurClé de configuration
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
Il vous sera demandé de confirmer
  • 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.
Vous serez informé
  • 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.
Le panier qui le prouve

Construit sur notre boutique de démonstration publique, Meridian Goods, pour que chaque prix ici puisse être reproduit plutôt que cru sur parole. La remise ci-dessous est ce que le moteur qui tourne au paiement calcule pour ce panier précis.

Le panier qui déclenche cette offre, et ce qu'elle coûte
ArticleQtéPrix unitaire
Braided USB-C Cable1$14.00
Sous-total$14.00
Remise-$3.50
Total$10.50

Connecté en tant que client portant le tag vip, wholesale.

Le chiffre auquel l'outil vous compare

Avant la publication, l'outil demande ce que votre ancien Script faisait à un panier que vous avez déjà. Réglez-le sur 1 de Braided USB-C Cable à $14.00 et la réponse est fixée.

La remise est de $3.50. Le total payé par l'acheteur est de $10.50.

La comparaison est exacte, jusqu'à la plus petite unité de votre devise. Un centime d'écart et la publication reste bloquée, ce qui est tout l'intérêt de l'étape.

Le panier qui ne doit rien produire
  • take the same cart, but sign in as the customer with no tags
Le panier qui ne doit pas déclencher cette offre
ArticleQtéPrix unitaire
Braided USB-C Cable1$14.00
Sous-total$14.00
Total$14.00

Déconnecté, ou connecté en tant que client sans tag.

Customer tag gate, broken include

Vérifiez le collage
Le Ruby d'origine

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
Ce qu'il advient de celui-ci

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.

Votre Script est probablement très bien. La copie qui parvient à l'outil ne l'est pas, et il ne devinera pas les prix à partir d'un fichier abîmé.

Clé du motif : input.notAScript

Il n'y a pas de panier à tester ici, puisque rien n'est construit. Coller ceci produit le message ci-dessus et aucune campagne.

Questions fréquentes

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.

Formes de Script apparentées

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.

Collez votre Script et voyez sa reconstruction

La reconstruction est comparée au montant que facturait votre ancien Script avant que vous puissiez la publier.

Nous utilisons des cookies essentiels pour faire fonctionner ce site et, uniquement avec votre autorisation, des cookies d'analyse pour comprendre le trafic. Consultez notre Politique de cookies.