Magento: Get the quantity in cart for a given product

前端 未结 4 642
鱼传尺愫
鱼传尺愫 2021-01-31 06:31

I use this code :

// $items = Mage::getModel(\'checkout/cart\')->getQuote()->getAllItems();
$items = Mage::getSingleton(\'checkout/session\')->getQuote(         


        
4条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 06:55

    you could try:

    $quote = Mage::getSingleton('checkout/session')->getQuote();
    $item = Mage::getModel('sales/quote_item')->getCollection()
                    ->addFieldToFilter('quote_id', $quote->getId())
                    ->addFieldToFilter('product_id', $productId)
                    ->getFirstItem();
    //to get the quantity: $item->getQty();
    

提交回复
热议问题