Discount code override (take priority) over conditions specified in scripts.

Highlighted
Shopify Partner
2 0 0

Hi, 

Its me again xd. This may be an easy issue, either way I can get the syntax just right. Basically, I am trying to make so that if a non-developer enters a discount in natively in the shopify admin(not using scripts), then I will need that discount to overrides all the present conditionals set in the active scripts. 

To clarify this even further. All discounts entered here in the admin need to override code made in shopify scripts. I need the script to watch for all possible discounts labeled 'discount' + '...." example: discount-summer

My script is below and I will list my possible solutions:

member = false
nonMember = false

line = false


if !Input.cart.customer.nil? and Input.cart.customer.tags.include?('CLUB-LEVEL')
  Input.cart.line_items.each do |line_item|
    if line_item.variant.product.tags.include?('mix and match') && line_item.quantity >= 12 
      line = line_item 
      member = true 
    end
  end
else
  Input.cart.line_items.each do |line_item|
    if line_item.variant.product.tags.include?('mix and match') && line_item.quantity >= 12 
      line = line_item
      nonMember = true
    end
  end
end

if member == true
  line.change_line_price(line.line_price * (1-0.20), message: "20% off for purchasing 12 or more.")
elsif nonMember == true 
  line.change_line_price(line.line_price * (1-0.15), message: "15% off for purchasing 12 or more.")
end 

one idea i had was to make the script watch for a blank variable. if the discount codes entered did not include 'discount' + ..... then I wanted it to execute. if it was found i wanted it override.

blank = ''                <<<<<< new
member = false
nonMember = false

line = false

if !Input.card.discount_codes == 'discount' + blank       <<<<<<<<

if !Input.cart.customer.nil? and Input.cart.customer.tags.include?('CLUB-LEVEL')
  Input.cart.line_items.each do |line_item|
    if line_item.variant.product.tags.include?('mix and match') && line_item.quantity >= 12 
      line = line_item 
      member = true 
    end
  end
else
  Input.cart.line_items.each do |line_item|
    if line_item.variant.product.tags.include?('mix and match') && line_item.quantity >= 12 
      line = line_item
      nonMember = true
    end
  end
end

if member == true
  line.change_line_price(line.line_price * (1-0.20), message: "20% off for purchasing 12 or more.")
elsif nonMember == true 
  line.change_line_price(line.line_price * (1-0.15), message: "15% off for purchasing 12 or more.")
end

else      <<<<<<< new code
end      <<<

 

I greatly appreciate those will to help. Or those that read :)

0 Likes