[英]Show stock of configurable products on Magento 1.9
I'm new on Magento and I have problems to show stock of configurable product. 我是Magento的新手,我无法显示可配置产品的库存。 I have tried a lot of things that I found on Google, Stackoverflow, Magento Forums, but I failed.
我已经尝试了很多在Google,Stackoverflow,Magento论坛上发现的东西,但是失败了。 Here is the only solution that I cannot try:
这是我无法尝试的唯一解决方案:
$_product is your configurable product.
$ _product是您可配置的产品。
To get all its simple use :
为了获得所有简单的用法:
$_product->getTypeInstance(true)->getUsedProducts ( null, $_product);
$ _product-> getTypeInstance(true)-> getUsedProducts(null,$ _product);
So you might have something like :
因此,您可能会遇到类似:
foreach ($_product->getTypeInstance(true)->getUsedProducts ( null, $_product) as $simple) { $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($simple)->getQty();
foreach($ _product-> getTypeInstance(true)-> getUsedProducts(null,$ _product)as $ simple){$ stock = Mage :: getModel('cataloginventory / stock_item')-> loadByProduct($ simple)-> getQty() ; echo $simple->getName()." with size ".$simple->getSize()." have a stock of $stock";
echo $ simple-> getName()。“,大小为”。$ simple-> getSize()。“,存有$ stock”。 echo '
回声
';'; } I let you adapt to your precise needs and ask question if needed
}我让您适应自己的确切需求,并在需要时提出问题
My problem is: I don't know where I can apply this solution! 我的问题是:我不知道在哪里可以应用此解决方案!
()
()
You need to perform two step to get this working however I have checked this with version 1.8 but hope it will work in your case also 您需要执行两个步骤才能使此工作正常运行,但是我已经在1.8版中进行了检查,但希望它也能在您的情况下工作
step 1. copy file app/code/core/mage/catalog/block/product/view/type/configurable.php 步骤1.复制文件app / code / core / mage / catalog / block / product / view / type / configurable.php
And create a folder under app/code/local with same directory structure mage/catalog/block/product/view/type/configurable.php 并在app / code / local下创建一个具有相同目录结构的文件夹mage / catalog / block / product / view / type / configurable.php
Now find function name getJsonConfig in configuration.php file. 现在,在configuration.php文件中找到函数名称getJsonConfig。
Go to following code 转到以下代码
$info['options'][] = array( 'id' => $value['value_index'], 'label' => $value['label'], 'price' => $configurablePrice, 'oldPrice' => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']), 'products' => $productsIndex, );
Before this code place below two lines of code 在此代码之前放置在两行代码下方
$simpleproduct = Mage::getModel('catalog/product')->load($productsIndex); $qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty();
Here you can see that i'm getting product stock by product id, now in info option array code you have to add one parameter 在这里您可以看到我正在按产品ID获取产品库存,现在在信息选项数组代码中,您必须添加一个参数
$info['options'][] = array( 'id' => $value['value_index'], 'label' => $value['label'], 'price' => $configurablePrice, 'oldPrice' => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']), 'products' => $productsIndex, 'qty' => $qty, // we are sending stock parameter so we can use it latter in drop down field );
step 2. Now go js/varian/configuration.js 第2步。现在去js / varian / configuration.js
find the following line 找到以下行
if(allowedProducts.size()>0){ options[i].allowedProducts = allowedProducts; element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id);
Place following line under this 在此下方放置以下行
element.options[index].innerHTML += " Stock is :"+options[i].qty;
that's it all about cheer 这就是欢呼的全部
Let me know if you have any query 让我知道您是否有任何疑问
with app/code/local/Mage/Catalog/Block/Product/View/Type/Configurable.php 与应用程序/代码/本地/法师/目录/块/产品/视图/类型/Configurable.php
$simpleproduct = Mage::getModel('catalog/product')->load($productsIndex);
$qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty();
$info['options'][] = array(
'id' => $value['value_index'],
'label' => $value['label'],
'price' => $configurablePrice,
'oldPrice' => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']),
'products' => $productsIndex,
'qty' => $qty, // we are sending stock parameter so we can use it latter in drop down field
);
$optionPrices[] = $configurablePrice;
}
}
and at js/varien/configurable.js 并在js / varien / configurable.js
if(allowedProducts.size()>0){
options[i].allowedProducts = allowedProducts;
element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id);
if (typeof options[i].price != 'undefined') {
element.options[index].setAttribute('price', options[i].price);
}
element.options[index].innerHTML += " Stock is :"+options[i].qty;
element.options[index].config = options[i];
index++;
}
isn't working at 1.9.4... is it something wrong? 不是在1.9.4下工作...有什么问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.