Uncaught ReferenceError: theme is not defined

Highlighted
New Member
1 0 0

Hi, 

I need a help with adding a code in the empire Shopify theme, as in "empire.js" I did list the below code which allow the autoupdate function but its not working well and after i inspected the issue using google chrome i found this message : Uncaught ReferenceError: theme is not defined
at Empire.js:75. 

any recommendation please ! i am still in my first steps in Shopify development "beginner"

 

  
theme.ShippingBar = (function() {
  
  var bar = document.querySelector('.announcement-bar');
 
  if(bar)
  {
  var promote_txt = bar.dataset.promote;
  var unlocked_txt = bar.dataset.unlocked;
  var treshold = bar.dataset.treshold;
  }
  
  function update()
  {
    if(bar)
    {
    $.getJSON('/cart.js').then(
    
      function(cart) {
     
        var value_left = treshold - cart.total_price;
        var value_left_money = theme.Currency.formatMoney(value_left,theme.moneyFormat);
        
        if(value_left <= 0){
        bar.innerHTML =  '<p class="announcement-bar__message">' + unlocked_txt + '</p>';
        }
        else{
          bar.innerHTML = '<p class="announcement-bar__message">' + promote_txt.replace('[value]',value_left_money) + '</p>';
        }
        
      }
      
    );
    }
  }
  return { update:update }
  
}) ();  

 

0 Likes