How to access to configurable product stock qty via js?
Someone knows how to get qty for each simple product of configurable product via javascript in product page?
It seems that spConfig
retrieved with
#product_addtocart_form": {
"configurable": {
"spConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>
}
}
hasn't data about qty.
I have to retrieve it with custom code or do you have some hints on how to find qty information?
magento2 configurable-product
add a comment |
Someone knows how to get qty for each simple product of configurable product via javascript in product page?
It seems that spConfig
retrieved with
#product_addtocart_form": {
"configurable": {
"spConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>
}
}
hasn't data about qty.
I have to retrieve it with custom code or do you have some hints on how to find qty information?
magento2 configurable-product
add a comment |
Someone knows how to get qty for each simple product of configurable product via javascript in product page?
It seems that spConfig
retrieved with
#product_addtocart_form": {
"configurable": {
"spConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>
}
}
hasn't data about qty.
I have to retrieve it with custom code or do you have some hints on how to find qty information?
magento2 configurable-product
Someone knows how to get qty for each simple product of configurable product via javascript in product page?
It seems that spConfig
retrieved with
#product_addtocart_form": {
"configurable": {
"spConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>
}
}
hasn't data about qty.
I have to retrieve it with custom code or do you have some hints on how to find qty information?
magento2 configurable-product
magento2 configurable-product
edited Jun 6 '16 at 10:31
LucScu
asked Jun 6 '16 at 10:24
LucScuLucScu
1,256929
1,256929
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Thx to @Amit Bera for hints, here my answer.
Override MagentoConfigurableProductModelConfigurableAttributeData
and extends getAttributeOptionsData()
adding qty
field:
/**
* @var \MagentoCatalogInventoryApiStockStateInterface
*/
protected $_stockState;
/**
*
*/
public function __construct(
MagentoCatalogInventoryApiStockStateInterface $stockState
) {
$this->_stockState = $stockState;
}
/**
* @param Attribute $attribute
* @param array $config
* @return array
*/
protected function getAttributeOptionsData($attribute, $config) {
$attributeOptionsData = ;
foreach ($attribute->getOptions() as $attributeOption) {
$optionId = $attributeOption['value_index'];
$attributeOptionsData = [
'id' => $optionId,
'label' => $attributeOption['label'],
'products' => isset($config[$attribute->getAttributeId()][$optionId])
? $config[$attribute->getAttributeId()][$optionId]
: ,
'qty' => isset($config[$attribute->getAttributeId()][$optionId][0])
? $this->_stockState->getStockQty($config[$attribute->getAttributeId()][$optionId][0])
: '',
];
}
return $attributeOptionsData;
}
Now in appcodexxxyyyviewfrontendtemplatesproductviewtypeoptionsconfigurable.phtml
you could retrieve simple product qty with simple js:
var config = <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>;
.....
// loop options config.attributes[attribute_id].options
// for each simple product to obtain:
// Object {id: "231", label: "M", products: ["2089"], qty: 2}
add a comment |
In this case,you need to rewrite class MagentoConfigurableProductHelperData;
then at getOptions() function at
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$StockState = $objectManager->get('MagentoCatalogInventoryApiStockStateInterface');
$options['qty'][$productId]=$StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId());
after $images = $this->getGalleryImages($product);
thx for the hint, have i to instantiate $StockState right?
– LucScu
Jun 6 '16 at 12:13
1
yes, i have call StockStateInterface inter face by using magento.stackexchange.com/questions/97943/…
– Amit Bera♦
Jun 6 '16 at 12:17
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%2f119508%2fhow-to-access-to-configurable-product-stock-qty-via-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thx to @Amit Bera for hints, here my answer.
Override MagentoConfigurableProductModelConfigurableAttributeData
and extends getAttributeOptionsData()
adding qty
field:
/**
* @var \MagentoCatalogInventoryApiStockStateInterface
*/
protected $_stockState;
/**
*
*/
public function __construct(
MagentoCatalogInventoryApiStockStateInterface $stockState
) {
$this->_stockState = $stockState;
}
/**
* @param Attribute $attribute
* @param array $config
* @return array
*/
protected function getAttributeOptionsData($attribute, $config) {
$attributeOptionsData = ;
foreach ($attribute->getOptions() as $attributeOption) {
$optionId = $attributeOption['value_index'];
$attributeOptionsData = [
'id' => $optionId,
'label' => $attributeOption['label'],
'products' => isset($config[$attribute->getAttributeId()][$optionId])
? $config[$attribute->getAttributeId()][$optionId]
: ,
'qty' => isset($config[$attribute->getAttributeId()][$optionId][0])
? $this->_stockState->getStockQty($config[$attribute->getAttributeId()][$optionId][0])
: '',
];
}
return $attributeOptionsData;
}
Now in appcodexxxyyyviewfrontendtemplatesproductviewtypeoptionsconfigurable.phtml
you could retrieve simple product qty with simple js:
var config = <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>;
.....
// loop options config.attributes[attribute_id].options
// for each simple product to obtain:
// Object {id: "231", label: "M", products: ["2089"], qty: 2}
add a comment |
Thx to @Amit Bera for hints, here my answer.
Override MagentoConfigurableProductModelConfigurableAttributeData
and extends getAttributeOptionsData()
adding qty
field:
/**
* @var \MagentoCatalogInventoryApiStockStateInterface
*/
protected $_stockState;
/**
*
*/
public function __construct(
MagentoCatalogInventoryApiStockStateInterface $stockState
) {
$this->_stockState = $stockState;
}
/**
* @param Attribute $attribute
* @param array $config
* @return array
*/
protected function getAttributeOptionsData($attribute, $config) {
$attributeOptionsData = ;
foreach ($attribute->getOptions() as $attributeOption) {
$optionId = $attributeOption['value_index'];
$attributeOptionsData = [
'id' => $optionId,
'label' => $attributeOption['label'],
'products' => isset($config[$attribute->getAttributeId()][$optionId])
? $config[$attribute->getAttributeId()][$optionId]
: ,
'qty' => isset($config[$attribute->getAttributeId()][$optionId][0])
? $this->_stockState->getStockQty($config[$attribute->getAttributeId()][$optionId][0])
: '',
];
}
return $attributeOptionsData;
}
Now in appcodexxxyyyviewfrontendtemplatesproductviewtypeoptionsconfigurable.phtml
you could retrieve simple product qty with simple js:
var config = <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>;
.....
// loop options config.attributes[attribute_id].options
// for each simple product to obtain:
// Object {id: "231", label: "M", products: ["2089"], qty: 2}
add a comment |
Thx to @Amit Bera for hints, here my answer.
Override MagentoConfigurableProductModelConfigurableAttributeData
and extends getAttributeOptionsData()
adding qty
field:
/**
* @var \MagentoCatalogInventoryApiStockStateInterface
*/
protected $_stockState;
/**
*
*/
public function __construct(
MagentoCatalogInventoryApiStockStateInterface $stockState
) {
$this->_stockState = $stockState;
}
/**
* @param Attribute $attribute
* @param array $config
* @return array
*/
protected function getAttributeOptionsData($attribute, $config) {
$attributeOptionsData = ;
foreach ($attribute->getOptions() as $attributeOption) {
$optionId = $attributeOption['value_index'];
$attributeOptionsData = [
'id' => $optionId,
'label' => $attributeOption['label'],
'products' => isset($config[$attribute->getAttributeId()][$optionId])
? $config[$attribute->getAttributeId()][$optionId]
: ,
'qty' => isset($config[$attribute->getAttributeId()][$optionId][0])
? $this->_stockState->getStockQty($config[$attribute->getAttributeId()][$optionId][0])
: '',
];
}
return $attributeOptionsData;
}
Now in appcodexxxyyyviewfrontendtemplatesproductviewtypeoptionsconfigurable.phtml
you could retrieve simple product qty with simple js:
var config = <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>;
.....
// loop options config.attributes[attribute_id].options
// for each simple product to obtain:
// Object {id: "231", label: "M", products: ["2089"], qty: 2}
Thx to @Amit Bera for hints, here my answer.
Override MagentoConfigurableProductModelConfigurableAttributeData
and extends getAttributeOptionsData()
adding qty
field:
/**
* @var \MagentoCatalogInventoryApiStockStateInterface
*/
protected $_stockState;
/**
*
*/
public function __construct(
MagentoCatalogInventoryApiStockStateInterface $stockState
) {
$this->_stockState = $stockState;
}
/**
* @param Attribute $attribute
* @param array $config
* @return array
*/
protected function getAttributeOptionsData($attribute, $config) {
$attributeOptionsData = ;
foreach ($attribute->getOptions() as $attributeOption) {
$optionId = $attributeOption['value_index'];
$attributeOptionsData = [
'id' => $optionId,
'label' => $attributeOption['label'],
'products' => isset($config[$attribute->getAttributeId()][$optionId])
? $config[$attribute->getAttributeId()][$optionId]
: ,
'qty' => isset($config[$attribute->getAttributeId()][$optionId][0])
? $this->_stockState->getStockQty($config[$attribute->getAttributeId()][$optionId][0])
: '',
];
}
return $attributeOptionsData;
}
Now in appcodexxxyyyviewfrontendtemplatesproductviewtypeoptionsconfigurable.phtml
you could retrieve simple product qty with simple js:
var config = <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>;
.....
// loop options config.attributes[attribute_id].options
// for each simple product to obtain:
// Object {id: "231", label: "M", products: ["2089"], qty: 2}
answered Jun 6 '16 at 15:30
LucScuLucScu
1,256929
1,256929
add a comment |
add a comment |
In this case,you need to rewrite class MagentoConfigurableProductHelperData;
then at getOptions() function at
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$StockState = $objectManager->get('MagentoCatalogInventoryApiStockStateInterface');
$options['qty'][$productId]=$StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId());
after $images = $this->getGalleryImages($product);
thx for the hint, have i to instantiate $StockState right?
– LucScu
Jun 6 '16 at 12:13
1
yes, i have call StockStateInterface inter face by using magento.stackexchange.com/questions/97943/…
– Amit Bera♦
Jun 6 '16 at 12:17
add a comment |
In this case,you need to rewrite class MagentoConfigurableProductHelperData;
then at getOptions() function at
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$StockState = $objectManager->get('MagentoCatalogInventoryApiStockStateInterface');
$options['qty'][$productId]=$StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId());
after $images = $this->getGalleryImages($product);
thx for the hint, have i to instantiate $StockState right?
– LucScu
Jun 6 '16 at 12:13
1
yes, i have call StockStateInterface inter face by using magento.stackexchange.com/questions/97943/…
– Amit Bera♦
Jun 6 '16 at 12:17
add a comment |
In this case,you need to rewrite class MagentoConfigurableProductHelperData;
then at getOptions() function at
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$StockState = $objectManager->get('MagentoCatalogInventoryApiStockStateInterface');
$options['qty'][$productId]=$StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId());
after $images = $this->getGalleryImages($product);
In this case,you need to rewrite class MagentoConfigurableProductHelperData;
then at getOptions() function at
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$StockState = $objectManager->get('MagentoCatalogInventoryApiStockStateInterface');
$options['qty'][$productId]=$StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId());
after $images = $this->getGalleryImages($product);
edited 35 mins ago
Teja Bhagavan Kollepara
2,98641847
2,98641847
answered Jun 6 '16 at 10:45
Amit Bera♦Amit Bera
58.9k1475174
58.9k1475174
thx for the hint, have i to instantiate $StockState right?
– LucScu
Jun 6 '16 at 12:13
1
yes, i have call StockStateInterface inter face by using magento.stackexchange.com/questions/97943/…
– Amit Bera♦
Jun 6 '16 at 12:17
add a comment |
thx for the hint, have i to instantiate $StockState right?
– LucScu
Jun 6 '16 at 12:13
1
yes, i have call StockStateInterface inter face by using magento.stackexchange.com/questions/97943/…
– Amit Bera♦
Jun 6 '16 at 12:17
thx for the hint, have i to instantiate $StockState right?
– LucScu
Jun 6 '16 at 12:13
thx for the hint, have i to instantiate $StockState right?
– LucScu
Jun 6 '16 at 12:13
1
1
yes, i have call StockStateInterface inter face by using magento.stackexchange.com/questions/97943/…
– Amit Bera♦
Jun 6 '16 at 12:17
yes, i have call StockStateInterface inter face by using magento.stackexchange.com/questions/97943/…
– Amit Bera♦
Jun 6 '16 at 12:17
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%2f119508%2fhow-to-access-to-configurable-product-stock-qty-via-js%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