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

Migrating a purchase quantity limit script

Not a discount at all, and full of the exact syntax a BOGO uses, so a careless reader turns a purchase limit into a giveaway. The reliable tell is that it deletes cart lines and never changes a price.

別の Shopify API
この Script がしていたこと

It split the excess units off a line and deleted them from the cart.

自分のストアで試す

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

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

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

Script 本体

別の Shopify API

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

元の Ruby

# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP

class QuantityLimit < Campaign
  def initialize(condition, customer_qualifier, cart_qualifier, line_item_selector, limit_by, limit)
    super(condition, customer_qualifier, cart_qualifier, line_item_selector)
    @limit_by = limit_by
    @limit = limit
  end

  def run(cart)
    return unless qualifies?(cart)
    to_delete = []
    counts = {}
    cart.line_items.each_with_index do |item, index|
      next unless @line_item_selector.nil? || @line_item_selector.match?(item)
      key = @limit_by == :product ? item.variant.product.id : item.variant.id
      counts[key] = 0 unless counts[key]
      max_amount = @limit - counts[key]
      if max_amount <= 0
        to_delete << index
      elsif item.quantity > max_amount
        item.split(take: max_amount)
        counts[key] += max_amount
      else
        counts[key] += item.quantity
      end
    end
    to_delete.reverse.each { |index| cart.line_items.delete_at(index) }
  end
end

CAMPAIGNS = [
  QuantityLimit.new(:all, nil, nil, ProductTagSelector.new(:does, :match, ["limited"]), :variant, 2),
].freeze

CAMPAIGNS.each do |campaign|
  campaign.run(Input.cart)
end

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

This needs a different kind of Shopify app

Your Script blocked or limited checkout, such as a purchase limit or an age check. Shopify builds that with the Cart and Checkout Validation API, which Stackable does not ship.

Script のこの部分は割引ではありません。Shopify は上に挙げた別の種類の関数でこれを実現しますが、Stackable はそれを提供していません。

Shopify のドキュメントを読む

理由キー: otherApi.cartCheckoutValidation

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

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

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

紛らわしいペア D6

Quantity limit purchase cap (D6)

別の Shopify API

再現しません。This needs a different kind of Shopify app

異なる行
# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP
class QuantityLimit < Campaign
  def initialize(condition, customer_qualifier, cart_qualifier, line_item_selector, limit_by, limit)
    super(condition, customer_qualifier, cart_qualifier, line_item_selector)
    @limit_by = limit_by
    @limit = limit

さらに 26 行の違いが、それぞれのページにあります。

Purchase quantity limit を読む

Quantity limit first n discounted (D6)

再構築可

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

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

異なる行
DISCOUNT_PERCENTAGE = 30
MAX_UNITS = 2
num_to_discount = MAX_UNITS
Input.cart.line_items.each_with_index do |line_item, position|
  break if num_to_discount <= 0
  next unless line_item.variant.product.tags.include?("limited")

さらに 9 行の違いが、それぞれのページにあります。

Limit the discounted units を読む

よくある質問

Will Stackable rebuild this script?
No, and the reason is stated rather than hidden: Your Script blocked or limited checkout, such as a purchase limit or an age check. Shopify builds that with the Cart and Checkout Validation API, which Stackable does not ship.

関連する Script の型

Limit the discounted units

The discount applied to the first few units only, with the rest at full price.

Remove products by country

Products that could not ship to the shopper’s country, quietly deleted.

Hide a payment method

A payment option taken off checkout under a condition.

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

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

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