$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());
else:
echo 'Product Price: '. $final_price= Mage::helper('core')->currency($item->getPrice());
endif;
}
// 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();
Get All Items & Totals In Magento Shopping Cart
6 comments:
-
This Code is Very Nice But I need Mage::getSingleton('checkout/session')->getQuote()->setStoreId()->getAllItems(); So, Possible...?
-
In my below code return only returns 'qty' of each products and if do echo then it prints all things but in end it prints null aslo. Do you have any idea how can print all details in json file for rest calls.
Mage::app()->setCurrentStore(4);
$cart = Mage::getModel('sales/quote')->loadByCustomer($this->getApiUser()->getUserId());
$items = array();
foreach ($cart->getAllVisibleItems() as $key => $item) {
$items[] = array(
'name' => $item->getName(),
'entity_id' => $item->getProductId(),
'description' => $item->getDescription(),
'final_price_with_tax' => $item->getBasePriceInclTax(),
'qty' => $item->getQty()
);
}
return $items;
very good article.well done