I have two Shopify stores. I've created a script to apply a 25% discount if the customer is tagged with "employee". The script works on one of the stores, but generates an error on the other.
part of my script:
customer = Input.cart.customer CAMPAIGNS = [ if customer.tags.include? "employee" ItemCampaign.new( AndSelector.new( ExcludeGiftCardSelector.new, ), PercentageDiscount.new(25, "25% employee discount"), ) else ItemCampaign.new( AndSelector.new( ExcludeGiftCardSelector.new, ), PercentageDiscount.new(0, ""), ) end ]
I get an error on this line:
if customer.tags.include? "employee"
the error is "undefined method 'tags' for nil (No Customer)"
I do have customer with tag="employee" selected on the "input" screen.
Just to rule out user error here can you post a screenshot of:
To me, the error suggests that one of those customers doesn't have tags.
I just double checked, the test customer on the script that isn't working is tagged as "employee" and is added to the Scripts Editor.
What's interesting is the script works regardless of the error.
Funny thing is if you output the customer tags
in this scenario the console outputs the customers tags and also fires the error saying the customer is nil.
I found that the error goes away if I first check the customer does not equal nil