Migrating an exclude gift cards script
This line rarely arrives on its own. It sits inside somebody else’s script as one guard among several, which is exactly why it gets dropped, and why discounting a gift card is a merchant support ticket rather than a rounding error.
ReconstruídoIt skipped any line whose product was a gift card.
Cole no Resgate de Scripts e veja o que ele reconstrói
- Copie o Ruby no botão ao lado de qualquer Script desta página.
- No admin da Shopify, abra o Stackable, depois Ferramentas e depois Resgate de Scripts.
- 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.
O Script
ReconstruídoDISCOUNT_PERCENTAGE = 15
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: "15% off"
)
end
Output.cart = Input.cartReconhecido 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.
| Configuração | Valor | Chave de configuração |
|---|---|---|
| Offer type | volume | type |
| Counting | per_product | counting |
| Recurrence | once | recurrence |
| Tier 1 | min qty 1 -> 15% off | tiers[0] |
| Target scope | all | target.scope |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- 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.
- Your Script skipped gift cards and we cannot detect them, so gift cards are discounted unless you exclude them in targeting.
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.
| Item | Qtd | Preço unit. |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotal | $14.00 | |
| Desconto | -$2.10 | |
| Total | $11.90 | |
Sem login, ou logado como cliente sem tags.
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 é $2.10. O total que o cliente pagou é $11.90.
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.
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.
Perguntas frequentes
- Will Stackable rebuild this script?
- Yes. Every spelling on this page is rebuilt today as a volume 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 $2.10 off, and checkout charges $11.90.
- What will I have to check 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. Your Script skipped gift cards and we cannot detect them, so gift cards are discounted unless you exclude them in targeting.
Formatos de Script relacionados
A discount limited to products carrying one tag, vendor or type.
Already-marked-down products protected from a second discount.
A discount keyed on a property attached to one cart line.
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.