2

how can i access the spConfig variable in a custom function on product view page.

<script type="text/x-magento-init">

    {
                "#product_addtocart_form": {
                    "configurable": {
                        "spConfig": {"attributes":{"93":{"id":"93","code":"color","label":"Color","options":}},
                        "gallerySwitchStrategy": "prepend"
                    }
                }
            }
    }

</script>

when i try to log the

var sp_config = $('#product_addtocart_form').data(); 
console.log(sp_config);

the console log shows the following screen, and i have to access the option prices, enter image description here

0

You can use code like

require(['jquery'], function($) { 
    var config = $('#product_addtocart_form').data('mage-configurable').option('spConfig');
})
  • this gives the error : TypeError: $(...).data(...) is undefined – Asif hhh Feb 27 '17 at 13:04
  • i update script – KAndy Feb 27 '17 at 13:54
  • by using your code, i can print the .data() only, when i give the argument "mage-configurable" it shows undefined – Asif hhh Feb 28 '17 at 6:11
  • @Asifhhh: Can you try with $('#product_addtocart_form').data('mageConfigurable').options.value? – Toan Nguyen Jul 8 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.