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.
NachgebautIt stripped the tax portion out of tax-inclusive prices when the shipping country was outside the listed tax area.
Fügen Sie es in die Scripts-Rettung ein und sehen Sie, was daraus wird
- Kopieren Sie das Ruby mit der Schaltfläche neben jedem Script auf dieser Seite.
- Öffnen Sie im Shopify-Adminbereich Stackable, dann Tools, dann Scripts-Rettung.
- Fügen Sie es dort ein, lesen Sie, was das Tool bauen will, und vergleichen Sie das mit den Einstellungen auf dieser Seite.
Die Scripts-Rettung gehört zum Pro-Tarif. Nichts wird veröffentlicht, bevor Sie angeben, was Ihr altes Script berechnet hat, und beide Zahlen auf den Cent genau übereinstimmen.
Das Script
NachgebautGefährliches Paar D14. Diese Datei und ihr Gegenstück sehen fast gleich aus und verhalten sich unterschiedlich, lesen Sie also beide, bevor Sie entscheiden, welche Sie haben.
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.cartErkannt als Percentage off und neu aufgebaut als Angebot vom Typ volume. Das sind die echten Konfigurationsschlüssel, mit denen das Angebot gespeichert wird, sodass Sie Ihren eigenen Nachbau Feld für Feld damit abgleichen können.
| Einstellung | Wert | Konfigurationsschlüssel |
|---|---|---|
| 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.
Aufgebaut in unserem öffentlichen Demo-Shop Meridian Goods, damit sich jeder Preis hier nachrechnen lässt und nicht geglaubt werden muss. Der Rabatt unten ist das, was dieselbe Engine, die im Checkout läuft, für genau diesen Warenkorb berechnet.
| Artikel | Menge | Einzelpreis |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Zwischensumme | $14.00 | |
| Rabatt | -$2.33 | |
| Summe | $11.67 | |
Nicht angemeldet oder als Kunde ohne Tags angemeldet. Versand nach US.
Vor dem Veröffentlichen fragt das Tool, was Ihr altes Script mit einem Warenkorb gemacht hat, den Sie bereits haben. Stellen Sie ihn auf 1 von Braided USB-C Cable zu $14.00 ein, dann steht die Antwort fest.
Der Rabatt beträgt $2.33. Der Betrag, den der Käufer gezahlt hat, ist $11.67.
Der Vergleich ist exakt, bis auf die kleinste Einheit Ihrer Währung. Ein Cent daneben und das Veröffentlichen bleibt gesperrt, genau darum geht es bei diesem Schritt.
- take the same cart, but ship it to DE
| Artikel | Menge | Einzelpreis |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Zwischensumme | $14.00 | |
| Summe | $14.00 | |
Nicht angemeldet oder als Kunde ohne Tags angemeldet. Versand nach DE.
Zwei Dateien, die gleich aussehen
Jedes Paar unten ist dieselbe Script-Form in zwei Schreibweisen. Sie unterscheiden sich in ein, zwei Zeilen und tun Unterschiedliches. Lesen Sie beide, bevor Sie entscheiden, welche Sie haben.
Gefährliches Paar D14
Vat removal by country (D14)
NachgebautWird als volume-Angebot nachgebaut.
Rabatt im eigenen Warenkorb: $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)Und 5 weitere abweichende Zeilen, auf der eigenen Seite.
Flat percentage off all 20 (D14)
NachgebautWird als volume-Angebot nachgebaut.
Rabatt im eigenen Warenkorb: $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"
)Häufige Fragen
- 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.
Verwandte Script-Formen
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.
Fügen Sie Ihr Script ein und sehen Sie den Nachbau
Der Nachbau wird mit dem Betrag abgeglichen, den Ihr altes Script berechnet hat, bevor Sie ihn veröffentlichen können.