Magento News
Magento – disable product when stock reaches 0
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
Magento – disable product when stock reaches 0
Possibly Related Posts:
- Database query different results
- Menu highlight in magento under admin
- magento disable a banner on certain category pages or have a banner with multiple links
- Magento, using ACL for frontend. Possible?
- Magento IE-7 Fix In Windows XP
RSS Feed