Searching Orders By B_Firstname Or S_Firstname

Hi, im trying to search orders by Billing or Shipping ( b_firstname or s_firstname ) name. Anyone can point me on the right direction pls.

I add this in orders_serch_form.tpl

My Search

And add a hook with this in func.php (app/addons/my_changes/)

	  if (!empty($params['b_firstname'])) {
		 $condition .= db_quote(" " . (isset($params["compact"]) ? "OR" : "AND") . " (?:orders.b_firstname LIKE ?l)", "%".trim($params['b_firstname'])."%");
	  }

Best Regards

JeMa

The name of the input is S_firstname, but in the function you check by B_firstname

The name of the input is S_firstname, but in the function you check by B_firstname

I just copy the bad line, i have both added eComLabs, S and B

I just copy the bad line, i have both added eComLabs, S and B

Better if you post the full context of the code then maybe someone can help more instead of critique of 'pseudo / snippet code' :)

I just copy the bad line, i have both added eComLabs, S and B

So it does not work? What hook do you use? Post the whole function here

So it does not work? What hook do you use? Post the whole function here

Be careful what you wish for it might turn into Pastebin soon ;-P

Done !

Just in case anyone need it, i Post it here, this is useful to add any order search criteria to your cart.



in app/addons/my_changes/func.php add your search criteria lines, in my case s_firstname and s_lastname

  if (!defined('BOOTSTRAP')) { die('Access denied'); }
function fn_my_changes_create_orders_condition_pre(&$params, $lang_code){
		if (!empty($params['q'])) {
				$params['postcode'] = $params['q'];
// if you would like to add customer's 'company' name to the search query uncomment line below:
			  $params['email2'] = $params['q'];
			  $params['s_firstname'] = $params['q'];
			  $params['s_lastname'] = $params['q'];
		}
}
  function fn_my_changes_get_orders($params, $fields, $sortings, &$condition, $join, $group){
		if (!empty($params['postcode'])) {
				$condition .= db_quote(" " . (isset($params["compact"]) ? "OR" : "AND") . " (0 OR (?:orders.s_zipcode LIKE ?l OR ?:orders.b_zipcode LIKE ?l))", "%".trim($params['postcode'])."%", "%".trim($params['postcode'])."%");
		}
// if you would like to add customer's 'company' name to the search query uncomment lines below:
	  if (!empty($params['pnotes'])) {
		 $condition .= db_quote(" " . (isset($params["compact"]) ? "OR" : "AND") . " (?:orders.pnotes LIKE ?l)", "%".trim($params['pnotes'])."%");
	  }
  // if you would like to add customer's 'company' name to the search query uncomment lines below:
  if (!empty($params['s_firstname'])) {
	 $condition .= db_quote(" " . (isset($params["compact"]) ? "OR" : "AND") . " (?:orders.s_firstname LIKE ?l)", "%".trim($params['s_firstname'])."%");
  }
  
  	  // if you would like to add customer's 'company' name to the search query uncomment lines below:
  if (!empty($params['s_lastname'])) {
	 $condition .= db_quote(" " . (isset($params["compact"]) ? "OR" : "AND") . " (?:orders.s_lastname LIKE ?l)", "%".trim($params['s_lastname'])."%");
  }

Add the search criteria in app/addons/my_changes/schemas/search/sechema.post.php


and to finish, if you want to have the search in sidebar orders panel, add the fields on the template

desings/bakend/templates/views/orders/components/orders_search_form.tpl

{__("first_name")}
{__("last_name")}

Hope it helps anyone.

Best

JeMa

eComLabs, yes buddy, my mistake ! tnx to point me out.

Best

JeMa