Magento Forum

A to Z Filter on Custom Search
 
Chris Shennan
Jr. Member
 
Total Posts:  11
Joined:  2009-05-06
 

Hi,

I’ve build a custom search module so that I can restrict the results for the custom search (using http://inchoo.net/ecommerce/magento/advanced-search-in-magento-and-how-to-use-it-in-your-own-way/) to a specific subset of products which works fine. 

Now I need to add a new filter which lists the letters A to Z as hyperlinks and which will only bring back products within the subset which start with the selected letter.

Currently, I have

$filters["name""A";
Mage::getSingleton('catalogsearch/advanced')->addFilters($filters);

This seems to bring back any product with the letter A anywhere in the name i.e.

Audi - Matched
Vauxhall - Matched

but I need it bring back only those which start with A i.e.

Audi - Matched
Vauxhall - Not Matched.

Does anyone know how to achieve this?

Many Thanks.

Chris.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Chris Shennan
Jr. Member
 
Total Posts:  11
Joined:  2009-05-06
 

This is probably not a good method but I’ve had to edit the /app/code/core/Mage/CatatogSearch/Model/Advanced.php file and the following conditional statement to the bottom of the foreach ($attributes as $attribute) loop.

// ADD IN ADDITIONAL FUNCTIONALITY TO FILTER BY LETTER
if($code == "name")
{
    
// CHECK TO SEE IF THE LETTER ATTRIBUTE IS PASSED
    
if(array_key_exists("letter"$values))
    
{
        
// IF THE LETTER EXISTS
                
$letter trim($values["letter"]);
                if(
strlen($letter)  > 0)
                
{
                    
// ADD TO THE CRITERIA
                    
$table $attribute->getBackend()->getTable();
                    
$attributeId $attribute->getId();
                    
$condition = array('like'=>"{$letter}%");
                
}
    }
}
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top