0

I am pretty new to opencart and I want to learn how can I create a more advanced search function.

For example I have products in my store, some of them are blue and some of them are red. How can I specify or where I can specify a product's color (but not in the title, something like an attribute)?

And after that how can I search for red products? I do not want to search by the keywords. I want a tab where to select the color and if I choose blue the search will show me all the blue products.

I hope you understand what I wish.(and can you please give me some code examples: where to add what to add to achieve what)

Thank you!

1 Answer 1

2

Normally, you would use Product Tags for this (field is under Product description on Product Page in Admin > Catalog > Products). You could have problems with very short tags 3 characters or less. See this post for more info:

mysql fulltext MATCH,AGAINST returning 0 results

You would add tags to your products like: red,black,brown,leather,s,m,l,xl small, medium, large Then you could search any of the terms

[EDIT: in response to comment #1] I would imagine that you just type multiple terms into search box: 'brown','large' then all products that have (any? both?) of these tags returned.

You could use a Tag cloud or similar module to display tags on your pages, also you could use these terms in search field. If you search for 'brown', all products that have this tag will be returned. You may also consider a third party extension for a more advanced search, check Opencart site's extension section.

If you want to modify/improve the search functionality yourself, you'll need to tinker with SQL queries in catalog/model/catalog/product.php

Opencart Search is considered by many to be one of the weak points of this package. There have been discussions on Opencart forums on this matter.

Just see how it works for you with the out-of-the-box setup, then if you need more functionality, look for an extension that does what you want, hire a programmer or code it yourself.

4
  • but then how can I change the search to be more advanced, so I can select color: red,blue,yellow etc; size: s,m,l,xl; etc? Dec 13, 2012 at 12:09
  • 1
    I want to code it myself, so that is why am asking. I need an example of how can I add an atribute, I need to understand the concept, I have a project for my university and this is why I need to understand the concept. Could you recommend me something else than opencart with a better search engine by default? or something with a prebuild advanced search engine? Dec 13, 2012 at 17:26
  • 1
    Personally, I like Opencart a lot, cannot recommend anything. Check out other popular e-commerce packages like zen cart, oc commerce, magento etc. I am not too familiar with their search functionality, so cannot comment.
    – B-and-P
    Dec 14, 2012 at 5:29
  • 1
    As for modifying opencart search, I would probably add a separate function to catalog/model/catalog/product.php like my_Search() and build custom queries there. You need to know SQL quite well to pull it off. Just look at the code in catalog/controller/product/search.php and catalog/model/catalog/product.php Opencart uses fulltext indexes and uses MATCH() AGAINST()
    – B-and-P
    Dec 14, 2012 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.