Monday, July 16, 2012

Magento get cart / quote info


Magento get cart/ quote info


Method 1)
$cartHelper = Mage::helper('checkout/cart');
$cartQty = $cartHelper->getItemsCount();
$items = $cartHelper->getCart()->getItems();
foreach ($items as $item) {
echo $item->getItemId();

$product = Mage::getModel('catalog/product')->load($item->getProductId());
echo $product->getPublisher();
OR
echo Mage::getModel('catalog/product')->load($_item->getProduct()->getId())->getAttributeText('manufacturer');
}


Method 2)
$cart = Mage::getModel('checkout/cart');
$ids = $cart->getProductIds();
print_r($ids);

Method 3)
$session = Mage::getSingleton('checkout/session');
$output = "";
foreach ($session->getQuote()->getAllItems() as $item) {
$output .= 'id-->'.$item->getProductIds . "
";
$output .= 'id-->'.$item->getItemId() . "
";
$output .= 'sku-->'.$item->getSku() . "
";
$output .= 'name-->'.$item->getName() . "
";
$output .= 'qty-->'.$item->getQty() . "
";
}
print_r($output);