Differences Between Magento and Prestashop Modules Development

August 12, 2014 Artem Demidov Magento, Prestashop
Differences Between Magento and Prestashop Modules Development

Both Mаgentо and Prestаshоp provide possibilities to create custom modules to extend CMS functionalities.  In this article we will try to describe main differences between the modules which are designed for these systems on example of Customer Images Uploader module for Magento and Prestashop

Structural differences between Mаgentо and Prestаshоp modules

In spite of the fact that the structure of the modules in both CMSs follows the MVC(Model-View-Controller) concept, they still have certain major differences:

1Differences Between Magento and Prestashop

As illustrated on fig.1, Mаgentо and Prestаshоp modules have significant structural differences.  Let’s take a closer look at the structure of the modules and differences between them.

Controllers. Controllers serve as a key part of the module providing connection to the model.

2Differences Between Magento and Prestashop

Of course, implementation of controllers in Magento and Prestashop modules are different.

Example: Magento module controller code 

Example: Prestashop module controller code

Http addresses, which query the controller, are also different:

http://belvg.info/demo/customeruploadimages/index.php/uploadimages/images/upload/ –   The example of an http address for Magento.

http://belvg.info/demo/prestashop16/uploadimages/module/belvguploadimages/upload?action=browse&id_product=3&id_customer=0&id_shop=1 – The example of an http-address for Prestashop.

Models. In Magento models are represented with the classes in the Models catalog.  They are divided into business-models and resource-models. It is also possible to distinguish a collection-model which is a separate type.   Business-model is designed for processing data, which are retrieved from the database. However this model does not send requests to the database. It is inherited from the class Mage_Core_Model_Abstract.

Example: Magento business-model code 

Resource-model is responsible for working with the database. It provides interface for retrieving data from the database. Resource-model is either inherited from the class  Mage_Core_Model_Mysql4_Abstract or from the class Mage_Core_Model_Resource_Abstract .

Example: Mаgentо resource-model code 

Collections request database to retrieve multiple table rows.   Collections are inherited either from the class Mage_Core_Model_Mysql4_Collection_Abstract or from the class Mage_Core_Model_Resource_Collection_Abstract.

Example: Magento collection code

Prestashop model is represented with the classes from the directory prestаshоp/classes/. Although Prestаshоp classes from the directory prestаshоp/classes/ may also have a much wider application rather than using them as a model (for example, the directory prestаshоp/classes/ contains controllers), but in general, we can say that these classes are models. Catalog classes are created in the module root directory. This catalog contains models related to this module.

Example: Prestаshоp class code 

View. View is used to display information. The implementation of View in Mаgentо and Prestаshоp modules has the most significant differences.  In Mаgentо the View component is comprised of the following 3 elements:  Block, Template and Layout.

Block. Block is a class, which is required to output information (template). The basic class for Block is Mage_Core_Block_Template, as well as some other classes.

Example: Magento block code

Template. Templates are represented with .phtml files. These files contain the html markup of that part of the page, which is rendered by the block.

Example: Magento template code

Layout. Layout is an .xml file that contains page structure and connects templates and blocks.

Example: Magento layout code

Layout and Template are located in the directory app/design/[package name]/[theme name]. Package name – this is the current package, theme name – the current theme. If package name and theme name are not specified, then the current package is base, and the current theme is theme.

There are also smarty-templates in Prestashop that contain html and smarty tags.

Example: Prestashop template code 

Module templates are located in the directory modules/belvguplоаdimаges/view/templates. Instead of belvguplоаdimаges there can be used directories of any other module. But there are no other similarities with Magento for implementation of the View component.  Prestashop does not provide any specialized classes for template rendering.  A template can be used in the module controller in special hook methods.

Example:  Using template in the module Custom Images Uploader for Prestashop

P.S.  As we have illustrated by the module Customer Uploader Images, the implementation of Mаgentо and Prestаshоp modules has significant differences. But in spite of this, it is possible to create extensions for both systems, which can perform similar tasks.

Post a new comment