1

I want search shipping address by customer name, company, city or postcode. Please help me

This my code, but it get double, it gte shipping and billing address, i want get only shipping address.

$addressCollection = Mage::getModel('sales/order_address')->getCollection();
$addressCollection->getSelect()->where("lastname like '%$customerName%' and company like '%$customerCompany%' and city like '%$customerCity%' and postcode like '%$customerCode%'");
var_dump($addressCollection->getData());exit;

UPDATE

I follow answer and it show error

Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lastname like '%Nhân%' and company like '%%' and city like '%%' and postcode li' at line 1, query was: SELECT `main_table`.* FROM `sales_flat_order_address` AS `main_table` WHERE (address_type = 'shipping' lastname like '%Nhân%' and company like '%%' and city like '%%' and postcode like '%%')";
1

You want to just add "address_type" condition into your above code like this one.

$addressCollection = Mage::getModel('sales/order_address')
->getCollection()
->addFieldToFilter('address_type','shipping');
$addressCollection->getSelect()->where("lastname like '%$customerName%' and company like '%$customerCompany%' and city like '%$customerCity%' and postcode like '%$customerCode%'");
var_dump($addressCollection->getData());
exit;
  • it show error, please check update question – TN98 Oct 3 at 5:51
  • I update the answer Kindly check. – Dhiren Vasoya Oct 3 at 6:14
  • Thank you, can u help me a proplem? how to get only shipping address in storeId = 1 ? – TN98 Oct 3 at 6:35
  • you want list by store specific? – Dhiren Vasoya Oct 3 at 6:37
  • yes, i want like this – TN98 Oct 3 at 6:38
2
$customerName = "Nhân";
$customerCity = "";
$customerCompany = "";
$customerCode = "";

$addressCollection = Mage::getModel('sales/order_address')->getCollection();
$addressCollection->getSelect()->where("lastname like '%$customerName%' and company like '%$customerCompany%' and city like '%$customerCity%' and postcode like '%$customerCode%' and address_type= 'shipping' ");

//echo "SELECT `main_table`.* FROM `sales_flat_order_address` AS `main_table` WHERE (lastname like '%Nhân%' and company like '%%' and city like '%%' and postcode like '%%' and address_type= 'shipping' )";

echo $addressCollection->getSelect();
var_dump($addressCollection->getData());exit;

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.