Skip to content

Instantly share code, notes, and snippets.

@seedcms
Created January 19, 2017 22:30
Show Gist options
  • Save seedcms/9c72cd7a49f35c1bb16d36064fb23ce5 to your computer and use it in GitHub Desktop.
Save seedcms/9c72cd7a49f35c1bb16d36064fb23ce5 to your computer and use it in GitHub Desktop.
Take a percentage off the product based on vendor
@percent = Decimal.new(20) / 100.0
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
next unless product.vendor.include?('Nike')
line_discount = line_item.line_price * @percent
line_item.change_line_price(line_item.line_price - line_discount, message: "20% off all Nike products!")
end
Output.cart = Input.cart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment