-1

我已经在互联网上搜索了 3 次,但仍然一无所获。我只是想编写一些逻辑来显示每个类别以及每个类别有多少库存。如果有哪位聪明的人可以对这个棘手的问题有所了解,请随意回答。

4

1 回答 1

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

于 2012-11-12T16:59:31.937 回答