Snippets with the tag: session

Check if shipping methods are available

Description

function to know that there is any shipping method available

Code

public function haveShippingMethods()
{
	if (count(Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingRatesCollection())) {
		return true;
	}
	return false;
}

Array of billing and shipping addresses

Description

use this code to get an array of billing address and shipping address

Code

$all_data = array();
$customer = Mage::getModel(‘customer/session’)->getCustomer();
foreach($customer->getAddressesCollection() as $customer_address)
{
$all_data[] = $customer_address;
}
var_dump($all_data);

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'];