genix Posted June 22, 2012 Share Posted June 22, 2012 Hello, I encountered a problem, when I tried to associate each product attribute with an unique reference. When I tried to search for this reference, the product wouldn't show up in the search result. So I looked a bit into the prestashop search code, and could fix this problem with some simple modifications in "classes/Search.php". How to fix: Search for "public static function getAttributes" in "classes/Search.php" and replace the whole function with the following code: public static function getAttributes($db, $id_product, $id_lang) { $attributes = ''; $attributesArray = $db->ExecuteS(' SELECT al.name, pa.reference FROM '._DB_PREFIX_.'product_attribute pa INNER JOIN '._DB_PREFIX_.'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute INNER JOIN '._DB_PREFIX_.'attribute_lang al ON (pac.id_attribute = al.id_attribute AND al.id_lang = '.(int)$id_lang.') WHERE pa.id_product = '.(int)$id_product); foreach ($attributesArray AS $attribute) $attributes .= $attribute['name'].' '.($attribute['reference'] != "" ? $attribute['reference'].' ' : ''); return $attributes; } Now just reindex the products in the search configuration panel. Regards, genix. 4 Link to comment Share on other sites More sharing options...
Mike Kranzler Posted June 22, 2012 Share Posted June 22, 2012 Thanks for this contribution genix! We would love to have you submit this to the Forge as an Improvement here so that our development team can look into potentially integrating it into a future release. -Mike Link to comment Share on other sites More sharing options...
genix Posted June 22, 2012 Author Share Posted June 22, 2012 (edited) Done. (#PSCFI-5969) Edited June 22, 2012 by genix (see edit history) Link to comment Share on other sites More sharing options...
Mike Kranzler Posted June 22, 2012 Share Posted June 22, 2012 Done. Thanks! Link to comment Share on other sites More sharing options...
Bill Dalton Posted June 23, 2012 Share Posted June 23, 2012 I'm using 1.4.7.3 and I didn't even have function getAttributes This made a fantastic difference. I can now search for red tops and only tops that are available in red show in the results. Thank you for sharing. Link to comment Share on other sites More sharing options...
JAKCRABBIT Posted August 14, 2012 Share Posted August 14, 2012 (edited) 1.4.8.2 doesnt work with or without fix... some another solution? Test page: http://23907.w7.wedos.net/1139-basebalova-cepice-silent-hunter.html Edited August 14, 2012 by JAKCRABBIT (see edit history) Link to comment Share on other sites More sharing options...
jpryce Posted August 27, 2012 Share Posted August 27, 2012 anyone know how to reference features in search results as well? Link to comment Share on other sites More sharing options...
carmadsu Posted October 22, 2012 Share Posted October 22, 2012 Thanks for the help One question: When I do the search, does not show me the instant search box. This happens buuscando reference. Any idea why? Link to comment Share on other sites More sharing options...
deefaze Posted November 30, 2012 Share Posted November 30, 2012 And for Prestashop 1.5 (tested on 1.5.2), just a little nuance : location : override/classes/search.php code class Search extends SearchCore { public static function getAttributes($db, $id_product, $id_lang) { if (!Combination::isFeatureActive()) return ''; $attributes = ''; $attributesArray = $db->executeS(' SELECT al.name, pa.reference FROM '._DB_PREFIX_.'product_attribute pa INNER JOIN '._DB_PREFIX_.'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute INNER JOIN '._DB_PREFIX_.'attribute_lang al ON (pac.id_attribute = al.id_attribute AND al.id_lang = '.(int)$id_lang.') '.Shop::addSqlAssociation('product_attribute', 'pa').' WHERE pa.id_product = '.(int)$id_product); foreach ($attributesArray as $attribute) $attributes .= $attribute['name'].' '.($attribute['reference']!=""?$attribute['reference'].' ':''); return $attributes; } } 1 Link to comment Share on other sites More sharing options...
jmeile Posted May 5, 2013 Share Posted May 5, 2013 (edited) Hi Thanks to genix for the original fix and to deefaze for the 1.5.2 fix. Anyway, for prestashop 1.5.4, you will have to modify the Search class as follows: class SearchCore { public static function getAttributes($db, $id_product, $id_lang) { /* This function was patched to return convination references: * Post: [FIX] Include search by attribute references in search results http://www.prestashop.com/forums/topic/175234-fix-include-search-by-attribute-references-in-search-results */ if (!Combination::isFeatureActive()) return ''; $attributes = ''; $attributesArray = $db->executeS(' SELECT al.name, pa.reference FROM '._DB_PREFIX_.'product_attribute pa INNER JOIN '._DB_PREFIX_.'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute INNER JOIN '._DB_PREFIX_.'attribute_lang al ON (pac.id_attribute = al.id_attribute AND al.id_lang = '.(int)$id_lang.') '.Shop::addSqlAssociation('product_attribute', 'pa').' WHERE pa.id_product = '.(int)$id_product); foreach ($attributesArray as $attribute) $attributes .= $attribute['name'].' '.($attribute['reference'] !="" ? $attribute['reference'].' ' : ''); return $attributes; } } It is escentially the same code from deefaze, but the class is not named Search any more and it doesn't extends from SearchCore. By the way, I tried putting it on the "override/classes/Search.php" folder, but it didn't work. At the end I had to modify the original class. Best regards Josef Edited May 5, 2013 by jmeile (see edit history) 1 Link to comment Share on other sites More sharing options...
jmeile Posted May 5, 2013 Share Posted May 5, 2013 anyone know how to reference features in search results as well? Hi jpryce I see that you posted this long time ago, anyway, if you are still looking for this, in prestashop 1.5.4 is actually posible to do it. No need of changing code. On the other hand, if you want to look for "Customized values", I think this isn't implemented. Anyway, I don't see any practical use for this. On my case, those values include things like size, diameter, volume, etc., so it is nothing worth to be indexed. But if you had a practical case, let me know. Best regards Josef Link to comment Share on other sites More sharing options...
TourisT Posted May 26, 2013 Share Posted May 26, 2013 if you are still looking for this, in prestashop 1.5.4 is actually posible to do it. No need of changing code. Hi Josef, I have a clean 1.5.4.1 install, hundreeds of products loaded. References showing up on product detail pages. However, it's not search-able. Anything to activate / re-generate in the back office? Thanks, Link to comment Share on other sites More sharing options...
guest* Posted May 26, 2013 Share Posted May 26, 2013 Did you already reindexed your search-engine ? Tab Preferences -> search -> index -> link reindex products Link to comment Share on other sites More sharing options...
TourisT Posted May 26, 2013 Share Posted May 26, 2013 Did you already reindexed your search-engine ? Tab Preferences -> search -> index -> link reindex products Thanks, I was looking under "SEO & URLs" and couldn't find my way. Tested and working Link to comment Share on other sites More sharing options...
haunter Posted October 9, 2013 Share Posted October 9, 2013 BUMP!!!Presta team, why you still didnt implement that to new version, yet? Hope that will be in next rls ;-) Thanks to all 1 Link to comment Share on other sites More sharing options...
guanooo Posted November 21, 2013 Share Posted November 21, 2013 Works perfect for prestashop 1.5.5.0. Thanks for the help. Link to comment Share on other sites More sharing options...
Logical IT Posted November 28, 2013 Share Posted November 28, 2013 for version 1.5.6.0 I copied jmeile (#10) solution. Worked great - Thank you jmeile! Don't forget to rebuild your index - Back Office Preferences -> search -> indexation -> rebuild index This is bug and after a year and half since the issue was first reported I'm surprise PrestaShop still have'nt fixed this issue. Chris. Link to comment Share on other sites More sharing options...
geotargetplus Posted February 7, 2014 Share Posted February 7, 2014 Work Thanks! Link to comment Share on other sites More sharing options...
patrikar Posted May 7, 2014 Share Posted May 7, 2014 Following works for 1.5.x:Edit the file /override/classes/Search.php and make it look like this: <?php class Search extends SearchCore { /* Override: adding functionality to search by reference of attributes */ public static function getAttributes($db, $id_product, $id_lang) { if (!Combination::isFeatureActive()) return ''; $attributes = ''; $attributesArray = $db->executeS(' SELECT al.name, pa.reference FROM '._DB_PREFIX_.'product_attribute pa INNER JOIN '._DB_PREFIX_.'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute INNER JOIN '._DB_PREFIX_.'attribute_lang al ON (pac.id_attribute = al.id_attribute AND al.id_lang = '.(int)$id_lang.') '.Shop::addSqlAssociation('product_attribute', 'pa').' WHERE pa.id_product = '.(int)$id_product); foreach ($attributesArray as $attribute) $attributes .= $attribute['name'] . ' ' . $attribute['reference']; return $attributes; } } Next step is to log on to your shop backend and go to "Preferences > Search" and click "Rebuild entire index". Credit to posters above, I'm just clarifying what's already been told. Please pay a visit to this issue on the Prestashop issue tracker and give it a vote. Link to comment Share on other sites More sharing options...
Prestafan1234 Posted July 16, 2014 Share Posted July 16, 2014 I am working on a shop, where it is not possible to search for reference numbers in the attributes. I want to implement the above solution, but there is no /override/classes/Search.php file. My customer's shop is version 1.5.6.1 So I checked my own store which runs 1.5.6.2 and I don't have this file either - but I can search in attributes just fine. Has something changed in the versions since the solutions above? I have of course rebuilt the index on the customer's shop, so that is not the problem. Link to comment Share on other sites More sharing options...
Alvarosc Posted December 17, 2014 Share Posted December 17, 2014 Following works for 1.5.x: Edit the file /override/classes/Search.php and make it look like this: <?php class Search extends SearchCore { /* Override: adding functionality to search by reference of attributes */ public static function getAttributes($db, $id_product, $id_lang) { if (!Combination::isFeatureActive()) return ''; $attributes = ''; $attributesArray = $db->executeS(' SELECT al.name, pa.reference FROM '._DB_PREFIX_.'product_attribute pa INNER JOIN '._DB_PREFIX_.'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute INNER JOIN '._DB_PREFIX_.'attribute_lang al ON (pac.id_attribute = al.id_attribute AND al.id_lang = '.(int)$id_lang.') '.Shop::addSqlAssociation('product_attribute', 'pa').' WHERE pa.id_product = '.(int)$id_product); foreach ($attributesArray as $attribute) $attributes .= $attribute['name'] . ' ' . $attribute['reference']; return $attributes; } } Next step is to log on to your shop backend and go to "Preferences > Search" and click "Rebuild entire index". Credit to posters above, I'm just clarifying what's already been told. Please pay a visit to this issue on the Prestashop issue tracker and give it a vote. This worked perfectly for me. Prestashop 1.6.0.8. I've edited the file /classes/Search.php and I had to rebuild the index. So thanks Link to comment Share on other sites More sharing options...
ebski Posted July 27, 2016 Share Posted July 27, 2016 Cant believe they still haven't fixed this issue, but thanks for helping me out, worked like a charm for 1.6.1.4. Now the only thing I need to figure out is how to make the same thing work in backend search for reference, any ideas? Link to comment Share on other sites More sharing options...
Tatort Posted May 15, 2017 Share Posted May 15, 2017 Hi Guys! Someone know how to see the searched variation and not the default variation ? I don't find a way... Thanks! Romain Link to comment Share on other sites More sharing options...
Ezequielb Posted August 23, 2020 Share Posted August 23, 2020 On 5/15/2017 at 11:13 AM, Tatort said: Hi Guys! Someone know how to see the searched variation and not the default variation ? I don't find a way... Thanks! Romain Hello, I have the same question. How to show the specific variation as a result and not the default one? PS 1.7.6 1 Link to comment Share on other sites More sharing options...
CartaPenna Posted April 17, 2022 Share Posted April 17, 2022 Hello, I'm currently on version 1.7.8.3, I tried this solution but unfortunately it didn't work. I didn't have a Search.php file in Override, so I tried modifying the one in Classes. Has anyone fixed the issue recently? This is a pretty annoying one, hard to believe that there hasn't been yet an official solution. If not by fixing this issue, how is it possible to achieve the same thing (find a Combination by it's reference number)? Thanks in advance Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now