商品項目指令碼範例

商品項目指令碼會影響購物車中的商品項目,且會變更其屬性與價格。每次購物車屬性變更時,會執行這些指令碼,例如新增或移除商品項目,變更運送地址或新增折扣代碼。

若要在此頁面使用範本,請使用空白範本建立新的指令碼。

步驟:

  1. 在Shopify管理介面中,前往應用程式>脚本编辑器
  2. 按一下建立指令碼
  3. 點擊「商品項目」。
  4. 選取空白範本,然後按一下建立指令碼
  5. Ruby來源程式碼區段中,刪除預設程式碼行:<代码>输出。车=输入.车
  6. 從此頁面複製一個指令碼,貼入Ruby來源程式碼區段。
  7. 編輯此指令碼的自訂設定區段,以便您的商店啟用此功能。
  8. 測試您的指令碼。如需更多資訊,請參閱「對Shopify指令碼進行測試和偵錯」。
  9. 測試之後:
    • 按一下「儲存草稿」,儲存尚未發佈的指令碼草稿,或
    • 按一下「儲存並發佈」,建立並發佈指令碼

以消費金額計算的分級購物車折扣

使用此程式碼提供金額折扣,該折扣依據其購物車中商品的總價值而增加。此折扣會盡可能平均分攤於購物車的各個商品。

舉例來說,在顧客消費超過 $150 美元時,提供 $25 美元的總額折扣;消費超過 $300 美元時,提供 $50 美元的折扣;或在其消費超過 $400 美元時,提供 $75 美元的折扣。

# ================================ 可定制的设置  ================================# ================================================================#根据消费阈值分级购物车折扣#如果购物车总数大于(或等于)一个输入# threshold,关联的折扣将应用到购物车。的#折扣将尽可能均匀地分摊到所有商品上。# -“threshold”是符合条件所需的花费金额# - 'discount_amount'是应用于#车# - 'discount_message'是显示折扣时的消息#被应用# ================================================================SPENDING_THRESHOLDS阈值:150discount_amount:25discount_message:“花150美元就能得到25美元的折扣!”},阈值:300discount_amount:50discount_message:“花300美元就能得到50美元的折扣!”},阈值:400discount_amount:75discount_message:“花400美元就能减75美元!”},# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# DollarDiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DollarDiscountApplicatordef初始化discount_message@discount_messagediscount_message结束def应用line_itemdiscount_amountnew_line_priceline_itemline_price-discount_amountline_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# TieredCartDiscountBySpendCampaign#如果购物车总数大于(或等于)一个输入# threshold,关联的折扣将应用到购物车。的#折扣将尽可能均匀地分摊到所有商品上。# ================================================================TieredCartDiscountBySpendCampaigndef初始化@tierssort_by||:阈值}。反向结束def运行applicable_tier@tiers找到||subtotal_price> =分:One hundred.:阈值])返回如果applicable_tiernil ?discount_applicatorDollarDiscountApplicatorapplicable_tier: discount_message])discount_amountapplicable_tier: discount_amount项目line_itemssort_by|line_item|line_item变体价格自我loop_items项目discount_amountdiscount_applicator结束defloop_itemsline_itemsdiscount_amountdiscount_applicatoravg_discountdiscount_amountto_f1/line_items地图数量:).减少0+)))。2avg_discount分:One hundred.avg_discountdiscount_amount分:One hundred.discount_amountline_itemseach_with_index|line_item指数|打破如果discount_amount< =line_discountavg_discountline_item数量如果discount_amount<line_discount||指数= =line_items大小-1discount_updateline_itemline_price>discount_amount?discount_amountline_itemline_price其他的discount_updateline_itemline_price>line_discount?line_discountline_itemline_price结束discount_amount- =discount_updatediscount_applicator应用line_itemdiscount_update结束结束结束活动TieredCartDiscountBySpendCampaignSPENDING_THRESHOLDS),活动每一个|运动|运动运行输入结束输出输入

以消費金額計算的分級折扣

使用此程式碼提供百分比折扣,該折扣依據其購物車中商品的總價值而增加。

舉例來說,在顧客消費 $30 美元 (含) 以上時,提供 10% 折扣;消費 $50 美元 (含) 以上時,提供 15% 折扣;或在其消費 $100 美元 (含) 以上時,提供 20% 折扣。

# ================================ 可定制的设置  ================================# ================================================================#根据消费门槛分级折扣#如果购物车总数大于(或等于)一个输入# threshold,则关联折扣应用于每个项目。# -“threshold”是符合条件所需的花费金额# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================SPENDING_THRESHOLDS阈值:30.discount_type:百分比discount_amount:10discount_message:“花30美元就能打九折!”},阈值:50discount_type:百分比discount_amount:15discount_message:“花50美元就能打八五折!”},阈值:One hundred.discount_type:百分比discount_amount:20.discount_message:“花100美元就能打8折!”},# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# TieredDiscountBySpendCampaign#如果购物车总数大于(或等于)一个输入# threshold,则关联折扣应用于每个项目。# ================================================================TieredDiscountBySpendCampaigndef初始化@tierssort_by||:阈值}。反向结束def运行applicable_tier@tiers找到||subtotal_price> =分:One hundred.:阈值])返回如果applicable_tiernil ?discount_applicatorDiscountApplicatorapplicable_tier: discount_type),applicable_tier: discount_amount),applicable_tier: discount_messageline_items每一个|line_item|下一个如果line_item变体产品gift_card吗?discount_applicator应用line_item结束结束结束活动TieredDiscountBySpendCampaignSPENDING_THRESHOLDS),活动每一个|运动|运动运行输入结束输出输入

依數量計算的分級產品折扣

使用此程式碼為特定產品提供大量折扣,該百分比折扣依據購物車中的產品總數而增加。

舉例來說,在顧客購買 2 頂帽子 (含) 以上時,各提供 10% 折扣;或在其購買 5 頂帽子 (含) 以上時,提供 15% 折扣。

