0

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.

3

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

1

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.

2
  • thank you for your effort. I have fixed the issue in another way. Aug 6 '13 at 5:45
  • 1
    @monojitbanik It's good form to add your solution if you asked the question and solved it yourself.
    – Alan Storm
    Aug 6 '13 at 5:45

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.