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.
ReconstruitIt stripped the tax portion out of tax-inclusive prices when the shipping country was outside the listed tax area.
Collez-le dans Sauvetage des Scripts et regardez ce qu'il reconstruit
- Copiez le Ruby avec le bouton placé à côté de chaque Script de cette page.
- Dans votre interface Shopify, ouvrez Stackable, puis Outils, puis Sauvetage des Scripts.
- Collez-le, lisez ce que l'outil annonce qu'il va construire et comparez-le aux réglages de cette page.
Sauvetage des Scripts fait partie du forfait Pro. Rien n'est publié tant que vous n'avez pas indiqué la remise de votre ancien Script et que les deux chiffres ne correspondent pas au centime près.
Le Script
ReconstruitPaire à risque D14. Ce fichier et son jumeau se ressemblent presque à l'identique et se comportent différemment, alors lisez les deux avant de décider lequel vous avez.
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.cartReconnu comme Percentage off et reconstruit en offre de type volume. Voici les vraies clés de configuration avec lesquelles l'offre est enregistrée, pour que vous puissiez comparer votre propre reconstruction champ par champ.
| Réglage | Valeur | Clé de configuration |
|---|---|---|
| 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.
Construit sur notre boutique de démonstration publique, Meridian Goods, pour que chaque prix ici puisse être reproduit plutôt que cru sur parole. La remise ci-dessous est ce que le moteur qui tourne au paiement calcule pour ce panier précis.
| Article | Qté | Prix unitaire |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Sous-total | $14.00 | |
| Remise | -$2.33 | |
| Total | $11.67 | |
Déconnecté, ou connecté en tant que client sans tag. Livraison vers US.
Avant la publication, l'outil demande ce que votre ancien Script faisait à un panier que vous avez déjà. Réglez-le sur 1 de Braided USB-C Cable à $14.00 et la réponse est fixée.
La remise est de $2.33. Le total payé par l'acheteur est de $11.67.
La comparaison est exacte, jusqu'à la plus petite unité de votre devise. Un centime d'écart et la publication reste bloquée, ce qui est tout l'intérêt de l'étape.
- take the same cart, but ship it to DE
| Article | Qté | Prix unitaire |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Sous-total | $14.00 | |
| Total | $14.00 | |
Déconnecté, ou connecté en tant que client sans tag. Livraison vers DE.
Deux fichiers qui se ressemblent
Chaque paire ci-dessous est une même forme de Script écrite de deux façons. Une ou deux lignes les séparent et elles ne font pas la même chose, alors lisez les deux avant de décider laquelle vous avez.
Paire piégeuse D14
Vat removal by country (D14)
ReconstruitReconstruit en offre volume.
Remise sur son propre panier : $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)Et 5 autres lignes différentes, sur sa propre page.
Flat percentage off all 20 (D14)
ReconstruitReconstruit en offre volume.
Remise sur son propre panier : $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"
)Questions fréquentes
- 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.
Formes de Script apparentées
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.
Collez votre Script et voyez sa reconstruction
La reconstruction est comparée au montant que facturait votre ancien Script avant que vous puissiez la publier.