# ================================ 可定制的设置  ================================# ================================================================#按数量分级产品折扣如果匹配项的总数大于(或#等于)输入的阈值,则相关折扣为#应用于每个匹配项。# - 'product_selector_match_type'决定我们是否寻找#与输入选择器匹配或不匹配的产品。可以号是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'product_selector_type'决定产品的合格程度#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'product_selectors'是一个标识符列表(从上面)#合格产品。产品/变体ID列表应该只#包含数字(例如。没有引号)。如果使用':all',则此#也可以是“nil”。# - 'tiers'是一个层列表,其中:# -“quantity”是你需要购买的最小数量#合格# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================PRODUCT_DISCOUNT_TIERSproduct_selector_match_type:包括product_selector_type:标签product_selectors:“your_tag”),层:数量:2discount_type:百分比discount_amount:10discount_message:“2人以上9折”},数量:5discount_type:百分比discount_amount:15discount_message:“5岁以上打八五折”},),},# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# TieredProductDiscountByQuantityCampaign如果匹配项的总数大于(或#等于)输入的阈值,则相关折扣为#应用于每个匹配项。# ================================================================TieredProductDiscountByQuantityCampaigndef初始化活动@campaigns活动结束def运行@campaigns每一个|运动|product_selectorProductSelector运动: product_selector_match_type),运动: product_selector_type),运动: product_selectors),applicable_itemsline_items选择|line_item|product_selector比赛吗?line_item下一个如果applicable_itemsnil ?total_applicable_quantityapplicable_items地图数量:).减少0+运动:层]。sort_by||数量:}。反向applicable_tier找到||数量:< =total_applicable_quantity下一个如果applicable_tiernil ?discount_applicatorDiscountApplicatorapplicable_tier: discount_type),applicable_tier: discount_amount),applicable_tier: discount_messageapplicable_items每一个|line_item|discount_applicator应用line_item结束结束结束结束活动TieredProductDiscountByQuantityCampaignPRODUCT_DISCOUNT_TIERS),活动每一个|运动|运动运行输入结束输出输入

依產品消費金額計算的分級產品折扣

使用此程式碼以依據此購物車中特定商品項目的總價值,所提供的折扣百分比。

舉例來說,在顧客消費 $30 美元 (含) 以上時,提供 10% 折扣;消費 $50 美元 (含) 以上時,提供 15% 折扣;並在其消費 $100 美元 (含) 以上時,提供 20% 折扣,但僅針對符合特定標籤的品項提供折扣。

# ================================ 可定制的设置  ================================# ================================================================#分级产品折扣产品消费Threhsold如果花费在匹配物品上的总金额大于(或#等于)输入的阈值,则相关折扣为#应用于每个匹配项。# - 'product_selector_match_type'决定我们是否寻找#与输入选择器匹配或不匹配的产品。可以号是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'product_selector_type'决定产品的合格程度#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'product_selectors'是一个标识符列表(从上面)#用于合格产品。产品/变体ID列表应该#只包含数字(例如。没有引号)。如果使用':all',# this也可以是'nil'。# - 'tiers'是一个层列表,其中:# -“threshold”是需要的最低金额#合格# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================PRODUCT_DISCOUNT_TIERSproduct_selector_match_type:排除product_selector_type:标签product_selectors:“your_tag”“another_tag”),层:阈值:One hundred.discount_type:百分比discount_amount:10discount_message:“花100美元或以上,就能打九折!”},),},# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# TieredProductDiscountByProductSpendCampaign如果花费在匹配物品上的总金额大于(或#等于)输入的阈值,则相关折扣为#应用于每个匹配项。# ================================================================TieredProductDiscountByProductSpendCampaigndef初始化活动@campaigns活动结束def运行@campaigns每一个|运动|如果运动: product_selector_type= =:所有total_applicable_costsubtotal_priceapplicable_itemsline_items其他的product_selectorProductSelector运动: product_selector_match_type),运动: product_selector_type),运动: product_selectors),applicable_itemsline_items选择|line_item|product_selector比赛吗?line_item下一个如果applicable_itemsnil ?total_applicable_costapplicable_items地图: line_price).减少+结束运动:层]。sort_by||:阈值}。反向applicable_tier找到||total_applicable_cost> =分:One hundred.:阈值])下一个如果applicable_tiernil ?discount_applicatorDiscountApplicatorapplicable_tier: discount_type),applicable_tier: discount_amount),applicable_tier: discount_messageapplicable_items每一个|line_item|discount_applicator应用line_item结束结束结束结束活动TieredProductDiscountByProductSpendCampaignPRODUCT_DISCOUNT_TIERS),活动每一个|运动|运动运行输入结束输出输入

產品折扣

您可以使用這個指令碼針對特定品項提供折扣。

舉例而言,針對已標示<代码>折扣的品項,向顧客提供 10% 折扣。

# ================================ 可定制的设置  ================================# ================================================================#按产品折扣任何匹配的项目将按输入的金额打折。# - 'product_selector_match_type'决定我们是否寻找#与输入选择器匹配或不匹配的产品。可以号是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'product_selector_type'决定产品的合格程度#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'product_selectors'是一个标识符列表(从上面)#用于合格产品。产品/变体ID列表应该#只包含数字(例如。没有引号)。如果使用':all',# this也可以是'nil'。# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================PRODUCT_DISCOUNTSproduct_selector_match_type:包括product_selector_type:标签product_selectors:“your_tag”),discount_type:百分比discount_amount:10discount_message:“带标签的产品打九折!”# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# ProductDiscountCampaign任何匹配的项目将按输入的金额打折。# ================================================================ProductDiscountCampaigndef初始化活动@campaigns活动结束def运行@campaigns每一个|运动|product_selectorProductSelector运动: product_selector_match_type),运动: product_selector_type),运动: product_selectors),discount_applicatorDiscountApplicator运动: discount_type),运动: discount_amount),运动: discount_messageline_items每一个|line_item|下一个除非product_selector比赛吗?line_itemdiscount_applicator应用line_item结束结束结束结束活动ProductDiscountCampaignPRODUCT_DISCOUNTS),活动每一个|运动|运动运行输入结束输出输入

依折扣代碼提供產品折扣

使用此指令碼,讓系統只在顧客使用特定折扣代碼時提供特定品項的折扣。

舉例而言,若顧客使用<代码>DISCOUNT_10折扣代碼,則針對已標示<代码>折扣的品項,向顧客提供 10% 折扣。

