admin 管理员组文章数量: 1086019
I have made this code to show if some configurable product has or not stock. But I can't get the stock quantity anywhere in varien/product.js
updateStock: function(){
var tempProducts = [];
var allowedProducts = [];
var idColor = jQuery('#attribute85').val();
var idTalla = jQuery('#attribute127').val();
// productos por color
var options = this.getAttributeOptions(85);
for (var i = 0; i < options.length; i++ ) {
if (options[i].id == idColor) {
for (var j = 0; j < options[i].products.length; j++) {
tempProducts.push(options[i].products[j]);
}
}
}
jQuery('#input-box-127 a').each(function(index) {
// jQuery(this).find('.talla').removeClass('seleccionado');
jQuery(this).find('div').addClass('sin_stock');
idTalla = jQuery(this).attr('rel');
options = spConfig.getAttributeOptions(127);
for (var i = 0; i < options.length; i++ ) {
if (options[i].id == idTalla) {
for (var j = 0; j < options[i].products.length; j++) {
for (var index = 0; index < tempProducts.length; index++) {
if (tempProducts.indexOf(options[i].products[j]) > -1) {
//alert(jQuery(this).text());
jQuery(this).find('div').removeClass('sin_stock');
}
}
}
}
}
});
return allowedProducts.length > 0;
},
Is there any variable in magento where I can get the configurable product stock?
I have made this code to show if some configurable product has or not stock. But I can't get the stock quantity anywhere in varien/product.js
updateStock: function(){
var tempProducts = [];
var allowedProducts = [];
var idColor = jQuery('#attribute85').val();
var idTalla = jQuery('#attribute127').val();
// productos por color
var options = this.getAttributeOptions(85);
for (var i = 0; i < options.length; i++ ) {
if (options[i].id == idColor) {
for (var j = 0; j < options[i].products.length; j++) {
tempProducts.push(options[i].products[j]);
}
}
}
jQuery('#input-box-127 a').each(function(index) {
// jQuery(this).find('.talla').removeClass('seleccionado');
jQuery(this).find('div').addClass('sin_stock');
idTalla = jQuery(this).attr('rel');
options = spConfig.getAttributeOptions(127);
for (var i = 0; i < options.length; i++ ) {
if (options[i].id == idTalla) {
for (var j = 0; j < options[i].products.length; j++) {
for (var index = 0; index < tempProducts.length; index++) {
if (tempProducts.indexOf(options[i].products[j]) > -1) {
//alert(jQuery(this).text());
jQuery(this).find('div').removeClass('sin_stock');
}
}
}
}
}
});
return allowedProducts.length > 0;
},
Is there any variable in magento where I can get the configurable product stock?
Share Improve this question edited Jul 26, 2012 at 16:59 DaveRandom 88.7k11 gold badges158 silver badges173 bronze badges asked Jul 26, 2012 at 16:34 iVelaiVela 1,2011 gold badge22 silver badges40 bronze badges2 Answers
Reset to default 8You can get sub products list and count all sub product quantities as configurable product's quantity...
$product=Mage::getModel("catalog/product");
$prod=$product->load($prod_id);
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($prod);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$total_qty=0;
foreach($col as $sprod){
$sprod=$product->load($sprod->getId());
$qty = intval(Mage::getModel('cataloginventory/stock_item')->loadByProduct($sprod)->getQty());
$total_qty+=$qty;
}
In Magento there is NO stock level for a configurable product.
Each child product / variation has it's own stock level so you would need to check the stock of the variation currently selected.
本文标签: phpHow can I show configurable product stock quantity in MagentoStack Overflow
版权声明:本文标题:php - How can I show configurable product stock quantity in Magento? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1743989286a2514424.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论