Skip to content

Instantly share code, notes, and snippets.

@boldsupport
Created February 21, 2020 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boldsupport/4029ba3573fde3058c61237f17712cfa to your computer and use it in GitHub Desktop.
Save boldsupport/4029ba3573fde3058c61237f17712cfa to your computer and use it in GitHub Desktop.
var overrideSearchanise = function() {
if (window.BOLD && window.Searchanise && Searchanise.$) {
var boldgetjson = Searchanise.$.getJSON;
Searchanise.$.getJSON = function(a, b, c) {
if (/www.searchanise.com\/(getresults|getwidgets)/.test(a)) {
return boldgetjson(a, function(r) {
for (var i = 0; i < r.items.length; i++) {
BOLD.helpers.getSearchProduct(r.items[i].link, function(i, prod) {
r.items[i].list_price = r.items[i].price;
r.items[i].price = prod.price/100;
r.items[i].shopify_variants.forEach(function(variant, n) {
var matchingVariant = prod.variants.find(function(v) { return v.id == variant.variant_id })
if (matchingVariant) {
r.items[i].shopify_variants[n].list_price = r.items[i].shopify_variants[n].price;
r.items[i].shopify_variants[n].price = matchingVariant.price/100;
r.items[i].shopify_variants[n].price_USD = (matchingVariant.price/100).toFixed(2);
}
})
}.bind(this, i));
}
typeof b === "function" && b(r);
}, c, "json");
}
return boldgetjson(a,b,c);
}
return true
}
return false
}
var bold_count = 0
var bold_int = setInterval(function() {
bold_count++
(overrideSearchanise() || bold_count > 30) && clearInterval(bold_int)
}, 200)
var BOLD=window.BOLD||{};BOLD.helpers=BOLD.helpers||{},BOLD.helpers.getSearchProduct=function(e,t,o){var n,r=e;(o=o||{}).raw?r+=".js":r+="?view="+(o.view||"json"),(n=new XMLHttpRequest).onreadystatechange=function(){if(4==n.readyState&&200==n.status){var e=n.responseText;"string"==typeof e&&(e=JSON.parse(e)),"function"==typeof t?t(e):"object"==typeof Shopify&&"function"==typeof Shopify.onProduct&&Shopify.onProduct(e)}},n.open("GET",r,!1),n.send()},BOLD.helpers.getProduct=function(e,t,o){var n,r="/products/"+e;(o=o||{}).raw?r+=".js":r+="?view="+(o.view||"json"),(n=new XMLHttpRequest).onreadystatechange=function(){if(4==n.readyState&&200==n.status)try{var r=n.responseText;"string"==typeof r&&(r=JSON.parse(r)),"function"==typeof t?t(r):"object"==typeof Shopify&&"function"==typeof Shopify.onProduct&&Shopify.onProduct(r)}catch(n){if(o.raw)return!1;BOLD.helpers.getProduct(e,t,{raw:!0})}},n.open("GET",r,!0),n.send()};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment