Created
February 20, 2020 22:17
-
-
Save boldsupport/e106bb0c4d894c5cc7746cddc7cda194 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Polyfill Promise for IE | |
// | |
window.Promise || (function() { | |
var scr = document.createElement('script') | |
scr.src = 'https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js' | |
document.head.appendChild(scr) | |
})() | |
// | |
// End Polyfill | |
// | |
// | |
// Collection Grid Fix | |
// | |
function renderDiscountIcons(products) { | |
for (var i = 0; i < products.length; i++) { | |
var ele = document.querySelector('a[href*="' + products[i].handle + '"]'); | |
var xhr = new XMLHttpRequest() | |
xhr.addEventListener('load', function(res) { | |
var img = document.createRange().createContextualFragment(res.target.response); | |
this.prepend(img); | |
}.bind(ele)) | |
xhr.open('GET', '/products/' + products[i].handle + '?view=bold_discount'); | |
xhr.send(); | |
} | |
} | |
var bold_BCSfFilterCallback = BCSfFilterCallback; | |
BCSfFilterCallback = function(res) { | |
var promises = [] | |
for (var i = 0; i < res.products.length; i++) { | |
if (res.products[i].product_type === "OPTIONS_HIDDEN_PRODUCT" || res.products[i].product_type === "DISCOUNT_HIDDEN_PRODUCT" || res.products[i].tags.indexOf('DISCOUNT_HIDDEN_PRODUCT') !== -1 || res.products[i].product_type === "MOTIVATOR_HIDDEN_PRODUCT" || res.products[i].tags.indexOf('MOTIVATOR_HIDDEN_PRODUCT') !== -1) { | |
res.products.splice(i, 1); | |
i--; | |
} | |
} | |
for (var i = 0; i < res.products.length; i++) { | |
promises.push(new Promise(function(resolve, reject) { | |
BOLD.helpers.getProduct(res.products[i].handle, function(i, data) { | |
if (data.hidden) { | |
res.products[i].bold_ignore = true | |
return resolve() | |
} | |
res.products[i].price = data.price/100 | |
res.products[i].price_min = data.price_min/100 | |
res.products[i].price_max = data.price_max/100 | |
return resolve() | |
}.bind(this, i), {}, function(i) { | |
res.products[i].bold_ignore = true | |
return resolve() | |
}.bind(this, i)) | |
})) | |
} | |
Promise.all(promises).then(function() { | |
var final_products = [] | |
var prod | |
for (var i in res.products) { | |
prod = res.products[i] | |
if (typeof prod === 'object' && !prod.bold_ignore) { | |
final_products.push(prod) | |
} | |
} | |
res.products = final_products | |
bold_BCSfFilterCallback(res); | |
// Uncomment the line below to render discount icons (Product Discount App only!) | |
//renderDiscountIcons(res.products); | |
if (window.BOLD && BOLD.common && BOLD.common.eventEmitter && | |
typeof BOLD.common.eventEmitter.emit === 'function'){ | |
BOLD.common.eventEmitter.emit('BOLD_CURRENCY_double_check'); | |
} | |
}) | |
} | |
// | |
// End Collection Grid Fix | |
// | |
// | |
// Quick Search Fix | |
// | |
var bold_BCSfSuggestionCallback = BCSfSuggestionCallback; | |
var BCSfSuggestionCallback = function(response) { | |
var promises = [] | |
for (var n = 0; n < response.products.length; n++) { | |
if (response.products[n].product_type === 'DISCOUNT_HIDDEN_PRODUCT' || response.products[n].tags.indexOf('DISCOUNT_HIDDEN_PRODUCT') != -1 || response.products[n].product_type === "OPTIONS_HIDDEN_PRODUCT" || response.products[n].product_type === 'MOTIVATOR_HIDDEN_PRODUCT' || response.products[n].tags.indexOf('MOTIVATOR_HIDDEN_PRODUCT') != -1) { | |
response.products.splice(n, 1); | |
n--; | |
continue; | |
} | |
promises.push(new Promise(function(resolve, reject) { | |
BOLD.helpers.getProduct(response.products[n].handle, function(n, prod) { | |
if (prod.hidden) { | |
response.products[n].bold_ignore = true; | |
return resolve() | |
} | |
response.products[n].price_min = prod.price_min/100; | |
response.products[n].price_max = prod.price_max/100; | |
return resolve() | |
}.bind(this, n), {}, function(i) { | |
response.products[i].bold_ignore = true | |
return resolve() | |
}.bind(this, n)); | |
})) | |
} | |
Promise.all(promises).then(function() { | |
var final_products = [] | |
var prod | |
for (var i in response.products) { | |
prod = response.products[i] | |
if (typeof prod === 'object' && !prod.bold_ignore) { | |
final_products.push(prod) | |
} | |
} | |
response.products = final_products | |
bold_BCSfSuggestionCallback(response); | |
}) | |
} | |
// | |
// End Quick Search Fix | |
// | |
// | |
// Filter Item Fix | |
// | |
if (typeof bcsffilter === "object" && typeof BCSfFilter.prototype.buildFilterOptionSingleList === "function") { | |
var bold_buildFilterOptionSingleList = BCSfFilter.prototype.buildFilterOptionSingleList; | |
BCSfFilter.prototype.buildFilterOptionSingleList = function(data, b) { | |
for (var i = 0; i < data.values.length; i++) { | |
if (data.values[i].key.indexOf('OPTIONS_HIDDEN_PRODUCT') !== -1 || data.values[i].key.indexOf('DISCOUNT_HIDDEN_PRODUCT') !== -1 || data.values[i].key.indexOf('MOTIVATOR_HIDDEN_PRODUCT') !== -1) { | |
data.values.splice(i,1); | |
i-- | |
} | |
} | |
bold_buildFilterOptionSingleList.bind(bcsffilter)(data, b); | |
} | |
} | |
if (typeof bcsffilter === "object" && typeof BCSfFilter.prototype.buildFilterOptionMultipleList === "function") { | |
var bold_buildFilterOptionMultipleList = BCSfFilter.prototype.buildFilterOptionMultipleList | |
BCSfFilter.prototype.buildFilterOptionMultipleList = function(data,b) { | |
for (var i = 0; i < data.values.length; i++) { | |
if (data.values[i].key.indexOf('OPTIONS_HIDDEN_PRODUCT') !== -1 || data.values[i].key.indexOf('DISCOUNT_HIDDEN_PRODUCT') !== -1 || data.values[i].key.indexOf('MOTIVATOR_HIDDEN_PRODUCT') !== -1) { | |
data.values.splice(i,1); | |
i-- | |
} | |
} | |
bold_buildFilterOptionMultipleList.bind(bcsffilter)(data, b); | |
} | |
} | |
// | |
// End Filter Item Fix | |
// | |
// | |
// Bold Helpers getProduct (For Quick Search Fix) | |
// | |
var BOLD=window.BOLD||{};BOLD.helpers=BOLD.helpers||{},BOLD.helpers.getProduct=function(e,t,o,r){var n,s="/products/"+e;(o=o||{}).raw?s+=".js":s+="?view="+(o.view||"json"),(n=new XMLHttpRequest).onreadystatechange=function(){if(4==n.readyState&&200==n.status)try{var s=n.responseText;"string"==typeof s&&(s=JSON.parse(s)),"function"==typeof t?t(s):"object"==typeof Shopify&&"function"==typeof Shopify.onProduct&&Shopify.onProduct(s)}catch(r){if(o.raw)return!1;BOLD.helpers.getProduct(e,t,{raw:!0})}else 404==n.status&&r()},n.open("GET",s,!0),n.send()}; | |
// | |
// End Bold Helpers getProduct | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment