Pular para o conteúdo
Exemplos 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.

Reconstruído
O que o Script fazia

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

Os lojistas escreveram isso de 2 formas diferentes, e nem todas significam a mesma coisa. Cada variação está abaixo com o próprio carrinho e os próprios números.

Teste na sua própria loja

Cole no Resgate de Scripts e veja o que ele reconstrói

  1. Copie o Ruby no botão ao lado de qualquer Script desta página.
  2. No admin da Shopify, abra o Stackable, depois Ferramentas e depois Resgate de Scripts.
  3. Cole lá, leia o que a ferramenta diz que vai criar e compare com as configurações desta página.

O Resgate de Scripts está no plano Pro. Nada é publicado até você informar quanto o Script antigo descontava e os dois valores baterem no centavo.

Customer tag gate, set intersection

Reconstruído
O Ruby original

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
No que ele vira

Reconhecido como Percentage off e reconstruído como uma oferta do tipo volume. Estas são as chaves de configuração reais com as quais a oferta é salva, então você pode conferir a sua própria reconstrução campo a campo.

Cada configuração, detalhada
ConfiguraçãoValorChave de configuração
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
Você vai precisar confirmar
  • 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.
Você será avisado
  • 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.
O carrinho que comprova

Montado na nossa loja de demonstração pública, Meridian Goods, para que cada preço aqui possa ser reproduzido em vez de aceito por confiança. O desconto abaixo é o que o mesmo motor que roda no checkout calcula para este carrinho exato.

O carrinho que aciona esta oferta, e quanto ela custa
ItemQtdPreço unit.
Braided USB-C Cable1$14.00
Subtotal$14.00
Desconto-$3.50
Total$10.50

Logado como cliente com a tag vip, wholesale.

O número com o qual a ferramenta compara você

Antes de publicar, a ferramenta pergunta o que o seu Script antigo fazia com um carrinho que você já tem. Defina como 1 de Braided USB-C Cable a $14.00 e a resposta fica fixa.

O desconto é $3.50. O total que o cliente pagou é $10.50.

A comparação é exata, até a menor unidade da sua moeda. Um centavo de diferença e a publicação continua bloqueada, que é justamente o objetivo desta etapa.

O carrinho que não pode produzir nada
  • take the same cart, but sign in as the customer with no tags
O carrinho que não pode acionar esta oferta
ItemQtdPreço unit.
Braided USB-C Cable1$14.00
Subtotal$14.00
Total$14.00

Sem login, ou logado como cliente sem tags.

Customer tag gate, broken include

Confira o texto colado
O Ruby original

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
O que acontece com este

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.

É bem provável que o seu Script esteja certo. Quem não está é a cópia que chega à ferramenta, e ela não vai adivinhar preços a partir de um arquivo danificado.

Chave do motivo: input.notAScript

Não há carrinho para testar aqui, porque nada é criado. Colar isso produz a mensagem acima e nenhuma campanha.

Perguntas frequentes

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.

Formatos de Script relacionados

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.

Cole o seu Script e veja a reconstrução

A reconstrução é comparada com o valor que o seu Script antigo cobrava antes de você poder publicá-la.

Usamos cookies essenciais para operar este site e, apenas com sua permissão, cookies de análise para entender o tráfego. Leia nossa Política de Cookies.