Migrating a capped percentage discount script
Common on high-value carts and the one place where getting it wrong is wrong in both directions at once: read the cap as the discount and you give $50 flat, drop the cap and you give an uncapped quarter of the cart.
再構築可It worked out a percentage of the cart and then refused to take off more than a stated maximum.
スクリプトレスキューに貼り付けて、何が再現されるか確認する
- このページの各スクリプトの横にあるボタンで Ruby をコピーします。
- Shopify 管理画面で Stackable を開き、ツール、スクリプトレスキューの順に進みます。
- そこに貼り付け、ツールが作成すると示した内容を読み、このページの設定と見比べます。
スクリプトレスキューは Pro プランの機能です。以前のスクリプトの割引額を入力し、両方の金額が最小通貨単位まで一致するまで、何も公開されません。
Script 本体
再構築可危険なペア D10。このファイルと対になるファイルは見た目がほぼ同じで、動作が異なります。どちらを使っているか判断する前に両方を読んでください。
DISCOUNT_PERCENTAGE = 25
MAX_DISCOUNT = 50
cart_subtotal_float = Float((Input.cart.subtotal_price.cents / 100).to_s)
raw_discount = cart_subtotal_float * (DISCOUNT_PERCENTAGE / 100.0)
total_discount = [raw_discount, MAX_DISCOUNT].min
Input.cart.line_items.each do |line_item|
line_price_float = Float((line_item.line_price.cents / 100).to_s)
percentage = 1 - (((line_price_float / cart_subtotal_float) * total_discount) / line_price_float)
line_item.change_line_price(line_item.line_price * percentage, message: "25% off, up to $50")
end
Output.cart = Input.cartSpend threshold discount として認識され、spend_goal タイプのオファーとして再構築されます。以下はオファーが実際に保存される設定キーそのものなので、ご自身の再構築結果を項目ごとに照合できます。
| 設定項目 | 値 | 設定キー |
|---|---|---|
| Offer type | spend_goal | type |
| Counting | per_cart | counting |
| Recurrence | once | recurrence |
| Tier 1 | min spend $0.00 -> 25% off | tiers[0] |
| Target scope | all | target.scope |
| Maximum discount | $50.00 | maxDiscountAmount |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Confirm which products this applies to. We could not read product targeting from the script.
- The maximum applies to the whole order and is shared across the discounted items. If your Script capped each line on its own, that gave more away than this does.
公開デモストア Meridian Goods で作成しているため、ここに載せた価格はすべて、信じるのではなく再現して確かめられます。以下の割引額は、決済時に動くのと同じエンジンがこのカートに対して算出した金額です。
| 商品 | 数量 | 単価 |
|---|---|---|
| Canvas Belt Bag | 1 | $42.00 |
| Aria Wireless Earbuds | 2 | $79.00 |
| 小計 | $200.00 | |
| 割引 | -$50.00 | |
| 合計 | $150.00 | |
未ログイン、またはタグのない顧客としてログインしています。
公開前に、ツールは手元のカートに対して以前の Script が何をしていたかを尋ねます。カートを Walnut Desk Organizer 8、単価 $26.00 に設定すれば、答えは一つに定まります。
割引額は $50.00 です。購入者が支払った合計は $158.00 です。
照合は通貨の最小単位まで完全一致で行われます。1 単位でもずれれば公開はできません。それがこの手順の目的です。
This rule carries no condition at all, so it fires on any cart holding anything and there is no quiet cart to build. The negative check is an empty cart, which the app runs for you. That is correct behaviour, not a failure.
見た目がそっくりな 2 つのファイル
以下の各ペアは、同じ形のスクリプトを 2 通りに書いたものです。違いは 1 行か 2 行ですが、動作は異なります。どちらが手元のものか決める前に、両方を読んでください。
紛らわしいペア D10
Capped percentage discount (D10)
再構築可spend_goal オファーとして再現されます。
このカートでの割引: $50.00
DISCOUNT_PERCENTAGE = 25
MAX_DISCOUNT = 50
cart_subtotal_float = Float((Input.cart.subtotal_price.cents / 100).to_s)
raw_discount = cart_subtotal_float * (DISCOUNT_PERCENTAGE / 100.0)
total_discount = [raw_discount, MAX_DISCOUNT].min
line_price_float = Float((line_item.line_price.cents / 100).to_s)さらに 2 行の違いが、それぞれのページにあります。
Fixed total discount cart (D10)
再構築可spend_goal オファーとして再現されます。
このカートでの割引: $14.00
MAX_DISCOUNT = Money.new(cents: 10000)
remaining = MAX_DISCOUNT
break if remaining <= Money.zero
share = [line_item.line_price, remaining].min
line_item.change_line_price(line_item.line_price - share, message: "$100 off your order")
remaining = remaining - shareよくある質問
- Will Stackable rebuild this script?
- Yes. Every spelling on this page is rebuilt today as a spend_goal offer, and the cart above is the one that proves it.
- What cart proves it works?
- 1 x Canvas Belt Bag at $42.00 plus 2 x Aria Wireless Earbuds at $79.00. The engine takes $50.00 off, and checkout charges $150.00.
- What will I have to check before publishing?
- Confirm which products this applies to. We could not read product targeting from the script. The maximum applies to the whole order and is shared across the discounted items. If your Script capped each line on its own, that gave more away than this does.
関連する Script の型
One lump sum off the whole cart, spread across the lines.
Everything in the clearance line repriced to one round number per unit.
A flat sum taken off every unit, however many the shopper bought.