JackTheKnife
Limp Gawd
- Joined
- Mar 27, 2006
- Messages
- 272
I have try to update a div based on data from JSON (produced by Magento core) and choices from drop-down menu (onchange function reloadSKU())
and JSON data:
Where "7" is the main product ID; "33","32","31" etc are options IDs from the drop-down (same as values) and "807", "808" etc are SKUs for particular ID.
I never was doing anything with JSON so simply idk why is not working :\
Thanks
Code:
jQuery(document).ready(function(){
var json = <?php echo $this->getJsonSku() ?>;
jQuery(".product-custom-option").change(function(){
var sel_value = jQuery(".product-custom-option option:selected").val();
console.log(sel_value);
jQuery.each(json, function(i, val) {
var item_opt = val;
jQuery.each(item_opt, function(key, valu) {
if (key=sel_value) {
var sku = valu;
console.log(sku);
}
});
});
jQuery(".p-sku").html("SKU: " + sku);
})
});
Code:
{"7":{"33":"807","32":"808","31":"809","30":"1015","29":"1021"}
Where "7" is the main product ID; "33","32","31" etc are options IDs from the drop-down (same as values) and "807", "808" etc are SKUs for particular ID.
I never was doing anything with JSON so simply idk why is not working :\
Thanks
Last edited: