November Happy Hour will be moved to Thursday December 5th.

How-to do a Order search on a metafield value?

Vote:
 

Let's say we want to track from which ip address an order was submitted, and we want to be able to search for other orders from same ip address. How can we accomplish this?

#59764
Jun 27, 2012 8:13
Vote:
 

I have not tested this but I think you would have to create a new "IpAdress" metafield and expand the PurchaseOrder meta class with the field. Then make sure the field is filled during checkout.

After that you should be able to make a search more or less like this:

OrderSearchParameters parameters = new OrderSearchParameters();
OrderSearchOptions options = new OrderSearchOptions();

options.RecordsToRetrieve = 100;
options.StartingRecord = 0;
options.Classes.Add("MyMetaClassName");

parameters.SqlMetaWhereClause = string.Format("META.{0} = '127.0.0.1'", "IpAdresssMetaField");

int totalRecords;

var orders = OrderContext.Current.FindPurchaseOrders(parameters, options, out totalRecords);

 

#59774
Jun 27, 2012 12:52
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.