# ================================ 可定制的设置  ================================# ================================================================#产品折扣折扣码#如果使用了任何匹配的折扣代码,则任何匹配的项目#将按输入的金额折算。# - 'discount_code_match_type'确定是否下面# strings应该是完全匹配或部分匹配。可以是:# - ':exact'用于精确匹配# - ':partial'表示部分匹配# - 'discount_codes'是一个字符串列表,用于标识折扣#代码# - 'product_selector_match_type'决定我们是否寻找#与输入选择器匹配或不匹配的产品。可以号是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'product_selector_type'决定产品的合格程度#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'product_selectors'是一个标识符列表(从上面)#用于合格产品。产品/变体ID列表应该#只包含数字(例如。没有引号)。如果使用':all',# this也可以是'nil'。# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================PRODUCT_DISCOUNTS_BY_DISCOUNT_CODEdiscount_code_match_type:精确discount_codes:“TESTCODE1”“TESTCODE2”),product_selector_match_type:包括product_selector_type:标签product_selectors:“your_tag”),discount_type:百分比discount_amount:10discount_message:“带标签的产品打九折!”# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# DiscountCodeSelector属性中的任意一个匹配#输入的代码。# ================================================================DiscountCodeSelectordef初始化match_typediscount_codes@comparatormatch_type= =:确切?“= =”“有吗?”@discount_codesdiscount_codes地图|discount_code|discount_codeupcase结束def比赛吗?discount_code@discount_codes任何?|代码|discount_code代码upcase发送@comparator代码结束结束# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# ProductDiscountByCodeCampaign#如果使用了任何匹配的折扣代码,则任何匹配的项目#将按输入的金额折算。# ================================================================ProductDiscountByCodeCampaigndef初始化活动@campaigns活动结束def运行返回如果discount_codenil ?@campaigns每一个|运动|discount_code_selectorDiscountCodeSelector运动: discount_code_match_type),运动: discount_codes下一个除非discount_code_selector比赛吗?discount_codeproduct_selectorProductSelector运动: product_selector_match_type),运动: product_selector_type),运动: product_selectors),discount_applicatorDiscountApplicator运动: discount_type),运动: discount_amount),运动: discount_messageline_items每一个|line_item|下一个除非product_selector比赛吗?line_itemdiscount_applicator应用line_item结束结束结束结束活动ProductDiscountByCodeCampaignPRODUCT_DISCOUNTS_BY_DISCOUNT_CODE),活动每一个|运动|运动运行输入结束输出输入

購買特定金額的產品,便可獲得第二筆金額折扣

使用此指令碼,如果購買超過指定數量的特定商品便可提供折扣。

舉例而言,在顧客購買 3 件已標示<代码>折扣的品項時,第四件標示<代码>折扣的品項可獲得 50% 折扣。

# ================================ 可定制的设置  ================================# ================================================================#买X,买Y买Z#购买一定数量的匹配物品,得到一定数量的物品使用相同匹配项目的#,以应用所输入的折扣。为#的例子:#“买两件带有‘标签’的产品,再买一件#标有“tag”的标签,优惠10%”# - 'product_selector_match_type'决定我们是否寻找#与输入选择器匹配或不匹配的产品。可以号是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'product_selector_type'决定产品的合格程度#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'product_selectors'是一个标识符列表(从上面)#合格产品。产品/变体ID列表应该只#包含数字(例如。没有引号)。如果使用':all',则此#也可以是“nil”。# - 'quantity_to_buy'是需要购买的产品数量#合格# - 'quantity_to_discount'是要打折的产品数量# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用#在运行多个offer的情况下需要注意的是#产品选择之间不应该有任何重叠#因为这可能会导致额外的折扣。例如,你应该#不要提供“购买1件X产品,5折优惠1件”,以及“购买2件”# X产品,送一件”# ================================================================BUY_X_GET_Y_FOR_Zproduct_selector_match_type:包括product_selector_type::product_selectors:quantity_to_buy:1quantity_to_discount:1discount_type:百分比discount_amount:50discount_message:“买一件,第二件五折!”},# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# BuyXGetYForZCampaign#购买一定数量的匹配物品,得到一定数量的物品使用相同匹配项目的#,以应用所输入的折扣。# ================================================================BuyXGetYForZCampaigndef初始化活动@campaigns活动结束def运行@campaigns每一个|运动|product_selectorProductSelector运动: product_selector_match_type),运动: product_selector_type),运动: product_selectors),eligible_itemsline_items选择|line_item|product_selector比赛吗?line_item下一个如果eligible_itemsnil ?eligible_itemseligible_itemssort_by|line_item|-line_item变体价格quantity_to_buy运动: quantity_to_buyquantity_to_discount运动: quantity_to_discountbundle_sizequantity_to_buy+quantity_to_discountnumber_of_bundleseligible_items地图数量:).减少0+/bundle_size).地板上number_of_discountable_itemsnumber_of_bundlesquantity_to_discount下一个除非number_of_discountable_items>0discount_applicatorDiscountApplicator运动: discount_type),运动: discount_amount),运动: discount_message自我loop_itemsdiscount_applicatoreligible_itemsnumber_of_discountable_itemsquantity_to_buyquantity_to_discount结束结束defloop_itemsdiscount_applicatorline_itemsnum_to_discountquantity_to_buyquantity_to_discount盈余0bundle_sizequantity_to_buy+quantity_to_discountline_items每一个|line_item|line_quantityline_item数量+盈余如果line_quantity>quantity_to_buybundles_per_lineline_quantity/bundle_size).地板上take_quantitybundles_per_linequantity_to_discount盈余+ =line_quantity-bundle_sizebundles_per_line))如果line_item数量>take_quantitydiscount_itemline_item分裂花:take_quantitydiscount_applicator应用discount_item位置line_itemsfind_indexline_itemline_items插入位置+1discount_itemnum_to_discount- =take_quantity其他的discount_applicator应用line_itemnum_to_discount- =line_item数量结束其他的盈余+ =line_quantity结束打破如果num_to_discount< =0结束结束结束活动BuyXGetYForZCampaignBUY_X_GET_Y_FOR_Z),活动每一个|运动|运动运行输入结束输出输入

購買套裝,並以折扣價獲得額外產品

使用此折扣碼,在顧客購買一些其他商品時,對特定商品提供折扣。

舉例而言,若顧客同時購買一頂帽子,一件恤和一副太陽眼鏡,則可免費獲得一雙襪子。

