Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dylanjhunt/343cf9faa86674cdee8a55880701dcc7 to your computer and use it in GitHub Desktop.
Save dylanjhunt/343cf9faa86674cdee8a55880701dcc7 to your computer and use it in GitHub Desktop.
discount = Money.new(cents: 100) * 5
discounted_product = 1522083265
products_needed = [592406273, 4283854977, 4284984897]
products_seen = []
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
products_seen << product.id if products_needed.include?(product.id)
end
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next unless product.id == discounted_product
line_item.change_line_price(line_item.line_price - discount, message: "My Sale") if products_seen.uniq.sort == products_needed.uniq.sort
end
Output.cart = Input.cart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment