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.
再構築可It stripped the tax portion out of tax-inclusive prices when the shipping country was outside the listed tax area.
スクリプトレスキューに貼り付けて、何が再現されるか確認する
- このページの各スクリプトの横にあるボタンで Ruby をコピーします。
- Shopify 管理画面で Stackable を開き、ツール、スクリプトレスキューの順に進みます。
- そこに貼り付け、ツールが作成すると示した内容を読み、このページの設定と見比べます。
スクリプトレスキューは Pro プランの機能です。以前のスクリプトの割引額を入力し、両方の金額が最小通貨単位まで一致するまで、何も公開されません。
Script 本体
再構築可危険なペア D14。このファイルと対になるファイルは見た目がほぼ同じで、動作が異なります。どちらを使っているか判断する前に両方を読んでください。
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.cartPercentage off として認識され、volume タイプのオファーとして再構築されます。以下はオファーが実際に保存される設定キーそのものなので、ご自身の再構築結果を項目ごとに照合できます。
| 設定項目 | 値 | 設定キー |
|---|---|---|
| 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.
公開デモストア Meridian Goods で作成しているため、ここに載せた価格はすべて、信じるのではなく再現して確かめられます。以下の割引額は、決済時に動くのと同じエンジンがこのカートに対して算出した金額です。
| 商品 | 数量 | 単価 |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| 小計 | $14.00 | |
| 割引 | -$2.33 | |
| 合計 | $11.67 | |
未ログイン、またはタグのない顧客としてログインしています。 配送先は US です。
公開前に、ツールは手元のカートに対して以前の Script が何をしていたかを尋ねます。カートを Braided USB-C Cable 1、単価 $14.00 に設定すれば、答えは一つに定まります。
割引額は $2.33 です。購入者が支払った合計は $11.67 です。
照合は通貨の最小単位まで完全一致で行われます。1 単位でもずれれば公開はできません。それがこの手順の目的です。
- take the same cart, but ship it to DE
| 商品 | 数量 | 単価 |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| 小計 | $14.00 | |
| 合計 | $14.00 | |
未ログイン、またはタグのない顧客としてログインしています。 配送先は DE です。
見た目がそっくりな 2 つのファイル
以下の各ペアは、同じ形のスクリプトを 2 通りに書いたものです。違いは 1 行か 2 行ですが、動作は異なります。どちらが手元のものか決める前に、両方を読んでください。
紛らわしいペア D14
Vat removal by country (D14)
再構築可volume オファーとして再現されます。
このカートでの割引: $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)さらに 5 行の違いが、それぞれのページにあります。
Flat percentage off all 20 (D14)
再構築可volume オファーとして再現されます。
このカートでの割引: $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"
)よくある質問
- 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.
関連する Script の型
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.