# ================================ 可定制的设置  ================================# ================================================================#购买VWX产品,以Z折扣获得Y产品#购买一捆特定的物品,以折扣价获得另一件物品。#例如:#“买一件t恤、一顶帽子和太阳镜,就能免费得到一双袜子”# - 'bundle_items'是组成# bundle,其中:# - 'product_id'是产品的ID# - 'quantity_needed'是完成所需的数量#捆绑包# - 'quantity_to_buy'是符合条件的捆绑包数量#购买折扣产品# - 'discount_product_selector_match_type#查找与输入匹配或不匹配的产品#选择器。可以是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'discount_product_selector_type'决定如何合格#产品将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'discount_product_selectors'是一个标识符列表(从#以上)的合格产品。产品/变体ID列表#应该只包含数字(例如。没有引号)。如果':all'为# used,这也可以是'nil'。# - 'quantity_to_discount'是要折扣的项目数量每报价## - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================BUNDLE_DISCOUNTSbundle_items:product_id:1234567890987quantity_needed:1},product_id:1234567890986quantity_needed:1},),quantity_to_buy:1discount_product_selector_match_type:包括discount_product_selector_type: product_iddiscount_product_selectors:1234567890123),quantity_to_discount:1discount_type:百分比discount_amount:10discount_message:“购买VWX产品,9折获得Y产品”},# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# BundleSelector#找到所输入的bundle中的任何项目并保存#。# ================================================================BundleSelectordef初始化bundle_items@bundle_itemsbundle_items减少({})|accbundle_item|accbundle_item: product_id]]cart_items:[],quantity_needed:bundle_item: quantity_needed),total_quantity:0acc结束结束def构建line_items每一个|line_item|下一个除非@bundle_itemsline_item变体产品id@bundle_itemsline_item变体产品id] [: cart_items]。line_item@bundle_itemsline_item变体产品id] [: total_quantity+ =line_item数量结束@bundle_items结束结束# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# DiscountLoop#循环所提供的行项并对所提供的行项进行折扣按所提供的折扣编号。# ================================================================DiscountLoopdef初始化discount_applicator@discount_applicatordiscount_applicator结束defloop_itemsline_itemsnum_to_discountline_itemseach_with_index|line_item|打破如果num_to_discount< =0如果line_item数量>num_to_discountsplit_line_itemline_item分裂花:num_to_discount@discount_applicator应用split_line_item位置line_itemsfind_indexline_itemline_items插入位置+1split_line_item打破其他的@discount_applicator应用line_itemnum_to_discount- =line_item数量结束结束结束结束# ================================================================# BundleDiscountCampaign#如果输入的bundle存在,则输入的折扣为#应用到输入的产品。# ================================================================BundleDiscountCampaigndef初始化活动@campaigns活动结束def运行@campaigns每一个|运动|bundle_selectorBundleSelector运动: bundle_items])bundle_itemsbundle_selector构建下一个如果bundle_items任何?|product_idproduct_info|product_info: total_quantity<product_info: quantity_needed结束num_bundlesbundle_items地图|product_idproduct_info|product_info: total_quantity/product_info: quantity_needed])结束num_bundlesnum_bundles最小值地板上product_selectorProductSelector运动: discount_product_selector_match_type),运动: discount_product_selector_type),运动: discount_product_selectors),discount_itemsline_items选择|line_item|product_selector比赛吗?line_item下一个如果discount_itemsnil ?discount_applicatorDiscountApplicator运动: discount_type),运动: discount_amount),运动: discount_messagediscount_loopDiscountLoopdiscount_applicatordiscount_looploop_itemsdiscount_items运动: quantity_to_discountnum_bundles))结束结束结束活动BundleDiscountCampaignBUNDLE_DISCOUNTS),活动每一个|运动|运动运行输入结束输出输入

套裝折扣

在顧客將特定產品組合加入購物車時,使用此折扣碼提供折扣。

舉例而言,針對同時購買一件恤,一頂帽子和一副太陽眼鏡的顧客,提供20%的折扣。

# ================================ 可定制的设置  ================================# ================================================================#购买WXY产品,获得Z折扣#购买一捆特定的产品,以a的价格购买#折扣。例如:#“买一件t恤、一顶帽子和太阳镜,每件都打八折”# - 'bundle_items'是组成# bundle,其中:# - 'product_id'是产品的ID# - 'quantity_needed'是完成所需的数量#捆绑包# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================BUNDLE_DISCOUNTSbundle_items:product_id:1234567890987quantity_needed:1},product_id:1234567890986quantity_needed:1},),discount_type:百分比discount_amount:10discount_message:“购买X产品和Y产品,可以打九折!”},# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# BundleSelector#找到所输入的bundle中的任何项目并保存#。# ================================================================BundleSelectordef初始化bundle_items@bundle_itemsbundle_items减少({})|accbundle_item|accbundle_item: product_id]]cart_items:[],quantity_needed:bundle_item: quantity_needed),total_quantity:0acc结束结束def构建line_items每一个|line_item|下一个如果line_itemline_price_changed吗?下一个除非@bundle_itemsline_item变体产品id@bundle_itemsline_item变体产品id] [: cart_items]。line_item@bundle_itemsline_item变体产品id] [: total_quantity+ =line_item数量结束@bundle_items结束结束# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# DiscountLoop#循环所提供的行项并对所提供的行项进行折扣按所提供的折扣编号。# ================================================================DiscountLoopdef初始化discount_applicator@discount_applicatordiscount_applicator结束defloop_itemsline_itemsnum_to_discountline_itemseach_with_index|line_item|打破如果num_to_discount< =0如果line_item数量>num_to_discountsplit_line_itemline_item分裂花:num_to_discount@discount_applicator应用split_line_item位置line_itemsfind_indexline_itemline_items插入位置+1split_line_item打破其他的@discount_applicator应用line_itemnum_to_discount- =line_item数量结束结束结束结束# ================================================================# BundleDiscountCampaign#如果输入的bundle存在,则输入的折扣为#应用到bundle中的每个项目。# ================================================================BundleDiscountCampaigndef初始化活动@campaigns活动结束def运行@campaigns每一个|运动|bundle_selectorBundleSelector运动: bundle_items])bundle_itemsbundle_selector构建下一个如果bundle_items任何?|product_idproduct_info|product_info: total_quantity<product_info: quantity_needed结束num_bundlesbundle_items地图|product_idproduct_info|product_info: total_quantity/product_info: quantity_needed])结束num_bundlesnum_bundles最小值地板上discount_applicatorDiscountApplicator运动: discount_type),运动: discount_amount),运动: discount_messagediscount_loopDiscountLoopdiscount_applicatorbundle_items每一个|product_idproduct_info|discount_looploop_itemsproduct_info: cart_items),product_info: quantity_needednum_bundles),结束结束结束结束活动BundleDiscountCampaignBUNDLE_DISCOUNTS),活动每一个|运动|运动运行输入结束输出输入

買一送一折扣

使用此指令碼,在顧客購買一定數量的不同產品時,對某項商品提供百分比折扣。

舉例而言,針對同時購買兩件恤的顧客,提供帽子10%折扣。

