我试图按类别获取用户购物车中的商品数量。任何帮助都必须得到赞赏。
答案 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();
}
}