VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Coding Central => Topic started by: sandomatyas on March 10, 2022, 09:06:01 AM

Title: Search by id
Post by: sandomatyas on March 10, 2022, 09:06:01 AM
We need to use search by virtuemart_product_id in the admin area a lot, but using 'product_id' in Available Search Fields is not a best method, because searching for ID should return an exact match, not a substring match.
I checkhed core Joomla3 code how it works with core components and based on that I put this code in VirtueMartModelProduct.sortSearchListQuery right before it creates $whereString

if (stripos($this->keyword, 'id:') === 0)
{
$where = ['`p`.virtuemart_product_id='.(int) substr($this->keyword, 3)];
}

It does work, it helps me a lot and I'm sure it's a useful and easy-to-implement function for other users as well.
I'm not sure what keyword should we use here

Could you please consider implementing this?
Title: Re: Search by id
Post by: GJC Web Design on March 10, 2022, 11:00:46 AM
+1 -- would be very useful ...
A lot of VM troubleshooting etc requires quick finding of pids

I like this one:  id: short, universal, uses Joomla-logic
Title: Re: Search by id
Post by: Jörgen on March 10, 2022, 11:34:52 AM
+1 From me to

Jörgen
Title: Re: Search by id
Post by: sandomatyas on March 10, 2022, 13:32:46 PM
I forgot: sure, my solution is a quick one, it's better not to evaluate all of the other fields when you search for an id so maybe an if/else could cut the unneccessary ones
Title: Re: Search by id
Post by: Milbo on April 30, 2022, 23:08:28 PM
Hello Sandomatyas, good news, this was implemented by RuposTel and is part of the vm4 core! Check the news  https://virtuemart.net/news/506-virtuemart-4

:-) I am really happy that we could implement it in the last week before the release. And it just started, we can extend it.