僞代碼(假設你正試圖顯示每個項目多少股票有)
$category_id = 1;
$category = Mage::getModel('catalog/category')->load($category_id);
$totalStockLevel = 0;
// get all product within that category
$productCollection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category);
foreach($productCollection as $product){
// load stock
$stockLevel = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()
// do you logics here
$totalStockLevel += $stockLevel;
}
echo $totalStockLevel;
要獲得所有類別看http://www.magentocommerce.com/boards/viewthread/24947/
見http://www.magentocommerce.com/boards/viewthread/196846/#t247851
有趣的問題......如果你在每個類別中都有一些產品,應該顯示哪種庫存水平(最少,最少的產品)? – pzirkind