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

Migrating an exclude sale items script

The same intent, often the same comment in the merchant’s own file, and two completely different answers depending on how the markdown was detected. Getting the pair backwards either refuses something we support or leaks margin on every clearance line.

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

It skipped any line whose product was already marked down.

この処理はマーチャントによって 2 通りの書き方がされており、すべてが同じ意味とは限りません。それぞれの書き方を、専用のカートと数値とともに以下に示します。

自分のストアで試す

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

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

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

Exclude sale items tag proxy (D8)

再構築可

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

元の Ruby

DISCOUNT_PERCENTAGE = 10

Input.cart.line_items.each do |line_item|
  next if line_item.variant.product.tags.include?("sale")
  new_price = line_item.original_line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0))
  line_item.change_line_price(new_price, message: "10% off full-price items")
end

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

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

すべての設定項目
設定項目設定キー
Offer typevolumetype
Countingper_productcounting
Recurrenceoncerecurrence
Tier 1min qty 1 -> 10% offtiers[0]
Target scopealltarget.scope
Target excludessaletarget.excludeIds
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
確認を求められます
  • Your Script limited this to a tag, vendor, or product type. We carried that filter over, so confirm it selects the products you expect.
それを裏づけるカート

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

  • Targeting excludes sale. No Meridian Goods product carries those, so every product stays eligible and the exclusion is proved by the campaign settings, not by the cart.
このオファーが発動するカートと、その金額
商品数量単価
Braided USB-C Cable1$14.00
小計$14.00
割引-$1.40
合計$12.60

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

ツールが照合する金額

公開前に、ツールは手元のカートに対して以前の Script が何をしていたかを尋ねます。カートを Braided USB-C Cable 1、単価 $14.00 に設定すれば、答えは一つに定まります。

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

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

何も起きてはいけないカート
  • swap the cart for a single Ceramic Travel Mug
このオファーが発動してはいけないカート
商品数量単価
Ceramic Travel Mug1$22.00
小計$22.00
合計$22.00

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

Exclude sale items compare at (D8)

未対応

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

元の Ruby

DISCOUNT_PERCENTAGE = 10

Input.cart.line_items.each do |line_item|
  next if line_item.variant.compare_at_price && line_item.variant.compare_at_price > line_item.variant.price
  new_price = line_item.original_line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0))
  line_item.change_line_price(new_price, message: "10% off full-price items")
end

Output.cart = Input.cart
これはどうなるか

We have not built this yet

Your Script skipped items that were already marked down. Shopify does give us the sale price, but our checkout query is already at Shopify's cost limit, so we cannot ask for it today. Exclude those products by hand and we can rebuild the rest.

これは Shopify ではなく当社の不足です。Shopify では許可されていますが当社が未実装なので、リンクできる先はなく、プラットフォームのせいにできる点もありません。

理由キー: unsupported.compareAtExclusion

何も作成されないため、ここに検証できるカートはありません。これを貼り付けても上のメッセージが出るだけで、キャンペーンは作成されません。

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

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

紛らわしいペア D8

Exclude sale items tag proxy (D8)

再構築可

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

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

異なる行
  next if line_item.variant.product.tags.include?("sale")
Exclude sale items を読む

Exclude sale items compare at (D8)

未対応

再現しません。We have not built this yet

異なる行
  next if line_item.variant.compare_at_price && line_item.variant.compare_at_price > line_item.variant.price
Exclude sale items を読む

よくある質問

Will Stackable rebuild this script?
It depends on how yours is written. 1 of the 2 spellings on this page are rebuilt today; the rest are refused with a reason. Compare your file against the Ruby above.
What cart proves it works?
1 x Braided USB-C Cable at $14.00. The engine takes $1.40 off, and checkout charges $12.60.
What will I have to check before publishing?
Your Script limited this to a tag, vendor, or product type. We carried that filter over, so confirm it selects the products you expect.
What happens to the part you cannot rebuild?
We have not built this yet. Your Script skipped items that were already marked down. Shopify does give us the sale price, but our checkout query is already at Shopify's cost limit, so we cannot ask for it today. Exclude those products by hand and we can rebuild the rest.

関連する Script の型

Scoped to a tag or vendor

A discount limited to products carrying one tag, vendor or type.

Exclude gift cards

Gift cards left out of a discount that would otherwise have hit them.

Line item property

A discount keyed on a property attached to one cart line.

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

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

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