Prestashop 1.7: cloning of the module


25-07-2018
Денис Л.
Cms
Prestashop 1.7: cloning of the module

I recently encountered one problem. It was necessary to place several modules with the recommended products in one block of the site, in particular - "displayHome". It was required to display 8 modules with goods from different categories on the main page one by one. I decided to use the "Featured Products" module, which comes with Prestashop 1.7. One module in the "displayHome" area was perfectly placed, but as soon as I tried to place the second one the same error occurred: "The module has already been transplanted into the hook". I've been struggling for hours on this weekend. The result of many hours of trying was the following algorithm of actions, which I give below.

So, how to clone a module Featured products в Prestashop 1.7


The example describes cloning a module 'ps_featuredproducts', but the algorithm is applicable to any module Prestashop 1.7.

  1. We clone the folder with the module we need, assign it another name, for example ps_featuredproducts2
  2. At the root of the folder with the cloned module, change the name of the file ps_featuredproducts.php на ps_featuredproducts2.php
  3. At the root of the same folder we see two files config.xml and config_ru.xml. We go into each and change the tag <name> and the tag <displayName>, adding to the name '2'. Like this: <name>ps_featuredproducts2</name> and <displayName><![CDATA[Featured products2]]></displayName>
  4. We go in the folder views, further templates, further hook and change the name of the file ps_featuredproducts.tpl to ps_featuredproducts2.tpl
  5. Open the resulting file, add to the tag <section> classes "featured-products clearfix". Like this: <section class="featured-products clearfix">.
  6. Next for the tag <h1> add classes "h1 products-section-title text-uppercase".
  7. In the attribute "s" тега <h1> write the name of the given block, for example, if we show the goods of a category "a Series X" we write the given name.
  8. Next for an item <a> below we add classes "all-product-link float-xs-left float-md-right h4", and in the attribute "s" of this element we write the phrase we need to refer to all elements of this category, for example "All products of the X series".
  9. We return to the file ps_featuredproducts2.php, which is in the root of the cloned module. We open it.
  10. Change "class Ps_FeaturedProducts" to "class Ps_FeaturedProducts2"
  11. Change "$this->name = 'ps_featuredproducts'" to "$this->name = 'ps_featuredproducts2'"
  12. Change "$this->displayName = $this->trans('Featured products', array(), 'Modules.Featuredproducts.Admin')" to "$this->displayName = $this->trans('Featured products2', array(), 'Modules.Featuredproducts.Admin');"
  13. Change "$this->templateFile = 'module:ps_featuredproducts/views/templates/hook/ps_featuredproducts.tpl';" to "$this->templateFile = 'module:ps_featuredproducts2/views/templates/hook/ps_featuredproducts2.tpl';"
  14. Change "if (!$this->isCached($this->templateFile, $this->getCacheId('ps_featuredproducts')))" to "if (!$this->isCached($this->templateFile, $this->getCacheId('ps_featuredproducts2')))"
  15. Change "return $this->fetch($this->templateFile, $this->getCacheId('ps_featuredproducts'));" to "return $this->fetch($this->templateFile, $this->getCacheId('ps_featuredproducts2'));"
  16. Press ctrl + h to call the search and replace function in a text editor. In the whole file we change "HOME_FEATURED_CAT" to "HOME_FEATURED_CAT2"
  17. Save the file.
  18. With the help of phpMyAdmin go to the site database.
  19. Open the table "ps_configuration". Click the checkbox "show all" to display all the rows of this table.
  20. In the column "Filter lines" we enter "HOME_FEATURED_CAT". We copy this line. The name is changed to "HOME_FEATURED_CAT2"
  21. Open the table "ps_module", click the "show all" checkbox to display all rows of this table.
  22. Looking for a string "ps_featuredproducts", copy it, the name is assigned "ps_featuredproducts2"
  23. Go to the admin panel of the site.
  24. Click "Advanced Options" --> "Performance". Click "Clear cache".
  25. We go in the "Modules" --> "Modules and Services"
  26. Go to the installed modules.
  27. Find the module "ps_featuredproducts2".
  28. Choose "Configure" --> "Uninstall"
  29. Attention! When uninstalling the module files DO NOT delete!
  30. Again go to the "Modules" --> "Modules and Services"
  31. Click "Advanced Options" --> "Performance". Click "Clear cache".
  32. In the column 'Search' we enter ps_featuredproducts2. We see our remote module. Click "install". A window appears about the safe installation of the module.
  33. Click "Advanced Options" --> "Performance". Click "Clear cache".
  34. Select "Configure Module". In the settings we put the category we need for the output of goods.
  35. We go in the "Design" --> "Arrangement of blocks". Click the icon with the anchor "Arrange the module".
  36. Select a module "ps_featuredproducts2", we have it in the necessary area of the site, for example "displayHome"
  37. We check that in the output category of goods there are goods, otherwise nothing will be output.
  38. If the products in the output category are there, then go to the site and see in the desired area our cloned module.
  39. If you need to clone more - clone by the same algorithm.