Created
February 27, 2020 17:19
-
-
Save boldsupport/d1a6de433aba112ba7f99a48f70e3ea6 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
// 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