Migrating a remove-VAT-outside-the-EU script
The arithmetic is the trap. Taking 20% VAT out of a VAT-inclusive price is a 16.67% reduction, because the tax is a fifth of the pre-tax price and a sixth of the shelf price. The literal 20 sits right next to a divide by 100 in every one of these files.
ReconstruídoIt stripped the tax portion out of tax-inclusive prices when the shipping country was outside the listed tax area.
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 D14. 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.
VAT = 20
VAT_REMOVAL_MESSAGE = "VAT removed"
COUNTRY_CODES_EU = %w[AT BE BG CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE GB]
country_code = Input.cart.shipping_address&.country_code
unless country_code.nil? || COUNTRY_CODES_EU.include?(country_code)
vat_only_fraction = VAT / (100.0 + VAT)
Input.cart.line_items.each do |line_item|
next if line_item.variant.product.gift_card?
ex_vat_price = line_item.line_price - (line_item.line_price * vat_only_fraction)
line_item.change_line_price(ex_vat_price, message: VAT_REMOVAL_MESSAGE)
end
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 -> 16.67% off | tiers[0] |
| Target scope | all | target.scope |
| Country rule | exclude | countryTarget.mode |
| Countries | AT,BE,BG,CY,CZ,DK,EE,FI,FR,DE,GR,HU,IE,IT,LV,LT,LU,MT,NL,PL,PT,RO,SK,SI,ES,SE,GB | countryTarget.codes |
| Country read from | shipping | countryTarget.source |
| 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 worked from a tax-inclusive figure. We apply the percentage to the item price, so single-cent differences are possible.
- 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.33 | |
| Total | $11.67 | |
Sem login, ou logado como cliente sem tags. Envio para US.
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.33. O total que o cliente pagou é $11.67.
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.
- take the same cart, but ship it to DE
| Item | Qtd | Preço unit. |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotal | $14.00 | |
| Total | $14.00 | |
Sem login, ou logado como cliente sem tags. Envio para DE.
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 D14
Vat removal by country (D14)
ReconstruídoReconstruído como oferta volume.
Desconto no carrinho dele: $2.33
VAT = 20
VAT_REMOVAL_MESSAGE = "VAT removed"
COUNTRY_CODES_EU = %w[AT BE BG CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE GB]
country_code = Input.cart.shipping_address&.country_code
unless country_code.nil? || COUNTRY_CODES_EU.include?(country_code)
vat_only_fraction = VAT / (100.0 + VAT)E mais 5 linhas diferentes, na página dela.
Flat percentage off all 20 (D14)
ReconstruídoReconstruído como oferta volume.
Desconto no carrinho dele: $2.80
DISCOUNT_PERCENTAGE = 20
Input.cart.line_items.each do |line_item|
line_item.change_line_price(
line_item.line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0)),
message: "20% off"
)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.33 off, and checkout charges $11.67.
- 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 worked from a tax-inclusive figure. We apply the percentage to the item price, so single-cent differences are possible. 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
One percentage off the whole catalogue, with no condition attached.
Everything in the clearance line repriced to one round number per unit.
A flat sum taken off every unit, however many the shopper bought.
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.