magento 2 spConfig access
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,

magento2 javascript
bumped to the homepage by Community♦ 17 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
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,

magento2 javascript
bumped to the homepage by Community♦ 17 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
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,

magento2 javascript
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,

magento2 javascript
magento2 javascript
edited Feb 28 '17 at 6:09
Asif hhh
asked Feb 24 '17 at 13:33
Asif hhhAsif hhh
161110
161110
bumped to the homepage by Community♦ 17 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 17 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f161656%2fmagento-2-spconfig-access%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
You can use code like
require(['jquery'], function($) {
var config = $('#product_addtocart_form').data('mage-configurable').option('spConfig');
})
You can use code like
require(['jquery'], function($) {
var config = $('#product_addtocart_form').data('mage-configurable').option('spConfig');
})
edited Feb 27 '17 at 13:53
answered Feb 25 '17 at 22:23
KAndyKAndy
15.9k23044
15.9k23044
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
add a comment |
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
this gives the error : TypeError: $(...).data(...) is undefined
– Asif hhh
Feb 27 '17 at 13:04
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
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
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
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f161656%2fmagento-2-spconfig-access%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown