Saturday, 20 October 2012

How to get all products of cart magento

Here, I will show you how to get all shopping cart items and total in Magento Shopping Cart.
 - Get products id, name, price, quantity, etc. present in your cart.
- Get number of items in cart and total quantity in cart.
- Get base total price and grand total price of items in cart.

view plaincopy to clipboardprint?

     $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems(); 
     foreach($items as $item) { 
        echo 'Product ID: '.$item->getProductId().'<br>'; 
        echo 'Product Name: '.$item->getName().'<br>'; 
        echo 'Product Sku: '.$item->getSku().'<br>'; 
        echo 'Product Quantity: '.$item->getQty().'<br>'; 
        echo 'Product Price: '.$item->getPrice().'<br>'; 
     
    if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): 
        $_incl = $this->helper('checkout')->getPriceInclTax($item); 
        echo 'Product Price: '. $this->helper('checkout')->formatPrice($_incl- $item->getWeeeTaxDisposition()); 
    else: 
        echo 'Product Price: '. $magento_style_price = Mage::helper('core')->currency($item->getPrice()); 
    endif; 
       echo "<br>"; 
     } 
     
    // Total items added in cart 
    $totalItems = Mage::getModel('checkout/cart')->getQuote()->getItemsCount(); 
     
    // Total Quantity added in cart 
    $totalQuantity = Mage::getModel('checkout/cart')->getQuote()->getItemsQty(); 
     
    // Sub Total for item added in cart 
    $subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal(); 
     
    //grand total for for item added in cart 
    $grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal(); 

No comments:

Post a Comment