# ================================ 可定制的设置  ================================# ================================================================#购买W产品V,以Z折扣获得Y产品X#购买一定数量的匹配物品,得到一定数量的#一组不同的匹配项目与输入的折扣#应用。例如:#“买两件t恤,打九折送一顶帽子”# - 'buy_product_selector_match_type'决定我们是否查看#用于与输入的选择器匹配或不匹配的产品。#可以是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'buy_product_selector_type'确定合格的产品#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'buy_product_selectors'是一个标识符列表(从上面)#用于合格产品。产品/变体ID列表应该只#包含数字(例如。没有引号)。如果使用':all',则此#也可以是“nil”。# - 'quantity_to_buy'是需要购买的产品数量#合格# -“get_selector_match_type”与“Buy”相同#版本以上# -“get_product_selector_type”与“Buy”相同#版本以上# - 'get_product_selectors'和' Buy '的意思相同#版本以上# - 'quantity_to_discount'是要打折的产品数量# - 'allow_incomplete_bundle'确定是否部分#商品要打折,可以打折,也可以全部打折#需要在场。可以是:# - 'true'# - 'false'# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================BUYVOFW_GETXOFY_FORZbuy_product_selector_match_type:包括buy_product_selector_type:标签buy_product_selectors:“your_tag”“another_tag”),quantity_to_buy:1get_product_selector_match_type:包括get_product_selector_type:标签get_product_selectors:“your_other_tag”“a_different_tag”),quantity_to_discount:1allow_incomplete_bundle:discount_type:百分比discount_amount:One hundred.discount_message:“买X产品,免费送Y产品!”},buy_product_selector_match_type:包括buy_product_selector_type: product_idbuy_product_selectors:12345678909871234567890986),quantity_to_buy:1get_product_selector_match_type:包括get_product_selector_type: product_idget_product_selectors:12345678909851234567890984),quantity_to_discount:1allow_incomplete_bundle:discount_type:美元discount_amount:10discount_message:“买X产品,Y产品就能减价10美元!”},# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# DiscountLoop#循环所提供的行项并对所提供的行项进行折扣按所提供的折扣编号。# ================================================================DiscountLoopdef初始化discount_applicator@discount_applicatordiscount_applicator结束defloop_itemsline_itemsnum_to_discountline_items每一个|line_item|打破如果num_to_discount< =0如果line_item数量>num_to_discountsplit_line_itemline_item分裂花:num_to_discount@discount_applicator应用split_line_item位置line_itemsfind_indexline_itemline_items插入位置+1split_line_item打破其他的@discount_applicator应用line_itemnum_to_discount- =line_item数量结束结束结束结束# ================================================================# BuyVofWGetXofYForZCampaign#购买一定数量的匹配物品,得到一定数量的#一组不同的匹配项目与输入的折扣#应用。# ================================================================BuyVofWGetXofYForZCampaigndef初始化活动@campaigns活动结束def运行@campaigns每一个|运动|buy_product_selectorProductSelector运动: buy_product_selector_match_type),运动: buy_product_selector_type),运动: buy_product_selectors),get_product_selectorProductSelector运动: get_product_selector_match_type),运动: get_product_selector_type),运动: get_product_selectors),buy_items[]get_item[]line_items每一个|line_item|buy_itemsline_item如果buy_product_selector比赛吗?line_itemget_itemline_item如果get_product_selector比赛吗?line_item结束下一个如果buy_items空的吗?||get_item空的吗?get_itemget_itemsort_by|line_item|line_item变体价格quantity_to_buy运动: quantity_to_buyquantity_to_discount运动: quantity_to_discountbuy_offersbuy_items地图数量:).减少0+/quantity_to_buy).地板上如果运动: allow_incomplete_bundlenumber_of_bundlesbuy_offers其他的get_offersget_item地图数量:).减少0+/quantity_to_discount).地板上number_of_bundlesbuy_offersget_offers]。最小值结束number_of_discountable_itemsnumber_of_bundlesquantity_to_discount下一个除非number_of_discountable_items>0discount_applicatorDiscountApplicator运动: discount_type),运动: discount_amount),运动: discount_messagediscount_loopDiscountLoopdiscount_applicatordiscount_looploop_itemsget_itemnumber_of_discountable_items结束结束结束活动BuyVofWGetXofYForZCampaignBUYVOFW_GETXOFY_FORZ),活动每一个|运动|运动运行输入结束输出输入

以指定金額購買特定數量的產品

使用此指令碼以指定價格提供多種產品。

舉例而言,提供顧客2件t恤$20美元的優惠。

# ================================ 可定制的设置  ================================# ================================================================#花Z美元购买Y产品的X#以特定价格购买特定数量的匹配物品。#例如:“20美元买两件t恤”# - 'product_selector_match_type'决定我们是否寻找#与输入选择器匹配或不匹配的产品。可以号是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'product_selector_type'决定产品的合格程度#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'product_selectors'是一个标识符列表(从上面)#用于合格产品。产品/变体ID列表应该#只包含数字(例如。没有引号)。如果使用':all',# this也可以是'nil'。# - 'quantity_to_buy'是需要购买的产品数量#合格# - 'final_price '是所有产品的收费#是报价的一部分# - 'discount_message'是显示折扣时的消息#被应用# ================================================================BUY_X_GET_Y_FOR_Zproduct_selector_match_type:包括product_selector_type:标签product_selectors:“your_tag”),quantity_to_buy:2final_price:One hundred.discount_message:“20美元买两个”},# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DollarDiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DollarDiscountApplicatordef初始化discount_message@discount_messagediscount_message结束def应用line_itemdiscount_amountnew_line_priceline_itemline_price-discount_amountline_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# BuyXOfYForZCampaign#以特定价格购买特定数量的匹配物品。# ================================================================BuyXOfYForZCampaigndef初始化活动@campaigns活动结束def运行@campaigns每一个|运动|product_selectorProductSelector运动: product_selector_match_type),运动: product_selector_type),运动: product_selectors),eligible_itemsline_items选择|line_item|product_selector比赛吗?line_item下一个如果eligible_itemsnil ?eligible_item_counteligible_items地图数量:).减少0+quantity_to_buy运动: quantity_to_buynumber_of_offerseligible_item_count/quantity_to_buy).地板上下一个除非number_of_offers>0number_of_discountable_itemsnumber_of_offersquantity_to_buytotal_offer_price分:One hundred.number_of_offers运动: final_price])discount_applicatorDollarDiscountApplicator运动: discount_message])自我loop_itemseligible_itemsnumber_of_discountable_itemstotal_offer_pricediscount_applicator结束结束defloop_itemsline_itemsnum_to_discounttotal_pricediscount_applicatorcurrent_priceavg_pricetotal_price1/num_to_discountline_itemsline_itemssort_by|line_item|line_item变体价格line_items每一个|line_item|打破如果num_to_discount< =0如果line_item数量>num_to_discountsplit_line_itemline_item分裂花:num_to_discountdiscount_amountsplit_line_itemline_price-total_price-current_pricediscount_applicator应用split_line_itemdiscount_amount位置line_itemsfind_indexline_itemline_items插入位置+1split_line_item打破elsifline_item数量= =num_to_discountdiscount_amountline_itemline_price-total_price-current_pricediscount_applicator应用line_itemdiscount_amount打破其他的如果line_item变体价格< =avg_pricecurrent_price+ =line_itemline_price其他的discount_amountline_item变体价格-avg_priceline_item数量current_price+ =line_itemline_price-discount_amountdiscount_applicator应用line_itemdiscount_amount结束num_to_discount- =line_item数量结束结束结束结束活动BuyXOfYForZCampaignBUY_X_GET_Y_FOR_Z),活动每一个|运动|运动运行输入结束输出输入

