way to get customer information with javascript

Highlighted
New Member
2 0 0

I tried to get a customer tag information in the javascript module.
first, I coded for it in the main.js.liquid file as the following but I couldn't get customer object.

    customerVariants: function() {
      var tags;
      tags = _.map(this.get('customerTags'), function(tag) {
        return "(" + tag + ")";
      });
      return _.map(this.get('upgrades'), function(upgrade) {
        var variant;
        var discount_rate = 1;
  
      {% if customer %}        // customer object is nil

          {% if customer.tags contains 'Gold' %}      // I can't get the customer tag
                if(upgrade.product_type == "Maintenance"){
                  discount_rate = 0.8;
                }
                else{
                  discount_rate = 0.55;
                }
          {% elsif customer.tags contains 'Silver' %}     
                if(upgrade.product_type == "Maintenance"){
                  discount_rate = 0.8;
                }
                else{
                  discount_rate = 0.65;
                }
          {% elsif customer.tags contains 'Standard' %} 
                if(upgrade.product_type == "Maintenance"){
                  discount_rate = 0.8;
                }
                else{
                  discount_rate = 0.75;
                }
          {% elsif customer.tags contains 'Platinum' %}
                if(upgrade.product_type == "Maintenance"){
                  discount_rate = 0.7;
                }
                else{
                  discount_rate = 0.45;
                }
          {% elsif customer.tags contains 'Employee' or customer.tags contains 'admin' %}
               discount_rate = 0;
          {% elsif customer.tags contains 'INNEO' %}
               discount_rate = 0.45; 
          {% else %}      
                discount_rate = 1;
          {% endif %}

      {% endif %}        
        
        variant = _.reduce(upgrade.variants, function(best, variant) {
          var isApplicable;
          
          isApplicable = _.find(tags, function(tag) {
            return variant.title.indexOf(tag) >= 0;
          });
          return isApplicable && variant || best;
        });


current, the customer object hasn't any value.

I need to get the customer tag.

please let me know the best way that solves this issue.

Thanks

0 Likes
Highlighted
Shopify Partner
7 0 1

I had the same question here

0 Likes