我已经在互联网上搜索了3次,但仍然没有。我只想写一些逻辑,它将显示每个类别以及每个类别可用的库存量。如果有聪明的人可以解决这个棘手的问题,请随意回答。
答案 0 :(得分:3)
伪代码(假设您试图显示每件商品的库存量)
$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