Skip to content

Instantly share code, notes, and snippets.

@seedcms
Created January 22, 2017 01:57
Show Gist options
  • Save seedcms/9a017df7307fb69a72e339d2551160c6 to your computer and use it in GitHub Desktop.
Save seedcms/9a017df7307fb69a72e339d2551160c6 to your computer and use it in GitHub Desktop.
10% off 3 items / 15% off 7 items via product type
item = 0
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
if product.product_type == "Underwear"
item+=line_item.quantity
elsif product.product_type == "Socks"
item+=line_item.quantity
end
end
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
if product.product_type == "Underwear" || product.product_type == "Socks"
if item > 2 && item < 7
line_item.change_line_price(line_item.line_price * 0.90, message: "Customers with 3+ pairs of shoes or socks receive 10% off each pair")
elsif item > 6
line_item.change_line_price(line_item.line_price * 0.85, message: "Customers with 7+ pairs of shoes or socks receive 15% off each pair.")
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