Question

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&
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top