Magento按类别获得购物车中的商品数量

时间:2013-04-08 22:00:03

标签: magento

我试图按类别获取用户购物车中的商品数量。任何帮助都必须得到赞赏。

1 个答案:

答案 0 :(得分:0)

看看@ Magento: limit 3 products from category per order

.....
$quote = Mage::getSingleton('checkout/session')->getQuote();
foreach($quote->getAllVisibleItems() as $item){
      $product = Mage::getModel('catalog/product')->load($item->getId());
      $product_category_ids = explode(",", $product->getCategoryIds());
      //$product_category_ids = $product->getCategoryIds();

      foreach($product_category_ids as $category_id){
           $category_ids[$category_id]['category_id'] = $category_id;
           $category_ids[$category_id]['product_count'] = ($category_ids[$category_id]['product_count']) ? $category_ids[$category_id]['product_count'] + $item->getQty() : $item->getQty();
      }
}