Page 1 of 2

[MOD] Admin>Orders>Search : On product Name or SKU

Posted: Wed Jul 28, 2010 10:58 pm
by Martin
This mod allows you to search your orders using:
  • Product SKU (full or part of it)
  • Product name (full or part of it)
It does add some extra load to the SQL calls so you will want to be careful about stressing the system too much with multiple searches but it does make searches for things like "who bought which product when" a possibility.


Version 5.0.6 - 5.5.x (tested)

Open: /admin/includes/classes/class.orders.php

Find:

Code: Select all

			// Return an array containing details about orders.
			$query = sprintf("
Before, Add:

Code: Select all

//MOD Search using SKU or product name 		
			$extraJoins .= " LEFT JOIN [|PREFIX|]order_products sp ON (o.orderid=sp.orderorderid)";
//MOD END Search using SKU or product name

Find:

Code: Select all

SELECT %so.*, c.*, s.statusdesc AS ordstatustext, CONCAT(custconfirstname, ' ', custconlastname) AS custname,
Replace with

Code: Select all

SELECT %s DISTINCT o.orderid, o.*, c.*, s.statusdesc AS ordstatustext, CONCAT(custconfirstname, ' ', custconlastname) AS custname,

Find:

Code: Select all

$countQuery = "SELECT COUNT(o.orderid) FROM [|PREFIX|]orders o";
Replace with

Code: Select all

$countQuery = "SELECT COUNT(DISTINCT o.orderid) FROM [|PREFIX|]orders o";


Find:

Code: Select all

					OR ordshipzip      LIKE '%".$search_query."%'
					OR ordshipcountry  LIKE '%".$search_query."%'
				) ";
Replace with:

Code: Select all

					OR ordshipzip      LIKE '%".$search_query."%'
					OR ordshipcountry  LIKE '%".$search_query."%'
				";
//MOD Search using SKU or product name 				
//				) ";
				
				$queryWhere .= "
					OR ordprodsku      LIKE '%".$search_query."%'
					OR ordprodname     LIKE '%".$search_query."%'
				) "; 
			
//MOD END Search using SKU or product name

Re: [MOD] Admin>Orders>Search : On product Name or SKU

Posted: Thu Jul 29, 2010 9:39 am
by Tony Barnes
:D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D

Gold star for this one mate, one I'd meant to have a proper look into many times, but never got round to!!

Re: [MOD] Admin>Orders>Search : On product Name or SKU

Posted: Thu Jul 29, 2010 12:35 pm
by Martin
Version 1.0.2 fixes multiple copies of the same order.

Note: Full modification has been updated to include this fix.

Open: /admin/includes/classes/class.orders.php

Find:

Code: Select all

SELECT %so.*, c.*, s.statusdesc AS ordstatustext, CONCAT(custconfirstname, ' ', custconlastname) AS custname,
Replace with

Code: Select all

SELECT %s DISTINCT o.orderid, o.*, c.*, s.statusdesc AS ordstatustext, CONCAT(custconfirstname, ' ', custconlastname) AS custname,

Find:

Code: Select all

$countQuery = "SELECT COUNT(o.orderid) FROM [|PREFIX|]orders o";
Replace with

Code: Select all

$countQuery = "SELECT COUNT(DISTINCT o.orderid) FROM [|PREFIX|]orders o";

Re: [MOD] Admin>Orders>Search : On product Name or SKU

Posted: Thu Jul 29, 2010 2:28 pm
by Tony Barnes
Funnily I was just looking at orders from a single customer and it was pulling up lots of repeats, glad this was fixed so quickly!

Re: [MOD] Admin>Orders>Search : On product Name or SKU

Posted: Thu Jul 29, 2010 2:48 pm
by Martin
Tony Barnes wrote:Funnily I was just looking at orders from a single customer and it was pulling up lots of repeats, glad this was fixed so quickly!
Sorry... I was forgetting this was an Interspire product... I'll add some more bugs in now to help attenuate the shock... :|


:lol:

Re: [MOD] Admin>Orders>Search : On product Name or SKU

Posted: Thu Jul 29, 2010 7:51 pm
by CharlieFoxtrot
Martin wrote: I'll add some more bugs in now to help attenuate the shock...
Then you can sit back, relax, and ignore everyone for 6 months.

Re: [MOD] Admin>Orders>Search : On product Name or SKU

Posted: Thu Jul 29, 2010 8:55 pm
by Tony Barnes
lol, if you can get it so that it randomly doesn't work on occassion, just a weird error message pop up, that would be great :o :D

Re: [MOD] Admin>Orders>Search : On product Name or SKU

Posted: Thu Jul 29, 2010 8:59 pm
by CharlieFoxtrot
Tony Barnes wrote:lol, if you can get it so that it randomly doesn't work on occassion, just a weird error message pop up, that would be great :o :D
Must be a generic message. Something that gives no clue as to cause of the error. "Something went wrong."

(And make sure it's one of those errors that never shows up in the logs.)

Re: [MOD] Admin>Orders>Search : On product Name or SKU

Posted: Fri Jul 30, 2010 12:03 pm
by Tony Barnes
lol!

Re: [MOD] Admin>Orders>Search : On product Name or SKU

Posted: Fri Oct 15, 2010 12:59 pm
by grantg
Tried to apply this to 6.0.14 - the original code is the same, however, no extra functionality is added to the search when this hack is applied (ie. you cannot search for products ordered, only customers details as default). Shame :(
I tell a lie...the ordshipzip step is not the same, as the shipping calls have been removed from class.orders.php due to this single/multiple shipments malarky.

Now, I suspect, if I hunt down where these calls are made, I can edit that file...soon find out!