1

I want to add in Advanced Search possibility to search products by many sku-s. How to do it ?

In query it look like

sku=code&...

I want it to look like

sku=code,code,code$

or

sku=code;code;code&
2

Whether you are using an Ajax search or just the basic Magento search, you want to override the CatalogSearch AjaxController.php or ResultController.php . This way, it'll allow you to better manipulate the data you are receiving by getting the sku param like this :

$skus = $this->getRequest()->getParam('sku');

and then, build an array of conditions out of your sku's:

foreach (explode(',', $skus) as $sku)
{
    $filters[] = array('attribute'=>'sku', 'like'=>'%'.$sku.'%');
}

when getting your product collection, you can use the previous filter like this:

$yourCollection->addAttributeToFilter($filters);

Then you should be good, hope this helps.

  • Rather than splitting on comma, you could use querystring array syntax: ?sku[]=1&sku[]=2&sku[]=3 – philwinkle Mar 6 '14 at 16:48
  • well that could be a good idea but that was not what the OP asked, he asked for a way for the user to type comma-separated or semi-column-separated string to be parsed by the CatalogSearch controller as multiple sku's. Doing as you suggested would mean modifying the GET parameters with some JS after the user has type some comma-separated string in the search field. – Julien Lachal Mar 12 '14 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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