PrestaShop | How to move PrestaShop shopping cart to the menu?

When you work with the system PrestaShop, there comes a moment when the client has prepared its own individual template store. This template is often unfamiliar with the structure of preparing graphics store. But should the programmer should deal with each template - although it is the custom, and at first sight, you will need thorough reconstruction of some elements of the store.

Recently I had the opportunity to build a new store layout based on the default template for PrestaShop version 1.6. An important element of the project was on the menu. Why? The menu has been moved many items that were in the upper part of the shop; we are talking about shopping cart, user logon or search engine or logotype.

Many elements sufficient to move between Tpl files by creating your own template. However, you can do it more professionally and prepare new tabs (hook) and move there just individual elements. The advantage of this is that there is nothing to move from file to file, and only create an attachment point to which we direct new items. So, for example, create a new hook responsible for displaying the basket.

{hook h="displayCartinmenu"}

The above code snippet is placed in the TPL file where you want to display the new elements, modules. I added it to a file blocktopmenu.tpl w ./themes/nazwa_szablonu/modules/blocktopmenu/. But everything worked to create a new hook in the database - I have not found a way to install new hooks from the backend store, so we create a new entry in the table ps_hook.

Over printscreen from the database. We need to provide the name of Hook, in my case displayCartinmenu, we give title and description. Additionally, you can also generate an alias for the new Hook in the second table ps_hook_alias (simple matter, so I do not describe the details). To be able to assign modules to a new hook, we must first tell the module how to behave in a new place. We must therefore add a new method to main file php file in the module (I modified the file blockcart.php, because this is what the module allow you to display at the new location).

public function hookCartinmenu($params) { $params['blockcart_top'] = true; return $this->hookRightColumn($params); }

What makes the above code? I create a function that is responsible for the display module in hook basket called Cartinmenu that I created earlier. Two lines of code inside the function are the same as for displaying shopping cart in the top:

public function hookTop($params) { $params['blockcart_top'] = true; return $this->hookRightColumn($params); }

So duplication diagram display, which is already working for the hook named Top. The last step to be done at the end of the module is added to our hook by the back of the store.

In the administration panel, we must turn to choose from the menu: "Modules", then "Positions" and finally "The movement of the module."

In the first list, select the module, on the other hook to which we add the module and save the changes. After this operation, we obtain the following system:

If all steps are successful, and the effect it should be immediately apparent to the store. In my case the cart has been added to the menu - a module that is integrated with PrestaShop.

Using the hook is very useful especially when you need to display a module in a custom location for the store. In conclusion, a small amount of work can be a lot to gain, by the way without mixing in the source code of the individual modules.

Contact