Skip to content

Instantly share code, notes, and snippets.

@mendelB
Created August 7, 2015 21:08
Show Gist options
  • Save mendelB/81aae0a40a311a50b2c1 to your computer and use it in GitHub Desktop.
Save mendelB/81aae0a40a311a50b2c1 to your computer and use it in GitHub Desktop.
def apply_coupons(cart:[], coupons:[])
coupons.each do |e|
e.each do |key, value|
if cart[value]
if cart[value][:count] - e[:num] >= 0
cart[value][:count] -= e[:num]
if cart["#{value} W/COUPON"].nil?
cart["#{value} W/COUPON"] = cart[value]
cart["#{value} W/COUPON"] = {:price => e[:cost], clearance: cart[value][:clearance]}
cart["#{value} W/COUPON"][:count] = 1
else
cart["#{value} W/COUPON"][:count] += 1
end
end
end
end
end
cart
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment