Skip to content

Instantly share code, notes, and snippets.

@boldsupport
Created February 27, 2020 17:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boldsupport/d1a6de433aba112ba7f99a48f70e3ea6 to your computer and use it in GitHub Desktop.
Save boldsupport/d1a6de433aba112ba7f99a48f70e3ea6 to your computer and use it in GitHub Desktop.
// BOLD CUSTOM
var promisesArray = hits.map(function(hit){
return new Promise(function(resolve, reject){
if(hit.option1
&& window.BOLD
&& BOLD.pre
&& typeof BOLD.pre.addProductJson === 'function'){
var productJson = {"id": hit.id, "variants": [{"id": parseInt(hit.objectID), "price": hit.price*100 }]}
BOLD.pre.addProductJson(productJson)
.then(function(product){
if(product.variants.find(function(variant){
return variant.id == hit.objectID
})) {
hit.price = product.variants.find(function(variant){
return variant.id == hit.objectID
}).price * 0.01;
}
resolve(hit);
});
} else {
resolve(hit)
}
});
});
Promise.all(promisesArray)
.then(function(hits){
callback(hits, answer);
});
// callback(hits, answer);
// BOLD CUSTOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment