Mulitple discounts in script. Look at all discounts, but apply only one.

alex168
Shopify Partner
2 0 0

Hi, I have a scenario where I am trying to apply one discount to my cart from a list of possible discounts. Ideally, I would like the script to run through my cart and determine if a certain discount is found and to end the script. Currently, it is applying each condition and therefore the customer is getting mutiple discount on each line item. When, they should be only receiving one coupon NOT ALL OF THEM. 

 

Input.cart.line_items.each do |line_item|
  
  if line_item.variant.product.tags.include?('mix and match')
    if line_item.quantity >= 12
      line_item.change_line_price(line_item.line_price * (1-0.20),message:"20% off for purchasing 12.")
    end
  else line_item.variant.product.tags.empty?('')
    if line_item.quantity >= 12
      line_item.change_line_price(line_item.line_price * (1-0.15),message:"15% off for purchasing 12.")
    end
  end

end

#####
#so the last thing it should do is if it finds any tagged products it should only apply 
#the 20% off coupon and nothing else

Output.cart = Input.cart

I saw something about creating flags, but I am unclear as to how that would work. If someone could help that would be greatly appricaited. 

0 Likes
Mandelbrotian
Shopify Partner
132 1 19

Hi Alex,

So if the cart contains 12 of item A, which is tagged with 'mix and match', and 12 of item B, which has no tag, then the 20% discount should only apply to item A? Or should the 20% discount apply to A and then the 15% discount to B?

Cheers,

Elliott

Feeling a bit lost? Contact elliot@mandelbrotian.com for help with theme setup, alterations, custom functionality, and app development.
0 Likes