0

I want get shipping address of customer by name, city, company, or postcode. How to do it? Please help me.

I tryed this code but it get shipping address of all order.

$addressCollection = Mage::getModel('sales/order_address')->getCollection();
$addressCollection->getSelect()->where("address_type = 'shipping' and lastname like '%$customerName%' and company like '%$customerCompany%' and city like '%$customerCity%' and postcode like '%$customerCode%'");
  • where you want this shipping address ? I mean at which location? – Hassan Ali Shahzad Oct 4 at 8:18
  • shipping/billing address is associated with order or quote thats why I want to confirm where you want this ? – Hassan Ali Shahzad Oct 4 at 8:20
  • i want get all shipping address of customer – TN98 Oct 4 at 8:20
  • i think i sshould get in customer/address, but i can't get data like sales/order_address – TN98 Oct 4 at 8:21
  • DO you have customers id ? – Hassan Ali Shahzad Oct 4 at 8:24
0

If you have customer object like following:

$customer = Mage::getModel('customer/customer')->load($customerId);

Then just use the following code to get your desired address:

Primary Billing Address: $customer->getPrimaryBillingAddress();
Primary Shipping Address: $customer->getPrimaryShippingAddress();
General Address Selection: $customer->getAddressItemById();
  • Thanks, but i need search shipping address of customer by name, company, city, postcode, i haven't customer id – TN98 Oct 4 at 8:28
  • Ok I will update my answer for your scenarios as well. – Hassan Ali Shahzad Oct 4 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.