How do you get the assocIMG value by the key corresponding to the key, for example
If I have var 11786 , I want it to return media/catalog/product/8795139_633.jpg
var spConfig = { "attributes": { "125": { "id": "125", "code": "pos_colours", "label": "Colour", "options": [{ "id": "236", "label": "Dazzling Blue", "price": "0", "oldPrice": "0", "products": ["11148"] }, { "id": "305", "label": "Vintage Brown", "price": "0", "oldPrice": "0", "products": ["11786", "11787", "11788", "11789", "11790", "11791", "11792", "11793"] }] } } }; var assocIMG = // Added - Removed { here, causes issues with other scripts when not working with a configurable product. { 11786: 'media/catalog/product/8795139_633.jpg', 11787: 'media/catalog/product/8795139_633.jpg', }
Above are the objects I'm working with, and below is my current jQuery. Help would be greatly appreciated.
$('#attribute125').change(function() { var image = $(this).val(); $.each(spConfig.attributes, function() { prods = $(this.options).filter( function() { return this.id == image; } )[0].products[0]; alert(prods); }); });
source share