Showing posts with label get cart details. Show all posts
Showing posts with label get cart details. Show all posts

Tuesday, 27 May 2014

Get cart details in Magento

You can get the cart details with the following code

<?php
$cart = Mage::getModel('checkout/cart')->getQuote(); //to get cart detail
foreach ($cart->getAllItems() as $item) {
   echo  $productId = $item->getProduct()->getId(); // product id in cart
   echo $productPrice = $item->getProduct()->getPrice(); // product price in cart
$product = Mage::getModel('catalog/product')->load($productId); // load product to get all details of product
//load the categories of this product
$categoryCollection = $product->getCategoryCollection();
$catIds = $product->getCategoryIds(); // to get all category ids of products in cart
$catCollection = Mage::getResourceModel('catalog/category_collection')  // to get all all details of categories of products in cart
                     //->addAttributeToSelect('name')
                     //->addAttributeToSelect('url')
                     ->addAttributeToSelect('*')
                     ->addAttributeToFilter('entity_id', $catIds)
                     ->addIsActiveFilter();

foreach($catCollection as $cat){
 // print_r($cat->getData());
 $catname[] =  $cat->getName();
  //echo $cat->getUrl();
}

}
print_r($catname); //category names array
?>