Snippets with the tag: singleton

Count items in the cart

Description

How many items are in the cart? The code displays the answer.

Code

Mage::getSingleton('checkout/cart')->getSummaryQty();

Check if customer is logged in

Description

Check if customer is logged in.

Code

Mage::getSingleton('customer/session')->isLoggedIn()

Total items added in cart

Description

Total items added in cart

Code

Mage::getModel('checkout/cart')->getQuote()->getItemsCount();
Mage::getSingleton('checkout/session')->getQuote()->getItemsCount();

Total quantity added in cart

Description

Total quantity added in cart

Code

Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
Mage::getSingleton('checkout/session')->getQuote()->getItemsQty();

Get products data in cart

Description

Display products data in cart

Code

$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();

foreach($items as $item) {
        echo 'ID: '.$item->getProductId().'<br />';
        echo 'Name: '.$item->getName().'<br />';
        echo 'Sku: '.$item->getSku().'<br />';
        echo 'Quantity: '.$item->getQty().'<br />';
        echo 'Price: '.$item->getPrice().'<br />';
        echo "<br />";
}

Get order information on success page

Description

Get order information on success.phtml

Code

$_customerId = Mage::getSingleton('customer/session')->getCustomerId();
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);
$_totalData =$order->getData();
$_grand = $_totalData['grand_total'];