function refreshProducts() {
    var userMinPrice = parseInt(document.getElementById('price-range-min').value) * 100;
    var userMaxPrice = parseInt(document.getElementById('price-range-max').value) * 100;
    var userChoices = document.querySelectorAll('[data-js="filter"] input:checked');
    var productsString = '';
    // A running count of products which match the user's search configuration
    var matchingProductCount = 0;

    // Product loop
    for (var i = 0; i < objProducts.length; i++) {
      var product = objProducts[i];
      var matchesUserChoices = true;
      // Has the user made any choices?
      if (userChoices.length > 0) {
        // Loop through all of the checked inputs in the filter
        for (var j = 0; j < userChoices.length; j++) {
          var choice = userChoices[j];
          var method = choice.getAttribute('data-js');
          var name   = choice.getAttribute('name');
          var id     = choice.getAttribute('id');

          switch (method) {
            case 'tag':
              matchesUserChoices = matchesProductTag(product,collectIDs(name));
              break;
            case 'choice':
              matchesUserChoices = matchesChoice(product,name,id);
              break;
            case 'metafield':
              matchesUserChoices = matchesMetafield(product,name,id);
              break;
          }
          // Break out early as soon as false is found
          if (!matchesUserChoices) break;
        }
      }

      var stockCheck = true;
      // Only show products which are in stock
      if (document.getElementById('inStock').checked && !product.inStock) stockCheck = false;

      // Does this product match the user's criteria?
      if (
        product.intPrice >= userMinPrice &&
        product.intPrice <= userMaxPrice &&
        matchesUserChoices &&
        stockCheck
      ) {
        matchingProductCount++;
        productsString += '<section aria-label="' + product.title + '" itemscope="" itemtype="http://schema.org/Product">' +
          '<p><img src="' + product.image + '" alt="' + product.imageAlt + '" itemprop="image" loading="lazy"></p>' +
          '<h3 itemprop="name">' + product.title + '</h3>' +
          '<p>' + product.description + '</p>' +
          '<div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">';
        if (product.highPrice) {
          productsString += '<p>Retail: <del itemprop="highPrice">' + product.highPrice + '</del></p>';
        }
        productsString += '<p itemprop="price">' + product.lowPrice + '</p></div>';
        if (product.saving) {
          productsString += '<p>Saving ' + product.saving + '</p>';
        }
        if (product.inStock) {
          productsString += '<p><a href="/cart/add?id=' + product.id + '">Order now</a></p>';
        } else {
          productsString += '<p><strong>Sorry - this product is sold out</strong></p>';
        }
        productsString += '<p><a href="' + product.url + '">More information about ' + product.title + '</a></p></section>';
      }
    }
    if (productsString === '') {
      productsString = '<p>No products found. Please try widening your search.</p>';
    }
    // We have at least one product and need to add the count to the top of the results.
    else {
      var plural = '';
      if (matchingProductCount > 1) plural = 's';
      productsString = '<h2>We have found ' + matchingProductCount + ' product' + plural + '</h2>' + productsString;
    }
    document.querySelector('[data-js="products"]').innerHTML = productsString;
  }
// Rebuilds the product results, based on user's choices
Rebuilds the product results, based on user's choices
Rebuilds the product results based on user ' s choices
function refreshProducts() {
    var userMinPrice = parseInt(document.getElementById('price-range-min').value) * 100;
    var userMaxPrice = parseInt(document.getElementById('price-range-max').value) * 100;
    var userChoices = document.querySelectorAll('[data-js="filter"] input:checked');
    var productsString = '';
    var matchingProductCount = 0;
    for (var i = 0; i < objProducts.length; i++) {
      var product = objProducts[i];
      var matchesUserChoices = true;
      if (userChoices.length > 0) {
        for (var j = 0; j < userChoices.length; j++) {
          var choice = userChoices[j];
          var method = choice.getAttribute('data-js');
          var name   = choice.getAttribute('name');
          var id     = choice.getAttribute('id');
          switch (method) {
            case 'tag':
              matchesUserChoices = matchesProductTag(product,collectIDs(name));
              break;
            case 'choice':
              matchesUserChoices = matchesChoice(product,name,id);
              break;
            case 'metafield':
              matchesUserChoices = matchesMetafield(product,name,id);
              break;
          }
          if (!matchesUserChoices) break;
        }
      }
      var stockCheck = true;
      if (document.getElementById('inStock').checked && !product.inStock) stockCheck = false;
      if (
        product.intPrice >= userMinPrice &&
        product.intPrice <= userMaxPrice &&
        matchesUserChoices &&
        stockCheck
      ) {
        matchingProductCount++;
        productsString += '<section aria-label="' + product.title + '" itemscope="" itemtype="http://schema.org/Product">' +
          '<p><img src="' + product.image + '" alt="' + product.imageAlt + '" itemprop="image" loading="lazy"></p>' +
          '<h3 itemprop="name">' + product.title + '</h3>' +
          '<p>' + product.description + '</p>' +
          '<div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">';
        if (product.highPrice) {
          productsString += '<p>Retail: <del itemprop="highPrice">' + product.highPrice + '</del></p>';
        }
        productsString += '<p itemprop="price">' + product.lowPrice + '</p></div>';
        if (product.saving) {
          productsString += '<p>Saving ' + product.saving + '</p>';
        }
        if (product.inStock) {
          productsString += '<p><a href="/cart/add?id=' + product.id + '">Order now</a></p>';
        } else {
          productsString += '<p><strong>Sorry - this product is sold out</strong></p>';
        }
        productsString += '<p><a href="' + product.url + '">More information about ' + product.title + '</a></p></section>';
      }
    }
    if (productsString === '') {
      productsString = '<p>No products found. Please try widening your search.</p>';
    }
    else {
      var plural = '';
      if (matchingProductCount > 1) plural = 's';
      productsString = '<h2>We have found ' + matchingProductCount + ' product' + plural + '</h2>' + productsString;
    }
    document.querySelector('[data-js="products"]').innerHTML = productsString;
  }
