Migrating a spend threshold amount off script
Two Money.new calls sit in this file and nothing about their syntax says which is the threshold and which is the reward. Whichever a naive reader takes first wins, and the two answers are $100 off and $15 off.
ReconstruídoIt took a fixed sum off the order once the cart subtotal reached a threshold.
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ídoPar perigoso D2. Este arquivo e o parceiro dele são quase idênticos e se comportam de formas diferentes, então leia os dois antes de decidir qual é o seu.
THRESHOLD = Money.new(cents: 10000)
REWARD = Money.new(cents: 1500)
if Input.cart.subtotal_price >= THRESHOLD
remaining = REWARD
Input.cart.line_items.each do |line_item|
break if remaining <= Money.zero
share = [line_item.line_price, remaining].min
line_item.change_line_price(line_item.line_price - share, message: "Spend $100, get $15 off")
remaining = remaining - share
end
end
Output.cart = Input.cartReconhecido como Amount off the order e reconstruído como uma oferta do tipo spend_goal. 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 | spend_goal | type |
| Counting | per_cart | counting |
| Recurrence | once | recurrence |
| Tier 1 | min spend $100.00 -> $15.00 off each | tiers[0] |
| Target scope | all | target.scope |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Confirm which products this applies to. We could not read product targeting from the script.
- A fixed amount off the order is spread across the items at checkout, so each line shows part of it rather than one line carrying the whole discount.
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. |
|---|---|---|
| Felt Laptop Sleeve | 2 | $38.00 |
| Impact Phone Case | 1 | $24.00 |
| Subtotal | $100.00 | |
| Desconto | -$15.00 | |
| Total | $85.00 | |
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 4 de Walnut Desk Organizer a $26.00 e a resposta fica fixa.
O desconto é $15.00. O total que o cliente pagou é $89.00.
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.
- drop to 1 of the same product, under what the rule needs
| Item | Qtd | Preço unit. |
|---|---|---|
| Felt Laptop Sleeve | 1 | $38.00 |
| Subtotal | $38.00 | |
| Total | $38.00 | |
Sem login, ou logado como cliente sem tags.
Dois arquivos que parecem iguais
Cada dupla abaixo é a mesma forma de Script escrita de dois jeitos. Elas mudam em uma ou duas linhas e fazem coisas diferentes, então leia as duas antes de decidir qual é a sua.
Dupla perigosa D2
Spend threshold fixed amount (D2)
ReconstruídoReconstruído como oferta spend_goal.
Desconto no carrinho dele: $15.00
REWARD = Money.new(cents: 1500)
remaining = REWARD
break if remaining <= Money.zero
share = [line_item.line_price, remaining].min
line_item.change_line_price(line_item.line_price - share, message: "Spend $100, get $15 off")
remaining = remaining - shareSpend threshold percentage (D2)
ReconstruídoReconstruído como oferta spend_goal.
Desconto no carrinho dele: $15.00
line_item.change_line_price(line_item.line_price * (1.0 - (15 / 100.0)), message: "Spend $100, save 15%")Perguntas frequentes
- Will Stackable rebuild this script?
- Yes. Every spelling on this page is rebuilt today as a spend_goal offer, and the cart above is the one that proves it.
- What cart proves it works?
- 2 x Felt Laptop Sleeve at $38.00 plus 1 x Impact Phone Case at $24.00. The engine takes $15.00 off, and checkout charges $85.00.
- What will I have to check before publishing?
- Confirm which products this applies to. We could not read product targeting from the script. A fixed amount off the order is spread across the items at checkout, so each line shows part of it rather than one line carrying the whole discount.
Formatos de Script relacionados
A percentage that unlocks once the cart is worth enough.
A threshold read from what was left after a code had already come off.
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.