Magento - 当库存达到 0 时禁用产品
我一直在尝试找到一个干净的解决方案,以仅显示具有可过滤属性“库存”的产品,即分层导航过滤器“大号”将仅显示当前有大号库存的 T 恤。
我想在加载productCollection之前对此进行过滤,以保持页面加载快速(ish) - 我最近的尝试是尝试在其库存达到0时将项目的状态设置为禁用,以便magento的核心过滤将启动在分层导航结果页面上。
我尝试过的方法都没有成功将状态设置为禁用 - 我应该能够向 CatalogInventory/Model/Stock/Status.php updateStatus() 添加一些内容,对吗?或某处..类似:
/**
* Update product status from stock item
*
* @param int $productId
* @param string $productType
* @param int $websiteId
* @return Mage_CatalogInventory_Model_Stock_Status
*/
public function updateStatus($productId, $productType = null, $websiteId = null)
{
if (is_null($productType)) {
$productType = $this->getProductType($productId);
}
$storeId = Mage::app()->getStore()->getStoreId();
$item = $this->getStockItemModel()->loadByProduct($productId);
$status = self::STATUS_IN_STOCK;
$qty = 0;
if ($item->getId()) {
$status = $item->getIsInStock();
$qty = $item->getQty();
}
if($qty < 1)
Mage::getModel('catalog/product_status')->updateProductStatus($product->getId(), $storeId, Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
else
Mage::getModel('catalog/product_status')->updateProductStatus($product->getId(), $storeId, Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$this->_processChildren($productId, $productType, $qty, $status, $item->getStockId(), $websiteId);
$this->_processParents($productId, $item->getStockId(), $websiteId);
return $this;
}
我已经这样做好几天了,但运气不佳。如果有更优雅的解决方案,我很乐意,
谢谢
I've been trying to get a clean solution to showing only products that have a filterable attribute IN STOCK, ie layered navigation filter Large will only show T-shirts that currently have Large sizes in stock.
I'd like to filter this before the productCollection is loaded, to keep the page loads quick(ish) - my latest venture is to try and set the item's status to disabled when its stock reaches 0, so that magento's core filtering will kick in on the layered navigation results page.
None of the methods i've tried have successfully set the status to disabled - I should be able to add something to CatalogInventory/Model/Stock/Status.php updateStatus() right? or somewhere.. Something like:
/**
* Update product status from stock item
*
* @param int $productId
* @param string $productType
* @param int $websiteId
* @return Mage_CatalogInventory_Model_Stock_Status
*/
public function updateStatus($productId, $productType = null, $websiteId = null)
{
if (is_null($productType)) {
$productType = $this->getProductType($productId);
}
$storeId = Mage::app()->getStore()->getStoreId();
$item = $this->getStockItemModel()->loadByProduct($productId);
$status = self::STATUS_IN_STOCK;
$qty = 0;
if ($item->getId()) {
$status = $item->getIsInStock();
$qty = $item->getQty();
}
if($qty < 1)
Mage::getModel('catalog/product_status')->updateProductStatus($product->getId(), $storeId, Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
else
Mage::getModel('catalog/product_status')->updateProductStatus($product->getId(), $storeId, Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$this->_processChildren($productId, $productType, $qty, $status, $item->getStockId(), $websiteId);
$this->_processParents($productId, $item->getStockId(), $websiteId);
return $this;
}
I've been at this for days and had no luck. If there's a more elegant solution I'm wide open
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论