How I can filter orders collection by customer phone number? Here is my try:
$orders = Mage::getModel('sales/order')->getCollection()
->addAttributeToFilter('customer_phone', array('like' => '%' . $_POST['filter_client_phone'] . '%'))->load();
Also how I can filter orders collection by some attribute from shipping information of the order?
Try this:
Mage::getModel('sales/order')
->getCollection()
->addAddressFields()
->addAttributeToFilter('billing_telephone', $_POST['filter_client_phone'])
Note : use shipping_telephone
If you want to filter with shipping address telephone.
You may filter orders collection by using below query $addressTable=Mage::getSingleton("core/resource")->getTableName("sales/order_address"); $orders = Mage::getModel('sales/order')->getCollection(); $select=$orders->getSelect()->joinLeft(array('oa'=>$addressTable),'oa.parent_id=main_table.entity_id') ->where('oa.address_type=?','shipping') ->where('oa.telephone LIKE ?','%' . $_POST['filter_client_phone'] . '%');
$addressTable=Mage::getSingleton("core/resource")->getTableName("sales/order_address"); $orders = Mage::getModel('sales/order')->getCollection(); $select=$orders->getSelect()->joinLeft(array('oa'=>$addressTable),'oa.parent_id=main_table.entity_id') ->where('oa.address_type=?','shipping') ->where('oa.telephone LIKE ?','%' . $_POST['filter_client_phone'] . '%');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.