Script errors not consistent

Highlighted
New Member
1 0 0

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.

Any ideas?

0 Likes
Highlighted
Shopify Expert
9925 103 1762

Hey Clarke,

Just to rule out user error here can you post a screenshot of:

  • the test customers tags from both sites.
  • that customer added into the Scripts Editor (also from both sites)

To me, the error suggests that one of those customers doesn't have tags.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Highlighted
New Member
1 0 0

Jason,

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. 

Clarke

0 Likes
Highlighted
Tourist
15 0 1

Funny thing is if you output the customer tags

puts 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

if !Input.cart.customer.nil?

 

me@georgebutter.com
0 Likes