-1

我正在尝试按每个类别获取用户购物车中的商品数量。任何帮助将不胜感激。

4

1 回答 1

0

看一下@Magento:每个订单限制类别中的 3 个产品

.....
$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();
      }
}
于 2013-04-08T22:28:12.567 回答