1

I am trying to look up all orders for a user based on there Phone Number using the API.

I have built an application that uses Web Sockets inside of SugarCRM to do a Popup when a phone call is coming in. The only Data I will have access to at first is a Phone number, so I hope I can look up a user and there orders through the API with just that phone number?

I have done a lot of searching and have not found any examples of looking up orders by phone number through the API.

Does anyone have an idea if this is even possible? Or better how to do it?

1 Answer 1

2

**It seems that it is not possible out of the box. But you can do this. You need to do two things: extend the Magento core API (http://inchoo.net/ecommerce/magento/magento-api-v2/, http://www.magentocommerce.com/api/soap/create_your_own_api.html, http://ctodilemma.com/2013/04/customising-and-extending-the-magento-rest-api/) and get the data that you want:

 $collection = Mage::getModel('sales/order')
                         ->getCollection()
                         ->addFieldToFilter('sfoa.telephone',array('some_phone_number'));
$collection
    ->getSelect()
    ->join(array('sfoa'=>'sales_flat_order_address'),'sfoa.entity_id=main_table.entity_id',array('sfoa.telephone'));

Also please note, that telephone is associated with an order address, not directly with an order, so if you have shipping to multiple addresses you need to take than into account. Another thing to keep in mind is that you have two address records in sales_flat_order_address per order: billing and shipping each with associated telephone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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