I have made a request to scene7 to check if a product image exsists, if it does, the jsonp returns this:
/*jsonp*/checkS7SubProductImageExists({"catalogRecord.exists":"1"},"");
The site loads the template for every product, the code is there for every product, but even though the script is repeated, it only only works for the last product, not every product on the page. Any ideas why?
<script>
dojo.io.script.get({
url: '${scene7Path}${skuDetails.partNumber}?req=exists,json&handler=checkS7SubProductImageExists',
error: function(error){
console.debug("Problem retrieving the ImageSet");
}
});
function checkS7SubProductImageExists(results) {
var output_${skuDetails.partNumber} = document.getElementById("item_image_${skuDetails.partNumber}");
if (results['catalogRecord.exists'] == 1) {
var img = '<img src="${env_schemeToUse}://site.scene7.com/is/image/Site/${skuDetails.partNumber}?fmt=png&op_usm=1,1,1,0&id=ZeUq72&fmt=jpg&fit=constrain,1&wid=300&hei=300&fmt=png&op_usm=1,1,1,0">';
}
output_${skuDetails.partNumber}.innerHTML = img;
}
</script>
<div class="item_image">
<a onClick="showItemDialog(${skuDetails.uniqueID}, '${skuDetails.partNumber}', '${iconi_promo_val}', '${iconi_left_val}', '${brand_logo_val}', '${pack_size_val}');return false;" href="#">
<div id="item_image_${skuDetails.partNumber}">
</div>
</a>
</div>
It is not very clear but from what I understood you are copying the piece of code share in your question over and over and over.
If this is correct, then you have a name collision for you function
checkS7SubProductImageExists
. You redefine it over and over, but only one can "exist" : the last one...Try something like bellow.
Please note: this is an EXTREMELY ugly piece of code...!