Migrating a flat rate shipping script
Setting a rate TO a price and taking an amount OFF a rate need different information: the second needs only the discount, the first needs the rate’s own cost. That difference is the whole entry.
未対応It rewrote every delivery rate to one flat price.
スクリプトレスキューに貼り付けて、何が再現されるか確認する
- このページの各スクリプトの横にあるボタンで Ruby をコピーします。
- Shopify 管理画面で Stackable を開き、ツール、スクリプトレスキューの順に進みます。
- そこに貼り付け、ツールが作成すると示した内容を読み、このページの設定と見比べます。
スクリプトレスキューは Pro プランの機能です。以前のスクリプトの割引額を入力し、両方の金額が最小通貨単位まで一致するまで、何も公開されません。
Script 本体
未対応危険なペア D4。このファイルと対になるファイルは見た目がほぼ同じで、動作が異なります。どちらを使っているか判断する前に両方を読んでください。
# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP
class FixedPriceDiscount
def initialize(amount, message)
@amount = Money.new(cents: 100) * amount
@message = message
end
def apply(rate)
rate_discount = @amount > rate.price ? rate.price : rate.price - @amount
rate.apply_discount(rate_discount, { message: @message })
end
end
CAMPAIGNS = [
ShippingDiscount.new(:all, nil, nil, FixedPriceDiscount.new(5, "Flat rate shipping $5")),
].freeze
CAMPAIGNS.each do |campaign|
campaign.run(Input.shipping_rates, Input.cart)
end
Output.shipping_rates = Input.shipping_ratesWe have not built this yet
Your Script set shipping to a fixed price. We can take an amount or a percentage off shipping, but setting a rate to a price needs the rate's own cost, which we do not read yet.
これは Shopify ではなく当社の不足です。Shopify では許可されていますが当社が未実装なので、リンクできる先はなく、プラットフォームのせいにできる点もありません。
理由キー: unsupported.shippingFixedPrice
何も作成されないため、ここに検証できるカートはありません。これを貼り付けても上のメッセージが出るだけで、キャンペーンは作成されません。
見た目がそっくりな 2 つのファイル
以下の各ペアは、同じ形のスクリプトを 2 通りに書いたものです。違いは 1 行か 2 行ですが、動作は異なります。どちらが手元のものか決める前に、両方を読んでください。
紛らわしいペア D4
Shipping fixed price (D4)
未対応再現しません。We have not built this yet
class FixedPriceDiscount
rate_discount = @amount > rate.price ? rate.price : rate.price - @amount
ShippingDiscount.new(:all, nil, nil, FixedPriceDiscount.new(5, "Flat rate shipping $5")),Shipping fixed amount off (D4)
再構築可free_shipping オファーとして再現されます。
このカートでの配送料の節約: $5.00
class FixedDiscount
rate_discount = rate.price - @amount < Money.zero ? rate.price : @amount
ShippingDiscount.new(:all, nil, nil, FixedDiscount.new(5, "$5 off shipping")),よくある質問
- Will Stackable rebuild this script?
- No, and the reason is stated rather than hidden: Your Script set shipping to a fixed price. We can take an amount or a percentage off shipping, but setting a rate to a price needs the rate's own cost, which we do not read yet.
関連する Script の型
A flat sum off the delivery charge, floored at free.
A share taken off every delivery rate at checkout.
Delivery drops to free once the cart is worth enough.