Skip to content

Instantly share code, notes, and snippets.

@seedcms
Created January 22, 2017 00:51
Show Gist options
  • Save seedcms/113cb4794647ea1b0eddacebb0ee2e3c to your computer and use it in GitHub Desktop.
Save seedcms/113cb4794647ea1b0eddacebb0ee2e3c to your computer and use it in GitHub Desktop.
Free Gift Script
discounted_product = FREE GIFT ID
products_needed = [PRODUCT THAT NEEDS TO BE ADDED FOR FREE GIFT]
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 * 0.0, message: "Free gift with purchase") 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