Saturday, November 26, 2011

How to get all shopping cart items and total in magento

Here, I will show you how you can get  all shopping cart items and total in magento. Magento has a the feature to create rules in the Shopping Cart. fallow below steps.

     $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();  
     foreach($items as $item) {  
        echo 'Product ID: '.$item->getProductId().'';  
        echo 'Product Name: '.$item->getName().'';  
        echo 'Product Sku: '.$item->getSku().'';  
        echo 'Product Quantity: '.$item->getQty().'';  
        echo 'Product Price: '.$item->getPrice().'';  
    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());  
        echo 'Product Price: '. $magento_style_price = Mage::helper('core')->currency($item->getPrice());  
       echo "";  
    // 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: