Skip to content

Instantly share code, notes, and snippets.

@dylanjhunt
Created November 15, 2016 23:38
Show Gist options
  • Save dylanjhunt/fe36c416ad83474c94754b8a31e6c5ea to your computer and use it in GitHub Desktop.
Save dylanjhunt/fe36c416ad83474c94754b8a31e6c5ea to your computer and use it in GitHub Desktop.
total = Input.cart.subtotal_price_was
discount = 0.2 #discount percent in decimal format
message = "20% off Sitewide" #message to show when discount is applied
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
line_item.change_line_price(line_item.line_price * (1-discount), message: message) unless discount == 0
end
Output.cart = Input.cart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment