On this weblog, we’ll learn to override modules in PrestaShop. Typically, we have to improve or modify the module function then it’s not really useful to switch the module file straight. If we modify the module recordsdata straight then sooner or later when you improve the module, all modifications shall be misplaced. You’ll be able to see the beneath PrestaShop official to know extra about overriding:
https://devdocs.prestashop-project.org/8/modules/ideas/overrides/
We are able to override the beneath recordsdata of the module:
- Fundamental file
- Controller recordsdata (entrance & admin)
Override module primary file:
To override a module’s primary class, that you must lengthen it and you need to present the prolonged class the identical identify and add the Override
suffix:
Prestashop Firm ? Learn Extra
ie: If you wish to override ps_shoppingcart
module then the prolonged class identify shall be Ps_ShoppingcartOverride
.
class Ps_ShoppingcartOverride extends Ps_Shoppingcart { // Override the Ps_Shoppingcart strategies right here }
Override module controller file:
You’ll be able to override module admin and entrance controllers. To override module controllers, you need to do the identical factor as carried out for overriding the module primary class. It’s essential lengthen the controller class and supply the prolonged class the identical identify and add the Override suffix:
ie: If you wish to override the ps_emailsubscription
module entrance controller class Ps_EmailsubscriptionSubscriptionModuleFrontController
then the prolonged class identify ought to be Ps_EmailsubscriptionSubscriptionModuleFrontControllerOverride
:
class Ps_EmailsubscriptionSubscriptionModuleFrontControllerOverride extends Ps_EmailsubscriptionSubscriptionModuleFrontController { public operate postProcess() { ... } }
In the identical method, you can even override the module admin controller. All overridden module recordsdata are moved to the PrestaShop override folder (override/modules/<MODULE_NAME>/) throughout the set up of the module.
That’s all about this weblog.
If any subject or doubt please be at liberty to say it within the remark part.
I might be glad to assist.
Additionally, you may discover our PrestaShop Growth Providers & a wide range of high quality PrestaShop Modules.
For any doubt contact us at [email protected].