Hello Developers,
When I was started working in magento. i found so many problem in custom development in
magento. i tried so many times for google those things. When you are working with customer module
then you need to know everything about magento customer collection.
so here today i will tell you everything about magento customer address collection.
here i will tell you how to get all address of magento customer. you can play with magento address
collection.
Here is code to get cutomer all address. using dump you can check what is in your customer session collection.
$customer = Mage::getSingleton(‘customer/session’)->getCustomer();
foreach ($customer->getAddresses() as $address) {
Zend_Debug::dump($address->debug());
}
Now using same collection you can get only valuable or required information by using
those ways.
First Way
/pre>
<?php echo $address->getFirstname(); ?>
there is also another method
<?php echo $address->getData('firstname); ?>
You can check my another post on magento for all way to get value for attribute.
so finally to get all address value here is code
$customer = Mage::getSingleton('customer/session')->getCustomer();
foreach ($customer->getAddresses() as $address) {
echo $address->getFirstname();
echo $address->getLastname();
echo $address->getCompany();
echo $address->getStreet();
echo $address->getCity();
echo $address->getTelephone();
echo $address->getPostcode();
}
If you want to get only customer deaulft billing address then use this code.
$customer -> getDefaultShippingAddress();
and
$customer -> getPrimaryShippingAddress();
Thank You for visitng and reading my tutorial. if you face any problem in implementing
this code into your website.
Ask your queries on website or comment. i will give you solution.
Thank You
Magento Experts , Hire Us