購買即贈免費禮物

使用此指令碼,在購物車總額超過一定金額時,為特定產品提供折扣。

舉例而言,針對消費超過 $75 美元的顧客,提供免費贈品。

# ================================ 可定制的设置  ================================# ================================================================#花X美元,以Z折扣获得Y产品#如果购物车总数大于(或等于)输入的#阈值(减去折扣金额),则输入的#匹配项将按输入的金额折扣价。# - 'product_selector_match_type'决定我们是否寻找#与输入选择器匹配或不匹配的产品。可以号是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'product_selector_type'决定产品的合格程度#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'product_selectors'是一个标识符列表(从上面)#用于合格产品。产品/变体ID列表应该#只包含数字(例如。没有引号)。如果使用':all',# this也可以是'nil'。# -“threshold”是符合资格所需花费的金额# - 'quantity_to_discount'是要折扣的项目数量#如果合格# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================SPENDX_GETY_FORZproduct_selector_match_type:包括product_selector_type: product_idproduct_selectors:1234567890123),阈值:75quantity_to_discount:1discount_type:百分比discount_amount:One hundred.discount_message:“花75美元或更多就能免费获得X产品!”},# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# DiscountLoop#循环所提供的行项并对所提供的行项进行折扣按所提供的折扣编号。# ================================================================DiscountLoopdef初始化discount_applicator@discount_applicatordiscount_applicator结束defloop_itemsline_itemsnum_to_discountline_items每一个|line_item|打破如果num_to_discount< =0如果line_item数量>num_to_discountsplit_line_itemline_item分裂花:num_to_discount@discount_applicator应用split_line_item位置line_itemsfind_indexline_itemline_items插入位置+1split_line_item打破其他的@discount_applicator应用line_itemnum_to_discount- =line_item数量结束结束结束结束# ================================================================# SpendXGetYForZCampaign#如果购物车总数大于(或等于)输入的#阈值(减去折扣金额),则输入的#匹配项将按输入的金额折扣价。# ================================================================SpendXGetYForZCampaigndef初始化活动@campaigns活动结束def运行@campaigns每一个|运动|阈值分:One hundred.运动:阈值下一个如果subtotal_price<阈值product_selectorProductSelector运动: product_selector_match_type),运动: product_selector_type),运动: product_selectors),eligible_itemsline_items选择|line_item|product_selector比赛吗?line_item下一个如果eligible_itemsnil ?eligible_itemseligible_itemssort_by|line_item|line_item变体价格num_to_discount运动: quantity_to_discountcart_totalsubtotal_priceeligible_items每一个|line_item|打破如果num_to_discount< =0如果line_item数量>num_to_discountcart_total- =line_item变体价格num_to_discount打破其他的cart_total- =line_itemline_pricenum_to_discount- =line_item数量结束结束下一个如果cart_total<阈值discount_applicatordiscount_applicatorDiscountApplicator运动: discount_type),运动: discount_amount),运动: discount_messagediscount_loopDiscountLoopdiscount_applicatordiscount_looploop_itemseligible_items运动: quantity_to_discount])结束结束结束活动SpendXGetYForZCampaignSPENDX_GETY_FORZ),活动每一个|运动|运动运行输入结束输出输入

依顧客標籤提供產品折扣

使用此指令碼,針對有特定標籤的顧客,提供特定產品的折扣。

舉例而言,針對有<代码>贵宾標籤的顧客,提供 20% 折扣。

# ================================ 可定制的设置  ================================# ================================================================#产品折扣按客户标签如果我们有一个匹配的客户(通过标签),输入的折扣#将应用于任何匹配项。# - 'customer_tag_match_type'决定我们是否寻找客户#是否使用输入的标签进行标记。可以是:# - ':include'检查客户是否被标记# - ':exclude'以确保客户没有被标记# - 'customer_tags'是用于识别合格标签的列表#客户# - 'product_selector_match_type'决定我们是否寻找#与输入选择器匹配或不匹配的产品。可以号是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'product_selector_type'决定产品的合格程度#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'product_selectors'是一个标识符列表(从上面)#用于合格产品。产品/变体ID列表应该#只包含数字(例如。没有引号)。如果使用':all',# this也可以是'nil'。# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================DISCOUNTS_FOR_CUSTOMER_TAGcustomer_tag_match_type:包括customer_tags:“贵宾”),product_selector_match_type:包括product_selector_type::product_selectors:discount_type:百分比discount_amount:20.discount_message:“VIP客户有折扣!”},# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# CustomerTagSelector#查找所提供的客户是否有任何输入的标记。# ================================================================CustomerTagSelectordef初始化match_type标签@comparatormatch_type= =:包括?“什么?”“没有吗?”@ tags标签地图|标签|标签downcase结束def比赛吗?客户customer_tags客户标签地图|标签|标签downcase@ tagscustomer_tags).发送@comparator结束结束# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# DiscountForCustomerTagCampaign如果我们有一个匹配的客户(通过标签),输入的折扣#应用于任何匹配项。# ================================================================DiscountForCustomerTagCampaigndef初始化活动@campaigns活动结束def运行返回除非客户标签@campaigns每一个|运动|customer_tag_selectorCustomerTagSelector运动: customer_tag_match_type),运动: customer_tags])下一个除非customer_tag_selector比赛吗?客户product_selectorProductSelector运动: product_selector_match_type),运动: product_selector_type),运动: product_selectorsdiscount_applicatorDiscountApplicator运动: discount_type),运动: discount_amount),运动: discount_messageline_items每一个|line_item|下一个除非product_selector比赛吗?line_itemdiscount_applicator应用line_item结束结束结束结束活动DiscountForCustomerTagCampaignDISCOUNTS_FOR_CUSTOMER_TAG),活动每一个|运动|运动运行输入结束输出输入

依顧客行銷而定的產品折扣

您可以使用這個指令碼,針對接受行銷信件的顧客提供特定產品的折扣。

舉例而言,針對任何願意接受行銷資訊的顧客,提供適用於所有產品的 10% 折扣。

