Home    Articles

 

How to get customer address in magento checkout onepage

 

Here i will show you how to get the customer address.

In order to get the magento customer details when he is on the chechout page this code may help you.
It is a good ideea to get all the data into 1 array, like this:
By getting the shipping address you can calculate the shipping cost or anything you need.
To be able to use this code you need an observer that will call this code from checkout page.

$customerData= array('company'=>Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getCompany(),
	             'firstname'=>Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getFirstname(),
	    	     'lastname'=>Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getLastname(),
	    	     'street' =>Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getStreet(), 
	    	     'postcode'=>Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getPostcode(),
	    	     'city'=>Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getCity(),
	    	     'telephone'=>Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getTelephone()
		   );

If you want to get the billing address that is typed in the checkout page with all it’s data you can use this:

$billingAddress = Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress()->getData();

If you want to see what the method above will print…

Array
        (
            ....lot of data here 
            [msrp_amount] => 0
            [base_msrp_amount] => 0
            [freeshipping_amount] => 0
            [base_freeshipping_amount] => 0
            [weee_amount] => 0
            [base_weee_amount] => 0
            [free_method_weight] => 0
            [tax_shipping_amount] => 0
            [base_tax_shipping_amount] => 0
            [shipping_taxable] => 0
            [base_shipping_taxable] => 0
            [is_shipping_incl_tax] => 
        )

I’ve tried to use the same method for the shipping address but it didn’t worked, i don’t know why.

If there is no shipping method to get , the magento will use the billing address for the checkout process.

We will show you in the another tutorial how to get the customer shipping method and the payment method.

…first time posted on w3bdeveloper.com

by