Created
October 15, 2019 01:27
-
-
Save jimmijazz/0dcc6d3e6d9cda55770db4edc3aed7ce to your computer and use it in GitHub Desktop.
[Shopify Script]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# EG - I want to offer 15% off all cycling bib shorts when any of our cycling jerseys are purchased. | |
# Assumes no limit on how many of these products can be discounted in one cart | |
cartDiscountAmount = 15 # (Int) Percentage discount to apply. 15 = 15% | |
cartDiscountMessage = "15% off Pedla bibs" # (String) Message to apple when discounting | |
cartDiscountCondition = false # (Boolean) Should the cart discount conditions be applied | |
discountConditionalProductType = "Electronics" # (String) If this product type is in the cart other products may be discounted | |
discountTargetProductType = "Music" # (String) The product type that should be discounted. | |
Input.cart.line_items.each do |line_item| | |
puts line_item.variant.product.product_type | |
if line_item.variant.product.product_type === discountConditionalProductType | |
cartDiscountCondition = true | |
break | |
end | |
end | |
if cartDiscountCondition == true | |
Input.cart.line_items.each do |line_item| | |
if line_item.variant.product.product_type === discountTargetProductType | |
line_item.change_line_price(line_item.line_price * (1 - (cartDiscountAmount / 100)) , message: cartDiscountMessage) | |
end | |
end | |
end | |
Output.cart = Input.cart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment