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"


when i try to log the

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

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

1 Answer 1


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, 2017 at 13:04
  • i update script
    – KAndy
    Feb 27, 2017 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, 2017 at 6:11
  • @Asifhhh: Can you try with $('#product_addtocart_form').data('mageConfigurable').options.value? Jul 8, 2019 at 11:09
  • Thanks @KAndy for providing the answer, one of my major issues got resolved due to this. Feb 1 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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