where can I find prestashop controllers and how can i extend them?

依然范特西╮ 提交于 2019-12-04 06:03:19

问题


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 being called by the ajaxcart.add() function in the javascript. I want to know, where is the controller that responds to this ajax request is located, and how can i extend this controller in my module. Are there any good documentation regarding this? thanks


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/32266747/where-can-i-find-prestashop-controllers-and-how-can-i-extend-them

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!