Ví dụ về tp lnh mc hàng
tp lnh mc hàng nh hưởng n các mặt hàng trong giỏ hàng và có thể thay đổi thuc tính và giá của mặt hàng。Cac tập lệnh不chạy lầnộ星期四c mỗ我见到giỏ挂塞尔đổ我,như他们hoặc xoa mặt挂,塞尔đổ我địchỉgiao挂hoặc马giả米吉尔。
Để sử dng mẫu trên trang này, to tp lnh vi mẫu trng。
Các bc thực hin:
- Trong trang qun trshopify, vàoỨng dụng>脚本编辑器.
- Nhấp农村村民创建脚本(to tp lnh)。
- Nhấp农村村民c Mụ挂.
- Chọn空白模板(Mẫu tr), rdif nhp vào创建脚本(to tp lnh)。
- 阮富仲mụcRuby源代码(Mã nguubnn Ruby), xóa dòng mã mặc nh:<代码>输出。车=输入.车
- Sao chép tp lnh từ trang này và dán vào mcRuby源代码(Mã nguailn Ruby)。
- Chỉnh sửa m: c可定制的设置(Caiđặ深处t图伊chỉnh) củtập lệnhđểhoạtđộng tạ我cử挂起。
- Kiểm tra p lnh。Để bit thêm thông tin, tham khoThử nghim và gỡ lỗi Đoạn mã Shopify.
- 秀姬kiểm tra:
- nhấp农村村民保存草稿(lu blnháp) để lu blnháp cha ng của tp lnh hoặc
- nhấp农村村民保存并发布(lu và) để to và n mã。
Ưu đãi gim giá giỏ hàng c xp hng theo mc chi tiêu
Sử dng tp lnh này để tặng u đãi gim giá theo số tin, ttong theo tổng giá trmặt hàng trong giỏ hàng của khách。Ưu đãi gim giá này。
Vi dụ:Tặng曹khach挂ưuđai giảm 25美元阮富仲Tổng gia trịnếu khach chi越南计量公司ềhơn 150美元,giảm 50美元nếu khach chi越南计量公司ềhơn 300美元hoặc giảm 75美元nếu khach chi越南计量公司ềhơn 400美元。
# ================================ 可定制的设置 ================================# ================================================================#根据消费阈值分级购物车折扣##如果购物车总数大于(或等于)一个输入# threshold,关联的折扣将应用到购物车。的#折扣将尽可能均匀地分摊到所有商品上。## -“threshold”是符合条件所需的花费金额# - 'discount_amount'是应用于#车# - 'discount_message'是显示折扣时的消息#被应用# ================================================================SPENDING_THRESHOLDS=[{阈值:150,discount_amount:25,discount_message:“花150美元就能得到25美元的折扣!”,},{阈值:300,discount_amount:50,discount_message:“花300美元就能得到50美元的折扣!”,},{阈值:400,discount_amount:75,discount_message:“花400美元就能减75美元!”,},]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# DollarDiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DollarDiscountApplicatordef初始化(discount_message)@discount_message=discount_message结束def应用(line_item,discount_amount)new_line_price=line_item.line_price-discount_amountline_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# TieredCartDiscountBySpendCampaign##如果购物车总数大于(或等于)一个输入# threshold,关联的折扣将应用到购物车。的#折扣将尽可能均匀地分摊到所有商品上。# ================================================================类TieredCartDiscountBySpendCampaigndef初始化(层)@tiers=层.sort_by{|层|层[:阈值]}。反向结束def运行(车)applicable_tier=@tiers.找到{|层|车.subtotal_price> =(钱.新(分:One hundred.)*层[:阈值])}返回如果applicable_tier.nil ?discount_applicator=DollarDiscountApplicator.新(applicable_tier[: discount_message])discount_amount=applicable_tier[: discount_amount]项目=车.line_items.sort_by{|line_item|line_item.变体.价格}自我.loop_items(车,项目,discount_amount,discount_applicator)结束defloop_items(车,line_items,discount_amount,discount_applicator)avg_discount=(discount_amount.to_f*(1/line_items.地图(&数量:).减少(0,:+)))。轮(2)avg_discount=钱.新(分:One hundred.)*avg_discountdiscount_amount=钱.新(分:One hundred.)*discount_amountline_items.each_with_index做|line_item,指数|打破如果discount_amount< =钱.零line_discount=avg_discount*line_item.数量如果discount_amount<line_discount||指数= =(line_items.大小-1)discount_update=line_item.line_price>discount_amount?discount_amount:line_item.line_price其他的discount_update=line_item.line_price>line_discount?line_discount:line_item.line_price结束discount_amount- =discount_updatediscount_applicator.应用(line_item,discount_update)结束结束结束活动=[TieredCartDiscountBySpendCampaign.新(SPENDING_THRESHOLDS),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
Ưu đãi gim giá xp hng theo mc chi tiêu
Sử dng tp lnh này để tặng u đãi gim giá theo tỷ lệ phn trm,桐西奥tổng giá trcủa mặt hàng trong giỏ hàng。
Vi dụ:Tặng曹khach挂ưuđai giảm 10% nếu khach chi越南计量Từ30美元trởlen, giảm 15% nếu khach chi越南计量Từ50美元trởlen vhoặc 20% nếu khach chi越南计量T trởlenừ100美元。
# ================================ 可定制的设置 ================================# ================================================================#根据消费门槛分级折扣##如果购物车总数大于(或等于)一个输入# threshold,则关联折扣应用于每个项目。## -“threshold”是符合条件所需的花费金额# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================SPENDING_THRESHOLDS=[{阈值:30.,discount_type:百分比,discount_amount:10,discount_message:“花30美元就能打九折!”,},{阈值:50,discount_type:百分比,discount_amount:15,discount_message:“花50美元就能打八五折!”,},{阈值:One hundred.,discount_type:百分比,discount_amount:20.,discount_message:“花100美元就能打8折!”,},]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# TieredDiscountBySpendCampaign##如果购物车总数大于(或等于)一个输入# threshold,则关联折扣应用于每个项目。# ================================================================类TieredDiscountBySpendCampaigndef初始化(层)@tiers=层.sort_by{|层|层[:阈值]}。反向结束def运行(车)applicable_tier=@tiers.找到{|层|车.subtotal_price> =(钱.新(分:One hundred.)*层[:阈值])}返回如果applicable_tier.nil ?discount_applicator=DiscountApplicator.新(applicable_tier[: discount_type],applicable_tier[: discount_amount],applicable_tier[: discount_message])车.line_items.每一个做|line_item|下一个如果line_item.变体.产品.gift_card吗?discount_applicator.应用(line_item)结束结束结束活动=[TieredDiscountBySpendCampaign.新(SPENDING_THRESHOLDS),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
Ưu đãi gim giá sn phm xp hng theo số l
Sửdụng tập lệnh不đểtặngưuđai giảm gia川崎khach挂邮件用户代理年代ốlượng lớn một Sản phẩm cụthểvớưuđai giảm gia theo tỷlệphần trăm tăng theo Sốlượng年代ản phẩm阮富仲giỏ挂。
Vi dụ:Tặng曹khach挂ưuđai giảm mỗ我ũ10% nếu khach邮件用户代理Từ2 mũtrởlen hoặc giảm 15% nếu khach邮件用户代理ũtrởlen Từ5米。
# ================================ 可定制的设置 ================================# ================================================================#按数量分级产品折扣#如果匹配项的总数大于(或#等于)输入的阈值,则相关折扣为#应用于每个匹配项。## - '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_TIERS=[{product_selector_match_type:包括,product_selector_type:标签,product_selectors:[“your_tag”],层:[{数量:2,discount_type:百分比,discount_amount:10,discount_message:“2人以上9折”,},{数量:5,discount_type:百分比,discount_amount:15,discount_message:“5岁以上打八五折”,},],},]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector##根据输入的标准查找匹配的产品。# ================================================================类ProductSelectordef初始化(match_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# TieredProductDiscountByQuantityCampaign#如果匹配项的总数大于(或#等于)输入的阈值,则相关折扣为#应用于每个匹配项。# ================================================================类TieredProductDiscountByQuantityCampaigndef初始化(活动)@campaigns=活动结束def运行(车)@campaigns.每一个做|运动|product_selector=ProductSelector.新(运动[: product_selector_match_type],运动[: product_selector_type],运动[: product_selectors],)applicable_items=车.line_items.选择{|line_item|product_selector.比赛吗?(line_item)}下一个如果applicable_items.nil ?total_applicable_quantity=applicable_items.地图(&数量:).减少(0,:+)层=运动[:层]。sort_by{|层|层[数量:]}。反向applicable_tier=层.找到{|层|层[数量:]< =total_applicable_quantity}下一个如果applicable_tier.nil ?discount_applicator=DiscountApplicator.新(applicable_tier[: discount_type],applicable_tier[: discount_amount],applicable_tier[: discount_message])applicable_items.每一个做|line_item|discount_applicator.应用(line_item)结束结束结束结束活动=[TieredProductDiscountByQuantityCampaign.新(PRODUCT_DISCOUNT_TIERS),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
Ưu đãi gim giá sn phm xp hng theo mc chi tiêu sn phm
Sử dng tp lnh này để cung cp u đãi gim giá theo tỷ lệ phn trm tongng theo tổng giá trcủa mặt hàng cụ thể trong giỏ hàng。
Vi dụ:Tặng曹khach挂ưuđai giảm 10% nếu khach chi越南计量Từ30美元trởlen, giảm 15% nếu khach chi越南计量Từ50美元trởlen弗吉尼亚州20% nếu khach chi越南计量Từ100美元trởlen, nhưng chỉ曹những mặT挂khớp vớthẻcụể。
# ================================ 可定制的设置 ================================# ================================================================#分级产品折扣产品消费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_TIERS=[{product_selector_match_type:排除,product_selector_type:标签,product_selectors:[“your_tag”,“another_tag”],层:[{阈值:One hundred.,discount_type:百分比,discount_amount:10,discount_message:“花100美元或以上,就能打九折!”,},],},]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector##根据输入的标准查找匹配的产品。# ================================================================类ProductSelectordef初始化(match_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# TieredProductDiscountByProductSpendCampaign#如果花费在匹配物品上的总金额大于(或#等于)输入的阈值,则相关折扣为#应用于每个匹配项。# ================================================================类TieredProductDiscountByProductSpendCampaigndef初始化(活动)@campaigns=活动结束def运行(车)@campaigns.每一个做|运动|如果运动[: product_selector_type]= =:所有total_applicable_cost=车.subtotal_priceapplicable_items=车.line_items其他的product_selector=ProductSelector.新(运动[: product_selector_match_type],运动[: product_selector_type],运动[: product_selectors],)applicable_items=车.line_items.选择{|line_item|product_selector.比赛吗?(line_item)}下一个如果applicable_items.nil ?total_applicable_cost=applicable_items.地图(&: line_price).减少(钱.零,:+)结束层=运动[:层]。sort_by{|层|层[:阈值]}。反向applicable_tier=层.找到{|层|total_applicable_cost> =(钱.新(分:One hundred.)*层[:阈值])}下一个如果applicable_tier.nil ?discount_applicator=DiscountApplicator.新(applicable_tier[: discount_type],applicable_tier[: discount_amount],applicable_tier[: discount_message])applicable_items.每一个做|line_item|discount_applicator.应用(line_item)结束结束结束结束活动=[TieredProductDiscountByProductSpendCampaign.新(PRODUCT_DISCOUNT_TIERS),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
gim giá sn phm
Sử dng tp lnh này để tặng u đãi gim giá cho các mặt hàng cụ thể。
Ví dụ: Tặng cho khách hàng u đãi gim 10% i vi các mặt hàng c gắn thẻ<代码>折扣.
# ================================ 可定制的设置 ================================# ================================================================#按产品折扣#任何匹配的项目将按输入的金额打折。## - '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=[{product_selector_match_type:包括,product_selector_type:标签,product_selectors:[“your_tag”],discount_type:百分比,discount_amount:10,discount_message:“带标签的产品打九折!”}]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector##根据输入的标准查找匹配的产品。# ================================================================类ProductSelectordef初始化(match_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# ProductDiscountCampaign#任何匹配的项目将按输入的金额打折。# ================================================================类ProductDiscountCampaigndef初始化(活动)@campaigns=活动结束def运行(车)@campaigns.每一个做|运动|product_selector=ProductSelector.新(运动[: product_selector_match_type],运动[: product_selector_type],运动[: product_selectors],)discount_applicator=DiscountApplicator.新(运动[: discount_type],运动[: discount_amount],运动[: discount_message])车.line_items.每一个做|line_item|下一个除非product_selector.比赛吗?(line_item)discount_applicator.应用(line_item)结束结束结束结束活动=[ProductDiscountCampaign.新(PRODUCT_DISCOUNTS),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
gim giá sn phm bằng mã gim giá
Sử dng tp lnh này để tặng gim giá cho các mặt hàng cụ thể nu sử dng mã gim giá cụ thể。
Ví dụ: Tặng cho khách hàng u đãi gim 10% i vi các mặt hàng c gắn thẻ<代码>折扣nu họ sử dng mã gim giá<代码>DISCOUNT_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_CODE=[{discount_code_match_type:精确,discount_codes:[“TESTCODE1”,“TESTCODE2”],product_selector_match_type:包括,product_selector_type:标签,product_selectors:[“your_tag”],discount_type:百分比,discount_amount:10,discount_message:“带标签的产品打九折!”}]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# DiscountCodeSelector#属性中的任意一个匹配#输入的代码。# ================================================================类DiscountCodeSelectordef初始化(match_type,discount_codes)@comparator=match_type= =:确切?“= =”:“有吗?”@discount_codes=discount_codes.地图{|discount_code|discount_code.upcase.带}结束def比赛吗?(discount_code)@discount_codes.任何?{|代码|discount_code.代码.upcase.发送(@comparator,代码)}结束结束# ================================================================# ProductSelector##根据输入的标准查找匹配的产品。# ================================================================类ProductSelectordef初始化(match_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# ProductDiscountByCodeCampaign##如果使用了任何匹配的折扣代码,则任何匹配的项目#将按输入的金额折算。# ================================================================类ProductDiscountByCodeCampaigndef初始化(活动)@campaigns=活动结束def运行(车)返回如果车.discount_code.nil ?@campaigns.每一个做|运动|discount_code_selector=DiscountCodeSelector.新(运动[: discount_code_match_type],运动[: discount_codes])下一个除非discount_code_selector.比赛吗?(车.discount_code)product_selector=ProductSelector.新(运动[: product_selector_match_type],运动[: product_selector_type],运动[: product_selectors],)discount_applicator=DiscountApplicator.新(运动[: discount_type],运动[: discount_amount],运动[: discount_message])车.line_items.每一个做|line_item|下一个除非product_selector.比赛吗?(line_item)discount_applicator.应用(line_item)结束结束结束结束活动=[ProductDiscountByCodeCampaign.新(PRODUCT_DISCOUNTS_BY_DISCOUNT_CODE),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
Mua số lng sn phm cụ thể và nhn u đãi gim giá ln Mua hàng thứ hai
Sử dng tp lnh này để tặng u đãi gim giá i vi mount mặt hàng cụ thể khi khách hàng mua nhiu hn mount số ng nht vnh。
Ví dụ: Tặng cho khách hàng u đãi gim giá 50% i vi mặt hàng thứ tư c gắn thẻ<代码>折扣Khi mua ba mặt hàng c gắn thẻ<代码>折扣.
# ================================ 可定制的设置 ================================# ================================================================#买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_Z=[{product_selector_match_type:包括,product_selector_type::,product_selectors:零,quantity_to_buy:1,quantity_to_discount:1,discount_type:百分比,discount_amount:50,discount_message:“买一件,第二件五折!”,},]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector##根据输入的标准查找匹配的产品。# ================================================================类ProductSelectordef初始化(match_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# BuyXGetYForZCampaign##购买一定数量的匹配物品,得到一定数量的物品使用相同匹配项目的#,以应用所输入的折扣。# ================================================================类BuyXGetYForZCampaigndef初始化(活动)@campaigns=活动结束def运行(车)@campaigns.每一个做|运动|product_selector=ProductSelector.新(运动[: product_selector_match_type],运动[: product_selector_type],运动[: product_selectors],)eligible_items=车.line_items.选择{|line_item|product_selector.比赛吗?(line_item)}下一个如果eligible_items.nil ?eligible_items=eligible_items.sort_by{|line_item|-line_item.变体.价格}quantity_to_buy=运动[: quantity_to_buy]quantity_to_discount=运动[: quantity_to_discount]bundle_size=quantity_to_buy+quantity_to_discountnumber_of_bundles=(eligible_items.地图(&数量:).减少(0,:+)/bundle_size).地板上number_of_discountable_items=number_of_bundles*quantity_to_discount下一个除非number_of_discountable_items>0discount_applicator=DiscountApplicator.新(运动[: discount_type],运动[: discount_amount],运动[: discount_message])自我.loop_items(discount_applicator,车,eligible_items,number_of_discountable_items,quantity_to_buy,quantity_to_discount)结束结束defloop_items(discount_applicator,车,line_items,num_to_discount,quantity_to_buy,quantity_to_discount)盈余=0bundle_size=quantity_to_buy+quantity_to_discountline_items.每一个做|line_item|line_quantity=line_item.数量+盈余如果line_quantity>quantity_to_buybundles_per_line=(line_quantity/bundle_size).地板上take_quantity=bundles_per_line*quantity_to_discount盈余+ =(line_quantity-(bundle_size*bundles_per_line))如果line_item.数量>take_quantitydiscount_item=line_item.分裂(花:take_quantity)discount_applicator.应用(discount_item)位置=车.line_items.find_index(line_item)车.line_items.插入(位置+1,discount_item)num_to_discount- =take_quantity其他的discount_applicator.应用(line_item)num_to_discount- =line_item.数量结束其他的盈余+ =line_quantity结束打破如果num_to_discount< =0结束结束结束活动=[BuyXGetYForZCampaign.新(BUY_X_GET_Y_FOR_Z),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
Mua theo gói và nhn u đãi gim giá khi Mua thêm sn phm
Sử dng tp lnh này để tặng u đãi gim giá i vi mặt hàng cụ thể nu khách hàng đã mua nhiu mặt hàng khác。
Ví dụ: Tặng cho khách hàng mut đôi tt min phí khi khách mua cmũ, áo thun và kính râm。
# ================================ 可定制的设置 ================================# ================================================================#购买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_DISCOUNTS=[{bundle_items:[{product_id:1234567890987,quantity_needed:1},{product_id:1234567890986,quantity_needed:1},],quantity_to_buy:1,discount_product_selector_match_type:包括,discount_product_selector_type: product_id,discount_product_selectors:[1234567890123],quantity_to_discount:1,discount_type:百分比,discount_amount:10,discount_message:“购买VWX产品,9折获得Y产品”,},]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# BundleSelector##找到所输入的bundle中的任何项目并保存#。# ================================================================类BundleSelectordef初始化(bundle_items)@bundle_items=bundle_items.减少({})做|acc,bundle_item|acc[bundle_item[: product_id]]={cart_items:[],quantity_needed:bundle_item[: quantity_needed],total_quantity:0,}acc结束结束def构建(车)车.line_items.每一个做|line_item|下一个除非@bundle_items[line_item.变体.产品.id]@bundle_items[line_item.变体.产品.id] [: cart_items]。推(line_item)@bundle_items[line_item.变体.产品.id] [: total_quantity]+ =line_item.数量结束@bundle_items结束结束# ================================================================# ProductSelector##根据输入的标准查找匹配的产品。# ================================================================类ProductSelectordef初始化(match_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# DiscountLoop##循环所提供的行项并对所提供的行项进行折扣按所提供的折扣编号。# ================================================================类DiscountLoopdef初始化(discount_applicator)@discount_applicator=discount_applicator结束defloop_items(车,line_items,num_to_discount)line_items.each_with_index做|line_item|打破如果num_to_discount< =0如果line_item.数量>num_to_discountsplit_line_item=line_item.分裂(花:num_to_discount)@discount_applicator.应用(split_line_item)位置=车.line_items.find_index(line_item)车.line_items.插入(位置+1,split_line_item)打破其他的@discount_applicator.应用(line_item)num_to_discount- =line_item.数量结束结束结束结束# ================================================================# BundleDiscountCampaign##如果输入的bundle存在,则输入的折扣为#应用到输入的产品。# ================================================================类BundleDiscountCampaigndef初始化(活动)@campaigns=活动结束def运行(车)@campaigns.每一个做|运动|bundle_selector=BundleSelector.新(运动[: bundle_items])bundle_items=bundle_selector.构建(车)下一个如果bundle_items.任何?做|product_id,product_info|product_info[: total_quantity]<product_info[: quantity_needed]结束num_bundles=bundle_items.地图做|product_id,product_info|(product_info[: total_quantity]/product_info[: quantity_needed])结束num_bundles=num_bundles.最小值.地板上product_selector=ProductSelector.新(运动[: discount_product_selector_match_type],运动[: discount_product_selector_type],运动[: discount_product_selectors],)discount_items=车.line_items.选择{|line_item|product_selector.比赛吗?(line_item)}下一个如果discount_items.nil ?discount_applicator=DiscountApplicator.新(运动[: discount_type],运动[: discount_amount],运动[: discount_message])discount_loop=DiscountLoop.新(discount_applicator)discount_loop.loop_items(车,discount_items,(运动[: quantity_to_discount]*num_bundles))结束结束结束活动=[BundleDiscountCampaign.新(BUNDLE_DISCOUNTS),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
Ưu đãi gim giá theo gói
Sử dng tp lnh này để tặng u đãi gim giá khi khách hàng thêm mut nhóm sphm nht nh vào giỏ hàng。
Ví dụ: Tặng cho khách hàng u đãi gim 20% khi khách hàng mua áo thun, mũ, và kính râm。
# ================================ 可定制的设置 ================================# ================================================================#购买WXY产品,获得Z折扣##购买一捆特定的产品,以a的价格购买#折扣。例如:##“买一件t恤、一顶帽子和太阳镜,每件都打八折”## - 'bundle_items'是组成# bundle,其中:# - 'product_id'是产品的ID# - 'quantity_needed'是完成所需的数量#捆绑包# - 'discount_type'是要提供的折扣类型。可以#:# - ': % '# - ':dollar'# - 'discount_amount'是百分比/美元折扣# apply(每项)# - 'discount_message'是显示折扣时的消息#被应用# ================================================================BUNDLE_DISCOUNTS=[{bundle_items:[{product_id:1234567890987,quantity_needed:1},{product_id:1234567890986,quantity_needed:1},],discount_type:百分比,discount_amount:10,discount_message:“购买X产品和Y产品,可以打九折!”,},]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# BundleSelector##找到所输入的bundle中的任何项目并保存#。# ================================================================类BundleSelectordef初始化(bundle_items)@bundle_items=bundle_items.减少({})做|acc,bundle_item|acc[bundle_item[: product_id]]={cart_items:[],quantity_needed:bundle_item[: quantity_needed],total_quantity:0,}acc结束结束def构建(车)车.line_items.每一个做|line_item|下一个如果line_item.line_price_changed吗?下一个除非@bundle_items[line_item.变体.产品.id]@bundle_items[line_item.变体.产品.id] [: cart_items]。推(line_item)@bundle_items[line_item.变体.产品.id] [: total_quantity]+ =line_item.数量结束@bundle_items结束结束# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# DiscountLoop##循环所提供的行项并对所提供的行项进行折扣按所提供的折扣编号。# ================================================================类DiscountLoopdef初始化(discount_applicator)@discount_applicator=discount_applicator结束defloop_items(车,line_items,num_to_discount)line_items.each_with_index做|line_item|打破如果num_to_discount< =0如果line_item.数量>num_to_discountsplit_line_item=line_item.分裂(花:num_to_discount)@discount_applicator.应用(split_line_item)位置=车.line_items.find_index(line_item)车.line_items.插入(位置+1,split_line_item)打破其他的@discount_applicator.应用(line_item)num_to_discount- =line_item.数量结束结束结束结束# ================================================================# BundleDiscountCampaign##如果输入的bundle存在,则输入的折扣为#应用到bundle中的每个项目。# ================================================================类BundleDiscountCampaigndef初始化(活动)@campaigns=活动结束def运行(车)@campaigns.每一个做|运动|bundle_selector=BundleSelector.新(运动[: bundle_items])bundle_items=bundle_selector.构建(车)下一个如果bundle_items.任何?做|product_id,product_info|product_info[: total_quantity]<product_info[: quantity_needed]结束num_bundles=bundle_items.地图做|product_id,product_info|(product_info[: total_quantity]/product_info[: quantity_needed])结束num_bundles=num_bundles.最小值.地板上discount_applicator=DiscountApplicator.新(运动[: discount_type],运动[: discount_amount],运动[: discount_message])discount_loop=DiscountLoop.新(discount_applicator)bundle_items.每一个做|product_id,product_info|discount_loop.loop_items(车,product_info[: cart_items],(product_info[: quantity_needed]*num_bundles),)结束结束结束结束活动=[BundleDiscountCampaign.新(BUNDLE_DISCOUNTS),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
Ưu đãi gim giá mua 1 tặng 1 (BOGO)
Sửdụng tập lệnh不đểtặngưuđai giảm gia theo tỷlệphần trămđố我m vớột mặ挂川崎khach挂邮件用户代理một Sốlượng nhấtđịnh củmột Sản phẩm khac。
Ví dụ: Tặng cho khách hàng u đãi gim 10% để mua mutt mũ khi khách hàng mua 2 áo thun。
# ================================ 可定制的设置 ================================# ================================================================#购买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_FORZ=[{buy_product_selector_match_type:包括,buy_product_selector_type:标签,buy_product_selectors:[“your_tag”,“another_tag”],quantity_to_buy:1,get_product_selector_match_type:包括,get_product_selector_type:标签,get_product_selectors:[“your_other_tag”,“a_different_tag”],quantity_to_discount:1,allow_incomplete_bundle:假,discount_type:百分比,discount_amount:One hundred.,discount_message:“买X产品,免费送Y产品!”,},{buy_product_selector_match_type:包括,buy_product_selector_type: product_id,buy_product_selectors:[1234567890987,1234567890986],quantity_to_buy:1,get_product_selector_match_type:包括,get_product_selector_type: product_id,get_product_selectors:[1234567890985,1234567890984],quantity_to_discount:1,allow_incomplete_bundle:假,discount_type:美元,discount_amount:10,discount_message:“买X产品,Y产品就能减价10美元!”,},]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector##根据输入的标准查找匹配的产品。# ================================================================类ProductSelectordef初始化(match_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# DiscountLoop##循环所提供的行项并对所提供的行项进行折扣按所提供的折扣编号。# ================================================================类DiscountLoopdef初始化(discount_applicator)@discount_applicator=discount_applicator结束defloop_items(车,line_items,num_to_discount)line_items.每一个做|line_item|打破如果num_to_discount< =0如果line_item.数量>num_to_discountsplit_line_item=line_item.分裂(花:num_to_discount)@discount_applicator.应用(split_line_item)位置=车.line_items.find_index(line_item)车.line_items.插入(位置+1,split_line_item)打破其他的@discount_applicator.应用(line_item)num_to_discount- =line_item.数量结束结束结束结束# ================================================================# BuyVofWGetXofYForZCampaign##购买一定数量的匹配物品,得到一定数量的#一组不同的匹配项目与输入的折扣#应用。# ================================================================类BuyVofWGetXofYForZCampaigndef初始化(活动)@campaigns=活动结束def运行(车)@campaigns.每一个做|运动|buy_product_selector=ProductSelector.新(运动[: buy_product_selector_match_type],运动[: buy_product_selector_type],运动[: buy_product_selectors],)get_product_selector=ProductSelector.新(运动[: get_product_selector_match_type],运动[: get_product_selector_type],运动[: get_product_selectors],)buy_items=[]get_item=[]车.line_items.每一个做|line_item|buy_items.推(line_item)如果buy_product_selector.比赛吗?(line_item)get_item.推(line_item)如果get_product_selector.比赛吗?(line_item)结束下一个如果buy_items.空的吗?||get_item.空的吗?get_item=get_item.sort_by{|line_item|line_item.变体.价格}quantity_to_buy=运动[: quantity_to_buy]quantity_to_discount=运动[: quantity_to_discount]buy_offers=(buy_items.地图(&数量:).减少(0,:+)/quantity_to_buy).地板上如果运动[: allow_incomplete_bundle]number_of_bundles=buy_offers其他的get_offers=(get_item.地图(&数量:).减少(0,:+)/quantity_to_discount).地板上number_of_bundles=[buy_offers,get_offers]。最小值结束number_of_discountable_items=number_of_bundles*quantity_to_discount下一个除非number_of_discountable_items>0discount_applicator=DiscountApplicator.新(运动[: discount_type],运动[: discount_amount],运动[: discount_message])discount_loop=DiscountLoop.新(discount_applicator)discount_loop.loop_items(车,get_item,number_of_discountable_items)结束结束结束活动=[BuyVofWGetXofYForZCampaign.新(BUYVOFW_GETXOFY_FORZ),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
Mua mut số l
Sửdụng tập lệnh不để禁令米ột秒ốản phẩm vớgiađchọn。
Ví dụ: Bán cho khách hàng 2 áo thun vi giá 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_Z=[{product_selector_match_type:包括,product_selector_type:标签,product_selectors:[“your_tag”],quantity_to_buy:2,final_price:One hundred.,discount_message:“20美元买两个”,},]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector##根据输入的标准查找匹配的产品。# ================================================================类ProductSelectordef初始化(match_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DollarDiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DollarDiscountApplicatordef初始化(discount_message)@discount_message=discount_message结束def应用(line_item,discount_amount)new_line_price=line_item.line_price-discount_amountline_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# BuyXOfYForZCampaign##以特定价格购买特定数量的匹配物品。# ================================================================类BuyXOfYForZCampaigndef初始化(活动)@campaigns=活动结束def运行(车)@campaigns.每一个做|运动|product_selector=ProductSelector.新(运动[: product_selector_match_type],运动[: product_selector_type],运动[: product_selectors],)eligible_items=车.line_items.选择{|line_item|product_selector.比赛吗?(line_item)}下一个如果eligible_items.nil ?eligible_item_count=eligible_items.地图(&数量:).减少(0,:+)quantity_to_buy=运动[: quantity_to_buy]number_of_offers=(eligible_item_count/quantity_to_buy).地板上下一个除非number_of_offers>0number_of_discountable_items=number_of_offers*quantity_to_buytotal_offer_price=钱.新(分:One hundred.)*(number_of_offers*运动[: final_price])discount_applicator=DollarDiscountApplicator.新(运动[: discount_message])自我.loop_items(车,eligible_items,number_of_discountable_items,total_offer_price,discount_applicator)结束结束defloop_items(车,line_items,num_to_discount,total_price,discount_applicator)current_price=钱.零avg_price=total_price*(1/num_to_discount)line_items=line_items.sort_by{|line_item|line_item.变体.价格}line_items.每一个做|line_item|打破如果num_to_discount< =0如果line_item.数量>num_to_discountsplit_line_item=line_item.分裂(花:num_to_discount)discount_amount=split_line_item.line_price-(total_price-current_price)discount_applicator.应用(split_line_item,discount_amount)位置=车.line_items.find_index(line_item)车.line_items.插入(位置+1,split_line_item)打破elsifline_item.数量= =num_to_discountdiscount_amount=line_item.line_price-(total_price-current_price)discount_applicator.应用(line_item,discount_amount)打破其他的如果line_item.变体.价格< =avg_pricecurrent_price+ =line_item.line_price其他的discount_amount=(line_item.变体.价格-avg_price)*line_item.数量current_price+ =(line_item.line_price-discount_amount)discount_applicator.应用(line_item,discount_amount)结束num_to_discount- =line_item.数量结束结束结束结束活动=[BuyXOfYForZCampaign.新(BUY_X_GET_Y_FOR_Z),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
Tặng quà miishan phí khi mua hàng
Sử dng tp lnh này để tặng u đãi gim giá i vi sn phm cụ thể nu tổng giá trgiỏ hàng ln nht số tin nht nh。
Ví dụ: Tặng quà min phí cho khách hàng nu khách hàng chi tiêu nhiu hn 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_FORZ=[{product_selector_match_type:包括,product_selector_type: product_id,product_selectors:[1234567890123],阈值:75,quantity_to_discount:1,discount_type:百分比,discount_amount:One hundred.,discount_message:“花75美元或更多就能免费获得X产品!”,},]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# ProductSelector##根据输入的标准查找匹配的产品。# ================================================================类ProductSelectordef初始化(match_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# DiscountLoop##循环所提供的行项并对所提供的行项进行折扣按所提供的折扣编号。# ================================================================类DiscountLoopdef初始化(discount_applicator)@discount_applicator=discount_applicator结束defloop_items(车,line_items,num_to_discount)line_items.每一个做|line_item|打破如果num_to_discount< =0如果line_item.数量>num_to_discountsplit_line_item=line_item.分裂(花:num_to_discount)@discount_applicator.应用(split_line_item)位置=车.line_items.find_index(line_item)车.line_items.插入(位置+1,split_line_item)打破其他的@discount_applicator.应用(line_item)num_to_discount- =line_item.数量结束结束结束结束# ================================================================# SpendXGetYForZCampaign##如果购物车总数大于(或等于)输入的#阈值(减去折扣金额),则输入的#匹配项将按输入的金额折扣价。# ================================================================类SpendXGetYForZCampaigndef初始化(活动)@campaigns=活动结束def运行(车)@campaigns.每一个做|运动|阈值=钱.新(分:One hundred.)*运动[:阈值]下一个如果车.subtotal_price<阈值product_selector=ProductSelector.新(运动[: product_selector_match_type],运动[: product_selector_type],运动[: product_selectors],)eligible_items=车.line_items.选择{|line_item|product_selector.比赛吗?(line_item)}下一个如果eligible_items.nil ?eligible_items=eligible_items.sort_by{|line_item|line_item.变体.价格}num_to_discount=运动[: quantity_to_discount]cart_total=车.subtotal_priceeligible_items.每一个做|line_item|打破如果num_to_discount< =0如果line_item.数量>num_to_discountcart_total- =line_item.变体.价格*num_to_discount打破其他的cart_total- =line_item.line_pricenum_to_discount- =line_item.数量结束结束下一个如果cart_total<阈值discount_applicator=discount_applicator=DiscountApplicator.新(运动[: discount_type],运动[: discount_amount],运动[: discount_message])discount_loop=DiscountLoop.新(discount_applicator)discount_loop.loop_items(车,eligible_items,运动[: quantity_to_discount])结束结束结束活动=[SpendXGetYForZCampaign.新(SPENDX_GETY_FORZ),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
Ưu đãi gim giá sn phm theo thẻ khách hàng
Sử dng tp lnh này để tặng u đãi gim giá i vi sn phm cụ thể cho khách hàng có thẻ cụ thể。
Ví dụ: Tặng u đãi gim giá 20% nu khách hàng có thẻ<代码>贵宾.
# ================================ 可定制的设置 ================================# ================================================================#产品折扣按客户标签#如果我们有一个匹配的客户(通过标签),输入的折扣#将应用于任何匹配项。## - '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_TAG=[{customer_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,标签)@comparator=match_type= =:包括?“什么?”:“没有吗?”@ tags=标签.地图{|标签|标签.downcase.带}结束def比赛吗?(客户)customer_tags=客户.标签.地图{|标签|标签.downcase.带}(@ tags&customer_tags).发送(@comparator)结束结束# ================================================================# ProductSelector##根据输入的标准查找匹配的产品。# ================================================================类ProductSelectordef初始化(match_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# DiscountForCustomerTagCampaign#如果我们有一个匹配的客户(通过标签),输入的折扣#应用于任何匹配项。# ================================================================类DiscountForCustomerTagCampaigndef初始化(活动)@campaigns=活动结束def运行(车)返回除非车.客户&.标签@campaigns.每一个做|运动|customer_tag_selector=CustomerTagSelector.新(运动[: customer_tag_match_type],运动[: customer_tags])下一个除非customer_tag_selector.比赛吗?(车.客户)product_selector=ProductSelector.新(运动[: product_selector_match_type],运动[: product_selector_type],运动[: product_selectors])discount_applicator=DiscountApplicator.新(运动[: discount_type],运动[: discount_amount],运动[: discount_message])车.line_items.每一个做|line_item|下一个除非product_selector.比赛吗?(line_item)discount_applicator.应用(line_item)结束结束结束结束活动=[DiscountForCustomerTagCampaign.新(DISCOUNTS_FOR_CUSTOMER_TAG),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
gim giá sn phm theo tip thkhách hàng
Sử dng tp lnh này để tặng u đãi gim giá i vi sn phm cụ thể cho khách hàng chp nhn tip th。
Ví dụ: gim giá 10% tt csn phm cho các khách hàng chp nhn tip th。
# ================================ 可定制的设置 ================================# ================================================================#客户营销的产品折扣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下载地址MARKETING=[{product_selector_match_type:包括,product_selector_type::,product_selectors:零,discount_type:百分比,discount_amount:10,discount_message:“订阅客户9折优惠!”}]# ================================ 脚本代码(不要编辑 ) ===============================# ================================================================# ProductSelector##根据输入的标准查找匹配的产品。# ================================================================类ProductSelectordef初始化(match_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# ProductDiscountByCustomerob欧宝娱乐app下载地址MarketingCampaign##如果客户接受营销,则任何匹配的项目都是ob欧宝娱乐app下载地址#以输入的金额折现。# ================================================================类ProductDiscountByCustomerob欧宝娱乐app下载地址MarketingCampaigndef初始化(活动)@campaigns=活动结束def运行(车)返回如果车.客户.nil ?@campaigns.每一个做|运动|下一个除非车.客户.accepts_ob欧宝娱乐app下载地址marketing吗?product_selector=ProductSelector.新(运动[: product_selector_match_type],运动[: product_selector_type],运动[: product_selectors])discount_applicator=DiscountApplicator.新(运动[: discount_type],运动[: discount_amount],运动[: discount_message])车.line_items.每一个做|line_item|下一个除非product_selector.比赛吗?(line_item)discount_applicator.应用(line_item)结束结束结束结束活动=[ProductDiscountByCustomerob欧宝娱乐app下载地址MarketingCampaign.新(PRODUCT_DISCOUNTS_BY_CUSTOMER_ob欧宝娱乐app下载地址MARKETING),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
gim giá sn phm theo số n hàng của khách hàng
Sử dng tp lnh này để tặng u đãi gim giá i vi sn phm cụ thể cho khách hàng có số lng n hàng cụ thể。
Ví dụ: gim giá 10% cho các khách hàng không có n hàng。
# ================================ 可定制的设置 ================================# ================================================================#产品折扣按订单计数##如果客户已经下了匹配数量的订单,任何#匹配项将按输入的金额折扣价。## - '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_COUNT=[{order_count_match_type: less_than,order_count_limit:1,product_selector_match_type:包括,product_selector_type::,product_selectors:零,discount_type:百分比,discount_amount:10,discount_message:“首次购房者打九折!”}]# ================================ 脚本代码(不要编辑 ) ===============================# ================================================================# OrderCountSelector##查找客户是否下了一定数量的订单# ================================================================类OrderCountSelectordef初始化(match_type,限制)@match_type=match_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_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DiscountApplicator##将输入的折扣应用到所提供的行项目。# ================================================================类DiscountApplicatordef初始化(discount_type,discount_amount,discount_message)@discount_type=discount_type@discount_message=discount_message@discount_amount=如果discount_type= =: %1-(discount_amount*0.01)其他的钱.新(分:One hundred.)*discount_amount结束结束def应用(line_item)new_line_price=如果@discount_type= =: %line_item.line_price*@discount_amount其他的[line_item.line_price-(@discount_amount*line_item.数量),钱.零]。马克斯结束line_item.change_line_price(new_line_price,信息:@discount_message)结束结束# ================================================================# ProductDiscountByOrderCountCampaign##如果客户已经下了匹配数量的订单,任何#匹配项将按输入的金额折扣价。# ================================================================类ProductDiscountByOrderCountCampaigndef初始化(活动)@campaigns=活动结束def运行(车)返回如果车.客户.nil ?@campaigns.每一个做|运动|order_count_selector=OrderCountSelector.新(运动[: order_count_match_type],运动[: order_count_limit])下一个除非order_count_selector.比赛吗?(车.客户)product_selector=ProductSelector.新(运动[: product_selector_match_type],运动[: product_selector_type],运动[: product_selectors])discount_applicator=DiscountApplicator.新(运动[: discount_type],运动[: discount_amount],运动[: discount_message])车.line_items.每一个做|line_item|下一个除非product_selector.比赛吗?(line_item)discount_applicator.应用(line_item)结束结束结束结束活动=[ProductDiscountByOrderCountCampaign.新(PRODUCT_DISCOUNTS_BY_ORDER_COUNT),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
Vô hiu hóa mã gim giá
Sử dng tp lnh này để không cho phép sử dng mã gim giá trong quá trình thanh toán。
Ví dụ: ngungn khách hàng sử dng mã gim giá khi cửa hàng ang có t gim giá。
# ================================ 可定制的设置 ================================# ================================================================#禁用折扣代码使用##任何折扣代码将被拒绝与输入的消息。## - 'REJECTION_MESSAGE'是显示折扣的消息#代码被拒绝# ================================================================REJECTION_MESSAGE=“本次促销期间不能使用折扣码”# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# DisableDiscountCodesCampaign##任何折扣代码将被拒绝与输入的消息。# ================================================================类DisableDiscountCodesCampaigndef初始化(rejection_message)@rejection_message=rejection_message结束def运行(车)返回如果车.discount_code.nil ?车.discount_code.拒绝(信息:@rejection_message)结束结束活动=[DisableDiscountCodesCampaign.新(REJECTION_MESSAGE),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
Vô hiu hóa mã gim giá i vi sn phm
Sửdụng tập lệnh不đểkhong曹phep Sửdụng马giảm gia阮富仲作为陈thanh toan nếu . Sản phẩm cụthể阮富仲giỏ挂。
Vi dụ:Ngăn khach挂马sửdụNg giảm gia nếu . sản phẩmđược n gắẻ<代码>折扣Trong giỏ hàng。
# ================================ 可定制的设置 ================================# ================================================================禁用产品的折扣代码##是否使用任何匹配的折扣代码,以及任何匹配的项目#是在购物车中,折扣代码被拒绝与输入#消息。## - '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_PRODUCTS=[{discount_code_match_type:精确,discount_codes:[“TESTCODE1”,“TESTCODE2”],product_selector_match_type:包括,product_selector_type:标签,product_selectors:[“折扣”],rejection_message:“折扣代码不能用于‘打折’产品”}]# ================================ 脚本代码(不要编辑 ) ================================# ================================================================# DiscountCodeSelector#属性中的任意一个匹配#输入的代码。# ================================================================类DiscountCodeSelectordef初始化(match_type,discount_codes)@comparator=match_type= =:确切?“= =”:“有吗?”@discount_codes=discount_codes.地图{|discount_code|discount_code.upcase.带}结束def比赛吗?(discount_code)@discount_codes.任何?{|代码|discount_code.代码.upcase.发送(@comparator,代码)}结束结束# ================================================================# ProductSelector##根据输入的标准查找匹配的产品。# ================================================================类ProductSelectordef初始化(match_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# DisableDiscountCodesForProductsCampaign##是否使用任何匹配的折扣代码,以及任何匹配的项目#是在购物车中,折扣代码被拒绝与输入#消息。# ================================================================类DisableDiscountCodesForProductsCampaigndef初始化(活动)@campaigns=活动结束def运行(车)返回如果车.discount_code.nil ?@campaigns.每一个做|运动|discount_code_selector=DiscountCodeSelector.新(运动[: discount_code_match_type],运动[: discount_codes])下一个除非discount_code_selector.比赛吗?(车.discount_code)product_selector=ProductSelector.新(运动[: product_selector_match_type],运动[: product_selector_type],运动[: product_selectors],)下一个除非车.line_items.任何?{|line_item|product_selector.比赛吗?(line_item)}车.discount_code.拒绝(信息:运动[: rejection_message])结束结束结束活动=[DisableDiscountCodesForProductsCampaign.新(REJECT_DISCOUNT_CODE_FOR_PRODUCTS),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车
gii hn số lsn phm
Sử dng tp lnh này để áp dng gii hn số lng i vi sn phm cụ thể。
Ví dụ: ngnafta n khách hàng mua hn 1 " sn phm X" trong mutt n hàng duy nht。
# ================================ 可定制的设置 ================================# ================================================================#产品数量限制#如果任意匹配项的数量大于#输入的阈值,多余的物品将从购物车中移除。#需要注意的是,我们不会通知客户#当这种情况发生时。## - '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_type,selector_type,选择器)@match_type=match_type@comparator=match_type= =:包括?“什么?”:“没有吗?”@selector_type=selector_type@ selector=选择器结束def比赛吗?(line_item)如果自我.respond_to吗?(@selector_type)自我.发送(@selector_type,line_item)其他的提高RuntimeError.新(“无效的产品选择器类型”)结束结束def标签(line_item)product_tags=line_item.变体.产品.标签.地图{|标签|标签.downcase.带}@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@ selector&product_tags).发送(@comparator)结束def类型(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.product_type.downcase.带)结束def供应商(line_item)@ selector=@ selector.地图{|选择器|选择器.downcase.带}(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.供应商.downcase.带)结束defproduct_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.产品.id)结束defvariant_id(line_item)(@match_type= =:包括)= =@ selector.包括什么?(line_item.变体.id)结束def订阅(line_item)!line_item.selling_plan_id.nil ?结束def所有(line_item)真正的结束结束# ================================================================# ProductQuantityLimitCampaign#如果任意匹配项的数量大于#输入的阈值,多余的物品将从购物车中移除。# ================================================================类ProductQuantityLimitCampaigndef初始化(启用,活动)@enable=启用@campaigns=活动结束def运行(车)返回除非@enable@campaigns.每一个做|运动|product_selector=ProductSelector.新(运动[: product_selector_match_type],运动[: product_selector_type],运动[: product_selectors])如果运动[: variant_level_limit]applicable_items={}车.line_items.每一个做|line_item|下一个除非product_selector.比赛吗?(line_item)id=line_item.变体.id如果applicable_items[id]。nil ?applicable_items[id]={项目:[],total_quantity:0}结束applicable_items[id] [:项目]。推(line_item)applicable_items[id] [: total_quantity]+ =line_item.数量结束下一个如果applicable_items.nil ?applicable_items.每一个做|id,信息|下一个除非信息[: total_quantity]>运动[: quantity_allowed]num_to_remove=信息[: total_quantity]-运动[: quantity_allowed]自我.loop_items(车,信息[:项目],num_to_remove)结束其他的applicable_items=车.line_items.选择{|line_item|product_selector.比赛吗?(line_item)}下一个如果applicable_items.nil ?total_quantity=applicable_items.地图(&数量:).减少(0,:+)下一个除非total_quantity>运动[: quantity_allowed]num_to_remove=total_quantity-运动[: quantity_allowed]自我.loop_items(车,applicable_items,num_to_remove)结束结束结束defloop_items(车,line_items,num_to_remove)line_items.每一个做|line_item|如果line_item.数量>num_to_removesplit_line_item=line_item.分裂(花:num_to_remove)打破其他的指数=车.line_items.find_index(line_item)车.line_items.delete_at(指数)num_to_remove- =line_item.数量结束打破如果num_to_remove< =0结束结束结束活动=[ProductQuantityLimitCampaign.新(QUANTITY_LIMITS[:使],QUANTITY_LIMITS[:活动],),]活动.每一个做|运动|运动.运行(输入.车)结束输出.车=输入.车