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.
OmbyggtIt stripped the tax portion out of tax-inclusive prices when the shipping country was outside the listed tax area.
Klistra in det i Scripts-räddning och se vad som byggs
- Kopiera Ruby-koden med knappen bredvid vilket Script som helst på sidan.
- Öppna Stackable i Shopify-adminen, sedan Verktyg, sedan Scripts-räddning.
- Klistra in det där, läs vad verktyget säger att det ska bygga och jämför med inställningarna på den här sidan.
Scripts-räddning ingår i Pro-planen. Ingenting publiceras förrän du anger vad ditt gamla Script gav i rabatt och båda beloppen stämmer på öret.
Detta Script
OmbyggtRiskabelt par D14. Den här filen och dess motpart ser nästan likadana ut och beter sig olika, så läs båda innan du avgör vilken du har.
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.cartIdentifierat som Percentage off och ombyggt till ett erbjudande av typen volume. Det här är de verkliga konfigurationsnycklarna som erbjudandet sparas med, så du kan stämma av din egen ombyggnad fält för fält.
| Inställning | Värde | Konfigurationsnyckel |
|---|---|---|
| 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.
Byggd i vår publika demobutik, Meridian Goods, så att varje pris här går att räkna efter i stället för att tas på förtroende. Rabatten nedan är vad samma motor som kör i kassan räknar fram för exakt den här varukorgen.
| Artikel | Antal | Styckpris |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Delsumma | $14.00 | |
| Rabatt | -$2.33 | |
| Summa | $11.67 | |
Utloggad, eller inloggad som kund utan taggar. Frakt till US.
Före publicering frågar verktyget vad ditt gamla Script gjorde med en varukorg du redan har. Sätt den till 1 av Braided USB-C Cable à $14.00, så är svaret givet.
Rabatten är $2.33. Summan som kunden betalade är $11.67.
Jämförelsen är exakt, ned till minsta enhet i din valuta. Ett öre fel och publiceringen förblir stängd, vilket är hela poängen med steget.
- take the same cart, but ship it to DE
| Artikel | Antal | Styckpris |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Delsumma | $14.00 | |
| Summa | $14.00 | |
Utloggad, eller inloggad som kund utan taggar. Frakt till DE.
Två filer som ser likadana ut
Varje par nedan är samma Script-form skriven på två sätt. De skiljer sig åt på en eller två rader och gör olika saker, så läs båda innan du avgör vilken du har.
Farligt par D14
Vat removal by country (D14)
OmbyggtByggs om till ett volume-erbjudande.
Rabatt i sin egen varukorg: $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)Och 5 rader till som skiljer sig, på den egna sidan.
Flat percentage off all 20 (D14)
OmbyggtByggs om till ett volume-erbjudande.
Rabatt i sin egen varukorg: $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"
)Vanliga frågor
- 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.
Besläktade Script-former
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.
Klistra in ditt Script och se det byggas om
Ombyggnaden stäms av mot beloppet som ditt gamla Script tog ut innan du kan publicera den.