Get Free Audit

Developer Tips: How to Enable Prestashop CMS Search. Part 1

Jul 30, 2012

1087 Alex Simonchik

In our blog we explained how PrestaShop search works and instantly received a comment from one of our readers.

Bill: This is good, but the search function is entirely about products. What about when customers want to search something from CMS pages?

Alas, there are no standard tools to do that. The only way to achieve this goal is to extend the standard functionality with the help of a new module. I’ll guide you the process of its development. Readers may also download the module archive at the end of this article.

PrestaShop stores all modules in the YOUR_STORE/modules/ folder. It includes at least one file – yourmodulename.php, which contains the core module functions. If you want to set an icon for your module, copy the logo.gif image into the folder with your module. This icon will be displayed in backend -> modules -> yourModule.

Let’s call our module belvg_cmssearchfree and create a folder with the same name in the modules directory. Belvg_cmssearchfree.php with the following content should be placed there:

We need to modify the SearchController work logic, so let’s create the same file in override/controllers folder. We add the function to enable search both within products and CMS:

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor


Search.tpl template will be extended with a section, responsible for displaying articles that satisfy the search criteria.

Please, notice that if you are planning to implement the multilanguage option in your module, you need to use the following construction for the templates: {l s=’ cms result has been found.’ mod=’belvg_cmssearchfree’}, where the mod=yourmodulename parameter is specified. Thereby translations will be available at backend ->Tools -> Translations -> Modify translations ->Module Translaions ->Choose Language -> Module: yourmodulename. When translations are saved, the file with multiple languages (e.g. en.php, fr.php, etc) will appear in the folder with your module.

modules prestashop belvg

PrestaShop Modules

Take your online store to the next level with BelVG PrestaShop Modules

Visit the store

The last thing to do is to take a look at install.php and uninstall.php files, where file replacement logic is contained. You could place the SearchController file in override folder manually, but since we create a product for addons.prestashop.com, manual approach for file transfer is a bad idea.

Install.php:


Uninstall.php:

As a result we get a module that enables search both within products and CMS.

Experienced developers won’t consider this article extremely helpful, because it is largely oriented on beginners.

If anything is left unclear or questionable, let’s discuss it in comments below. Feel free to suggest ideas for developer tips, and we’ll examine the case in our future posts.

Expect to read how to create more flexible Prestashop CMS search and configure module settings the next Monday, August 6.

development_prestashop

PrestaShop Development

Take your online store to the next level with BelVG PrestaShop Development

Visit the page
Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

13 Comments

  1. Ashsih,

    This module is not displayed in hooks, because it just modifies the behavior of Prestashop. If you want to change the position of search results, then you need to edit directly the tpl file of the theme or module.

  2. Hello Alex,

    Thanks for the great module.

    I have installed it in my localhost But it is not displaying in the front page.Please let me know how to setup the position of this module in the header.Because in backend module >position>not displaying there your module.
    Thanks in advance

  3. We have updated the CMS Search module for Prestashop 1.5. Head to our store to get it – http://module-presta.com/cms-search.html.

    But that’s not all – we will be offering the new version of the module for free to several blog readers who were interested in it’s appearance enough to ask us about it. If you wrote a comment to this post – please contact us at [email protected] and we will give you a special download code.

  4. Hi Martin, it would be extremely helpful if you could forward that file to me.

    Hi Alex, have you managed to upgrade this module to 1.5? Thanks for your excellent article!

  5. Hi,
    I have upgraded (hacked?) the SearchController override to be compatible with 1.5. There are a couple of issues:

    1) The install script tried to backup the file and copy to/from “override/Controllers/SearchController.php”, where the correct path should now include the folder “Front, (i.e. “override/Controllers/Front/SearchController.php”). I just manully copied the files and changed the install method in the module php file to return true.

    2) The name of the method to override is now initContent(). Actually I copied the base class (SearchControllerCore), changed the name and extends statement, and added the method of getting CMS content and the smarty assign variables.

    3) Context is now used to get language id, ie. $this->context->language->id

    I’m happy to forward the file, if you’re interested.

    Thanks for a great article!

    Best regards,

    Martin

  6. Hi Jörg,

    Thanks for installing our module. Actually, we are planning to upgrade all our PrestaShop modules to 1.5 version by the end of this year.

    Besides, we will post a new article on how to write modules in PrestaShop 1.5 shortly, so don’t forget to subscribe to our blog.

  7. Hi great Job. I used your module in prestashop 1.4 and it worked like charm BUT NOW IN PRESTASHOP 1.5, it doesn’t work anymore (not even install !). Do you have any idea why ? Have you planned to make an update ? If no could you please give me a hint ?
    Kind regards,
    Jörg

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *