Reputation: 51
I'm going to Magento->Sales->Orders and try to search for full name (Name Surname) on 'Bill to' input and get no results. But if I search just for name (Name) I get results. if I going to Magento->Customers->Manage Customers and trying to search using full name all works correctly.
Where this search implemented? What's the problem?
Upvotes: 2
Views: 1589
Reputation: 1
This is only for grid but it seems to do what I want.
protected function searchWithDoubleSpace($collection, $column)
{
if(!$value = trim($column->getFilter()->getValue()))
{
return $this;
}
//if there was a space input
elseif(preg_match('/ /', $value))
{
$revisedValue = str_replace(' ', ' ', $value); // replace a space with double space
$this->getCollection()->addAttributeToFilter($column->getData('index'), array(
array('like' => '%' . $value . '%'),
array('like' => '%' . $revisedValue.'%'))
); // search with both queries and includes results from both queries (OR)
}
else
{
$this->getCollection()->addAttributeToFilter($column->getData('index'), array('like' => '%'.$value.'%'));
}
return $this;
}
If there is a space input, creates two queries one as is and other with double space in place of single space. Finally get results from both queries.
Also, don't forget to add this piece of code in the column
'filter_condition_callback' => array($this, 'searchWithDoubleSpace')
Upvotes: 0
Reputation: 51
Here's the solution with correct rewrite and script for updating existing records in DB:
Upvotes: 1
Reputation: 5118
I've spotted this before.
If you try a search for name + surname in the Bill to / Ship to order grid, you need to put a double space in between the first name and surname, ie:
NOT:
John Smith
Try this:
John Smith
Only difference is the double space between the names. I haven't looked, but I imagine Magento concatenates the names in the grid either with a double space, or it looks for a middle name and if isn't present, outputs a space instead.
Weird, I know!
Upvotes: 4