I am new to prestashop, so please bear with me if I am asking a very simple question. I am into creating module, and in my task I have to extend the cart controller that is bein
I found a way to extending the prestashop default controllers inside a module.
I looked iniside the classes/Dispatcher.php
and found this inside the dispatch() method
case self::FC_MODULE :
$module_name = Validate::isModuleName(Tools::getValue('module')) ? Tools::getValue('module') : '';
$module = Module::getInstanceByName($module_name);
$controller_class = 'PageNotFoundController';
if (Validate::isLoadedObject($module) && $module->active) {
$controllers = Dispatcher::getControllers(_PS_MODULE_DIR_.$module_name.'/controllers/front/');
if (isset($controllers[strtolower($this->controller)])) {
include_once(_PS_MODULE_DIR_.$module_name.'/controllers/front/'.$this->controller.'.php');
$controller_class = $module_name.$this->controller.'ModuleFrontController';
}
}
$params_hook_action_dispatcher = array('controller_type' => self::FC_FRONT, 'controller_class' => $controller_class, 'is_module' => 1);
So, The naming convention for the controller is
<modulename><controllername>ModuleFrontController
and the path to the controller should be
module/<module name>/cotrollers/front/<controllername>.php
Example mycart controller inside an areacalc module
class areacalcmycartModuleFrontController extends CartController {
File path to the mycart controller inside an areacalc module
/modules/areacalc/controllers/front/mycart.php
url will be
http://localhost:8080/index.php?fc=module&module=areacalc&controller=mycart
You can override the defaut CartController.php, in the override module folder you add your class code (only the modified method) in this case i suppose you would modify the processChangeProductInCart method, you can see the prestashop override documentation