Question

I have a magento store where i have used magento advance search on home page. Works fine. In search form there is an attribute (caliber) which is actually a text type attribute but i m showing this attribute as dropdown in fronted (Used custom query to fetch the attribute value of all the product). It's also working fine. I want to show the exact result with this attribute value. Example : if caliber value is 9mm then only this product should show but it rather shows other products whose attribute value is 7mmX39mm since this has 9mm as well. I have changed search type mode from LIKE to FULLTEXT but both of mode are giving same result for me. Any help will be highly appreciated.

Was it helpful?

Solution

I have modified prepareCondition function in advanced.php page

app/code/local/Mage/CatalogSearch/Model/Resource/Advanced.php

Replaced below code

if (strlen($value) > 0) {
if (in_array($attribute->getBackendType(), array('varchar', 'text', 'static'))) {
$condition = array('like' => '%' . $value . '%'); // text search
} else {
$condition = $value;
}
}

BY

if (strlen($value) > 0) {
$condition = $value;
}

I got desire output.Thanks

OTHER TIPS

I'm not 100%, but I'm reasonably sure Magento doesn't have that functionality out of the box. If you wanted it, you'd need to make your attribute a non-text element.

If you're comfortable with custom programming in Magento, the approach I'd take (assuming a modern Magento version) is

  1. Setup an event observer for the catalog_product_collection_load_before

  2. Return early in the event observer method if the full action name isn't catalogsearch_advanced_result (i.e. you're not on the search results page) or there's not a value for caliber in the request

  3. Add an explicit = filter to the collection for the value of caliber

Re: #3, the code looks something like this

$collection->addFieldToFilter('caliber', $value);

Where $value is populated from the request post.

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