Pular para o conteúdo
Exemplos de Scripts

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ído
O que o Script fazia

It stripped the tax portion out of tax-inclusive prices when the shipping country was outside the listed tax area.

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.

O Script

Reconstruído

Par 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.

O Ruby original

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.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 -> 16.67% offtiers[0]
Target scopealltarget.scope
Country ruleexcludecountryTarget.mode
CountriesAT,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,GBcountryTarget.codes
Country read fromshippingcountryTarget.source
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
Você vai precisar confirmar
  • 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
  • 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.
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-$2.33
Total$11.67

Sem login, ou logado como cliente sem tags. Envio para US.

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 é $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.

O carrinho que não pode produzir nada
  • take the same cart, but ship it to DE
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. 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ído

Reconstruído como oferta volume.

Desconto no carrinho dele: $2.33

Linhas que mudam
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.

Ler Remove VAT outside the EU

Flat percentage off all 20 (D14)

Reconstruído

Reconstruído como oferta volume.

Desconto no carrinho dele: $2.80

Linhas que mudam
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"
  )
Ler Sitewide percentage 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

Sitewide percentage off

One percentage off the whole catalogue, with no condition attached.

Fixed price per item

Everything in the clearance line repriced to one round number per unit.

Amount off each item

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.

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.