コンテンツにスキップ
Script 実例集

Migrating a spend threshold percentage script

The cleanest script in the whole library, and the one worth doing first on camera: one threshold, one percentage, one money literal, nothing ambiguous anywhere in the file.

再構築可
この Script がしていたこと

It compared the cart subtotal to a threshold and took a percentage off once it was reached.

自分のストアで試す

スクリプトレスキューに貼り付けて、何が再現されるか確認する

  1. このページの各スクリプトの横にあるボタンで Ruby をコピーします。
  2. Shopify 管理画面で Stackable を開き、ツール、スクリプトレスキューの順に進みます。
  3. そこに貼り付け、ツールが作成すると示した内容を読み、このページの設定と見比べます。

スクリプトレスキューは Pro プランの機能です。以前のスクリプトの割引額を入力し、両方の金額が最小通貨単位まで一致するまで、何も公開されません。

Script 本体

再構築可

危険なペア D2。このファイルと対になるファイルは見た目がほぼ同じで、動作が異なります。どちらを使っているか判断する前に両方を読んでください。

元の Ruby

THRESHOLD = Money.new(cents: 10000)

if Input.cart.subtotal_price >= THRESHOLD
  Input.cart.line_items.each do |line_item|
    line_item.change_line_price(line_item.line_price * (1.0 - (15 / 100.0)), message: "Spend $100, save 15%")
  end
end

Output.cart = Input.cart
何になるか

Spend threshold discount として認識され、spend_goal タイプのオファーとして再構築されます。以下はオファーが実際に保存される設定キーそのものなので、ご自身の再構築結果を項目ごとに照合できます。

すべての設定項目
設定項目設定キー
Offer typespend_goaltype
Countingper_cartcounting
Recurrenceoncerecurrence
Tier 1min spend $100.00 -> 15% offtiers[0]
Target scopealltarget.scope
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
確認を求められます
  • Confirm which products this applies to. We could not read product targeting from the script.
それを裏づけるカート

公開デモストア Meridian Goods で作成しているため、ここに載せた価格はすべて、信じるのではなく再現して確かめられます。以下の割引額は、決済時に動くのと同じエンジンがこのカートに対して算出した金額です。

このオファーが発動するカートと、その金額
商品数量単価
Felt Laptop Sleeve2$38.00
Impact Phone Case1$24.00
小計$100.00
割引-$15.00
合計$85.00

未ログイン、またはタグのない顧客としてログインしています。

ツールが照合する金額

公開前に、ツールは手元のカートに対して以前の Script が何をしていたかを尋ねます。カートを Walnut Desk Organizer 4、単価 $26.00 に設定すれば、答えは一つに定まります。

割引額は $15.60 です。購入者が支払った合計は $88.40 です。

照合は通貨の最小単位まで完全一致で行われます。1 単位でもずれれば公開はできません。それがこの手順の目的です。

何も起きてはいけないカート
  • drop to 1 of the same product, under what the rule needs
このオファーが発動してはいけないカート
商品数量単価
Felt Laptop Sleeve1$38.00
小計$38.00
合計$38.00

未ログイン、またはタグのない顧客としてログインしています。

見た目がそっくりな 2 つのファイル

以下の各ペアは、同じ形のスクリプトを 2 通りに書いたものです。違いは 1 行か 2 行ですが、動作は異なります。どちらが手元のものか決める前に、両方を読んでください。

紛らわしいペア D2

Spend threshold percentage (D2)

再構築可

spend_goal オファーとして再現されます。

このカートでの割引: $15.00

異なる行
    line_item.change_line_price(line_item.line_price * (1.0 - (15 / 100.0)), message: "Spend $100, save 15%")
Spend threshold, percentage を読む

Spend threshold fixed amount (D2)

再構築可

spend_goal オファーとして再現されます。

このカートでの割引: $15.00

異なる行
REWARD = Money.new(cents: 1500)
  remaining = REWARD
    break if remaining <= Money.zero
    share = [line_item.line_price, remaining].min
    line_item.change_line_price(line_item.line_price - share, message: "Spend $100, get $15 off")
    remaining = remaining - share
Spend threshold, amount off を読む

よくある質問

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?
2 x Felt Laptop Sleeve at $38.00 plus 1 x Impact Phone Case at $24.00. The engine takes $15.00 off, and checkout charges $85.00.
What will I have to check before publishing?
Confirm which products this applies to. We could not read product targeting from the script.

関連する Script の型

Spend threshold, amount off

A flat sum off the order once the cart crosses a value.

Discounted cart subtotal

A threshold read from what was left after a code had already come off.

Script を貼り付けて再構築を確認

再構築の結果は、公開する前に、以前の Script が請求していた金額と照合されます。

本サイトの運営には必須Cookieを使用しており、お客様の同意をいただいた場合のみ、アクセス状況を把握するための分析Cookieを使用します。詳細は Cookieポリシー.