# ================================ 可定制的设置  ================================# ================================================================#客户营销的产品折扣ob欧宝娱乐app下载地址#如果客户接受营销,则任何匹配的项目都是ob欧宝娱乐app下载地址#以输入的金额折现。# - 'product_selector_match_type'决定我们是否寻找#与输入选择器匹配或不匹配的产品。可以号是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'product_selector_type'决定产品的合格程度#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'product_selectors'是一个标识符列表(从上面)#用于合格产品。产品/变体ID列表应该#只包含数字(例如。没有引号)。如果使用':all',# this也可以是'nil'。# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================PRODUCT_DISCOUNTS_BY_CUSTOMER_ob欧宝娱乐app下载地址MARKETINGproduct_selector_match_type:包括product_selector_type::product_selectors:discount_type:百分比discount_amount:10discount_message:“订阅客户9折优惠!”# ================================ 脚本代码(不要编辑 ) ===============================# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# ProductDiscountByCustomerob欧宝娱乐app下载地址MarketingCampaign#如果客户接受营销,则任何匹配的项目都是ob欧宝娱乐app下载地址#以输入的金额折现。# ================================================================ProductDiscountByCustomerob欧宝娱乐app下载地址MarketingCampaigndef初始化活动@campaigns活动结束def运行返回如果客户nil ?@campaigns每一个|运动|下一个除非客户accepts_ob欧宝娱乐app下载地址marketing吗?product_selectorProductSelector运动: product_selector_match_type),运动: product_selector_type),运动: product_selectorsdiscount_applicatorDiscountApplicator运动: discount_type),运动: discount_amount),运动: discount_messageline_items每一个|line_item|下一个除非product_selector比赛吗?line_itemdiscount_applicator应用line_item结束结束结束结束活动ProductDiscountByCustomerob欧宝娱乐app下载地址MarketingCampaignPRODUCT_DISCOUNTS_BY_CUSTOMER_ob欧宝娱乐app下载地址MARKETING),活动每一个|运动|运动运行输入结束输出输入

依顧客訂單數量而定的產品折扣

您可以使用這個指令碼,針對提交特定訂單數量的顧客提供特定產品的折扣。

舉例而言,針對沒有訂單的任何顧客,提供 10% 折扣。

# ================================ 可定制的设置  ================================# ================================================================#产品折扣按订单计数#如果客户已经下了匹配数量的订单,任何#匹配项将按输入的金额折扣价。# - 'order_count_match_type'决定我们如何比较#客户的订单数量到输入的限制。可以是:# - ':greater_than'以确保客户的订单计数#大于输入的限制# - ':greater_than_equal'确保客户的订单# count大于或等于输入的限制# - ':less_than'以确保客户的订单计数为#小于输入的限制# - ':less_than_equal'确保客户的订单# count小于或等于输入的限制# - 'product_selector_match_type'决定我们是否寻找#与输入选择器匹配或不匹配的产品。可以号是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'product_selector_type'决定产品的合格程度#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'product_selectors'是一个标识符列表(从上面)#用于合格产品。产品/变体ID列表应该#只包含数字(例如。没有引号)。如果使用':all',# this也可以是'nil'。# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================PRODUCT_DISCOUNTS_BY_ORDER_COUNTorder_count_match_type: less_thanorder_count_limit:1product_selector_match_type:包括product_selector_type::product_selectors:discount_type:百分比discount_amount:10discount_message:“首次购房者打九折!”# ================================ 脚本代码(不要编辑 ) ===============================# ================================================================# OrderCountSelector#查找客户是否下了一定数量的订单# ================================================================OrderCountSelectordef初始化match_type限制@match_typematch_type@limit限制结束def比赛吗?客户如果自我respond_to吗?@match_type自我发送@match_type客户@limit其他的提高RuntimeError“无效的订单计数匹配类型”结束结束defgreater_than客户限制客户orders_count>限制结束defgreater_than_equal客户限制客户orders_count> =限制结束defless_than客户限制客户orders_count<限制结束defless_than_equal客户限制客户orders_count< =限制结束结束# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DiscountApplicator#将输入的折扣应用到所提供的行项目。# ================================================================DiscountApplicatordef初始化discount_typediscount_amountdiscount_message@discount_typediscount_type@discount_messagediscount_message@discount_amount如果discount_type= =: %1-discount_amount0.01其他的分:One hundred.discount_amount结束结束def应用line_itemnew_line_price如果@discount_type= =: %line_itemline_price@discount_amount其他的line_itemline_price-@discount_amountline_item数量),]。马克斯结束line_itemchange_line_pricenew_line_price信息:@discount_message结束结束# ================================================================# ProductDiscountByOrderCountCampaign#如果客户已经下了匹配数量的订单,任何#匹配项将按输入的金额折扣价。# ================================================================ProductDiscountByOrderCountCampaigndef初始化活动@campaigns活动结束def运行返回如果客户nil ?@campaigns每一个|运动|order_count_selectorOrderCountSelector运动: order_count_match_type),运动: order_count_limit下一个除非order_count_selector比赛吗?客户product_selectorProductSelector运动: product_selector_match_type),运动: product_selector_type),运动: product_selectorsdiscount_applicatorDiscountApplicator运动: discount_type),运动: discount_amount),运动: discount_messageline_items每一个|line_item|下一个除非product_selector比赛吗?line_itemdiscount_applicator应用line_item结束结束结束结束活动ProductDiscountByOrderCountCampaignPRODUCT_DISCOUNTS_BY_ORDER_COUNT),活动每一个|运动|运动运行输入结束输出输入

停用折扣碼

使用此指令碼在結帳流程中停用折扣碼。

舉例而言,避免顧客在您商店提供特價時使用折扣代碼。

# ================================ 可定制的设置  ================================# ================================================================#禁用折扣代码使用#任何折扣代码将被拒绝与输入的消息。# - 'REJECTION_MESSAGE'是显示折扣的消息#代码被拒绝# ================================================================REJECTION_MESSAGE“本次促销期间不能使用折扣码”# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# DisableDiscountCodesCampaign#任何折扣代码将被拒绝与输入的消息。# ================================================================DisableDiscountCodesCampaigndef初始化rejection_message@rejection_messagerejection_message结束def运行返回如果discount_codenil ?discount_code拒绝信息:@rejection_message结束结束活动DisableDiscountCodesCampaignREJECTION_MESSAGE),活动每一个|运动|运动运行输入结束输出输入

針對特定產品停用折扣代碼

使用此指令碼,在結帳流程中購物車內有特定產品時,停用折扣代碼。

舉例而言,在購物車中有標示<代码>折扣的品項時,避免顧客使用折扣代碼。