function refreshProducts ( ) { var userMinPrice = parseInt ( document . getElementById ( 'price-range-min' ) . value ) * 100 ; var userMaxPrice = parseInt ( document . getElementById ( 'price-range-max' ) . value ) * 100 ; var userChoices = document . querySelectorAll ( '[data-js="filter"] input:checked' ) ; var productsString = '' ; var matchingProductCount = 0 ; for ( var i = 0 ; i < objProducts . length ; i ++ ) { var product = objProducts [ i ] ; var matchesUserChoices = true ; if ( userChoices . length > 0 ) { for ( var j = 0 ; j < userChoices . length ; j ++ ) { var choice = userChoices [ j ] ; var method = choice . getAttribute ( 'data-js' ) ; var name = choice . getAttribute ( 'name' ) ; var id = choice . getAttribute ( 'id' ) ; switch ( method ) { case 'tag' : matchesUserChoices = matchesProductTag ( product , collectIDs ( name ) ) ; break ; case 'choice' : matchesUserChoices = matchesChoice ( product , name , id ) ; break ; case 'metafield' : matchesUserChoices = matchesMetafield ( product , name , id ) ; break ; } if ( ! matchesUserChoices ) break ; } } var stockCheck = true ; if ( document . getElementById ( 'inStock' ) . checked && ! product . inStock ) stockCheck = false ; if ( product . intPrice >= userMinPrice && product . intPrice <= userMaxPrice && matchesUserChoices && stockCheck ) { matchingProductCount ++ ; productsString += '<section aria-label="' + product . title + '" itemscope="" itemtype="http://schema.org/Product">' + '<p><img src="' + product . image + '" alt="' + product . imageAlt + '" itemprop="image" loading="lazy"></p>' + '<h3 itemprop="name">' + product . title + '</h3>' + '<p>' + product . description + '</p>' + '<div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">' ; if ( product . highPrice ) { productsString += '<p>Retail: <del itemprop="highPrice">' + product . highPrice + '</del></p>' ; } productsString += '<p itemprop="price">' + product . lowPrice + '</p></div>' ; if ( product . saving ) { productsString += '<p>Saving ' + product . saving + '</p>' ; } if ( product . inStock ) { productsString += '<p><a href="/cart/add?id=' + product . id + '">Order now</a></p>' ; } else { productsString += '<p><strong>Sorry - this product is sold out</strong></p>' ; } productsString += '<p><a href="' + product . url + '">More information about ' + product . title + '</a></p></section>' ; } } if ( productsString === '' ) { productsString = '<p>No products found. Please try widening your search.</p>' ; } else { var plural = '' ; if ( matchingProductCount > 1 ) plural = 's' ; productsString = '<h2>We have found ' + matchingProductCount + ' product' + plural + '</h2>' + productsString ; } document . querySelector ( '[data-js="products"]' ) . innerHTML = productsString ; }
Rebuilds the product results, based on user's choices
Rebuilds the product results based on user ' s choices
// A running count of products which match the user's search configuration // Product loop // Has the user made any choices? // Loop through all of the checked inputs in the filter // Break out early as soon as false is found // Only show products which are in stock // Does this product match the user's criteria? // We have at least one product and need to add the count to the top of the results.