# ================================ 可定制的设置  ================================# ================================================================禁用产品的折扣代码#是否使用任何匹配的折扣代码,以及任何匹配的项目#是在购物车中,折扣代码被拒绝与输入#消息。# - 'discount_code_match_type'确定是否下面# strings应该是完全匹配或部分匹配。可以是:# - ':exact'用于精确匹配# - ':partial'表示部分匹配# - 'discount_codes'是一个字符串列表,用于标识折扣#代码# - 'product_selector_match_type'决定我们是否寻找#与输入选择器匹配或不匹配的产品。可以号是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'product_selector_type'决定产品的合格程度#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'product_selectors'是一个标识符列表(从上面)#用于合格产品。产品/变体ID列表应该#只包含数字(例如。没有引号)。如果使用':all',# this也可以是'nil'。# - 'rejection_message'是显示折扣的消息#代码被拒绝# ================================================================REJECT_DISCOUNT_CODE_FOR_PRODUCTSdiscount_code_match_type:精确discount_codes:“TESTCODE1”“TESTCODE2”),product_selector_match_type:包括product_selector_type:标签product_selectors:“折扣”),rejection_message:“折扣代码不能用于‘打折’产品”# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# DiscountCodeSelector属性中的任意一个匹配#输入的代码。# ================================================================DiscountCodeSelectordef初始化match_typediscount_codes@comparatormatch_type= =:确切?“= =”“有吗?”@discount_codesdiscount_codes地图|discount_code|discount_codeupcase结束def比赛吗?discount_code@discount_codes任何?|代码|discount_code代码upcase发送@comparator代码结束结束# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# DisableDiscountCodesForProductsCampaign#是否使用任何匹配的折扣代码,以及任何匹配的项目#是在购物车中,折扣代码被拒绝与输入#消息。# ================================================================DisableDiscountCodesForProductsCampaigndef初始化活动@campaigns活动结束def运行返回如果discount_codenil ?@campaigns每一个|运动|discount_code_selectorDiscountCodeSelector运动: discount_code_match_type),运动: discount_codes下一个除非discount_code_selector比赛吗?discount_codeproduct_selectorProductSelector运动: product_selector_match_type),运动: product_selector_type),运动: product_selectors),下一个除非line_items任何?|line_item|product_selector比赛吗?line_itemdiscount_code拒绝信息:运动: rejection_message])结束结束结束活动DisableDiscountCodesForProductsCampaignREJECT_DISCOUNT_CODE_FOR_PRODUCTS),活动每一个|运动|运动运行输入结束输出输入

限制產品數量

您可以使用這個指令碼對特定產品套用數量限制。

舉例而言,避免顧客在單筆訂單中購買超過1件“x產品”。

# ================================ 可定制的设置  ================================# ================================================================#产品数量限制如果任意匹配项的数量大于#输入的阈值,多余的物品将从购物车中移除。#需要注意的是,我们不会通知客户#当这种情况发生时。# - 'enable'决定活动是否运行。可以是:# - 'true'运行# - 'false'表示不运行# - 'product_selector_match_type'决定我们是否寻找#与输入选择器匹配或不匹配的产品。可以号是:# - ':include'检查产品是否匹配# - ':exclude'以确保产品不匹配# - 'product_selector_type'决定产品的合格程度#将被识别。可以是:# - ':tag'按标签查找产品# - ':type'按类型查找产品# - ':vendor'按供应商查找产品# - ':product_id'按ID查找产品# - ':variant_id'通过变量ID查找产品# - ':subscription'查找订阅产品# - ':all'用于所有产品# - 'product_selectors'是一个标识符列表(从上面)#用于合格产品。产品/变体ID列表应该#只包含数字(例如。没有引号)。如果使用':all',# this也可以是'nil'。# - 'variant_level_limit'确定是否低于限制#应用于变量或总量级别。为#示例,我可以有X个单独匹配的项目,#或者我只能有X个匹配的项目总数?#可以是:# - 'true'限制在一个变量级别# -“false”限制总数# - 'quantity_allowed'是允许的产品数量# ================================================================QUANTITY_LIMITS启用:真正的活动:product_selector_match_type:包括product_selector_type:标签product_selectors:“有限”),variant_level_limit:真正的quantity_allowed:2},# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector#根据输入的标准查找匹配的产品。# ================================================================ProductSelectordef初始化match_typeselector_type选择器@match_typematch_type@comparatormatch_type= =:包括?“什么?”“没有吗?”@selector_typeselector_type@ selector选择器结束def比赛吗?line_item如果自我respond_to吗?@selector_type自我发送@selector_typeline_item其他的提高RuntimeError“无效的产品选择器类型”结束结束def标签line_itemproduct_tagsline_item变体产品标签地图|标签|标签downcase@ selector@ selector地图|选择器|选择器downcase@ selectorproduct_tags).发送@comparator结束def类型line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品product_typedowncase结束def供应商line_item@ selector@ selector地图|选择器|选择器downcase@match_type= =:包括= =@ selector包括什么?line_item变体产品供应商downcase结束defproduct_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体产品id结束defvariant_idline_item@match_type= =:包括= =@ selector包括什么?line_item变体id结束def订阅line_itemline_itemselling_plan_idnil ?结束def所有line_item真正的结束结束# ================================================================# ProductQuantityLimitCampaign如果任意匹配项的数量大于#输入的阈值,多余的物品将从购物车中移除。# ================================================================ProductQuantityLimitCampaigndef初始化启用活动@enable启用@campaigns活动结束def运行返回除非@enable@campaigns每一个|运动|product_selectorProductSelector运动: product_selector_match_type),运动: product_selector_type),运动: product_selectors如果运动: variant_level_limitapplicable_items{}line_items每一个|line_item|下一个除非product_selector比赛吗?line_itemidline_item变体id如果applicable_itemsid]。nil ?applicable_itemsid项目:[],total_quantity:0结束applicable_itemsid] [:项目]。line_itemapplicable_itemsid] [: total_quantity+ =line_item数量结束下一个如果applicable_itemsnil ?applicable_items每一个|id信息|下一个除非信息: total_quantity>运动: quantity_allowednum_to_remove信息: total_quantity-运动: quantity_allowed自我loop_items信息:项目),num_to_remove结束其他的applicable_itemsline_items选择|line_item|product_selector比赛吗?line_item下一个如果applicable_itemsnil ?total_quantityapplicable_items地图数量:).减少0+下一个除非total_quantity>运动: quantity_allowednum_to_removetotal_quantity-运动: quantity_allowed自我loop_itemsapplicable_itemsnum_to_remove结束结束结束defloop_itemsline_itemsnum_to_removeline_items每一个|line_item|如果line_item数量>num_to_removesplit_line_itemline_item分裂花:num_to_remove打破其他的指数line_itemsfind_indexline_itemline_itemsdelete_at指数num_to_remove- =line_item数量结束打破如果num_to_remove< =0结束结束结束活动ProductQuantityLimitCampaignQUANTITY_LIMITS:使),QUANTITY_LIMITS:活动),),活动每一个|运动|运动运行输入结束输出输入

準備好開始透過Shopify銷售商品了嗎?

免費試用