dvi Posted May 7, 2019 Share Posted May 7, 2019 Hello, Thank you in advance. Recently I created a module extension for admin order controller, with more columns and filters in the backend. But I don't understand, when I apply one search with filter the page redirects to the index page of modules, and not apply the filter correctly. Can someone please help me?? I attached my helper code: $helper_list = New HelperList(); $helper_list->module = $this; $helper_list->title = $this->l('Todos los pedidos'); //$helper_list->shopLinkType = ''; //$helper->table = 'orders'; //$helper_list->no_link = true; $helper_list->show_toolbar = true; $helper_list->simple_header = false; $helper_list->identifier = 'id_order'; $helper_list->token = Tools::getAdminTokenLite('AdminModules'); $helper_list->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name; $helper_list->actions = array('editOrder'); $helper_list->listTotal = count($pedidos); return $helper_list->generateList($pedidos, $fields_list); } Thank you!! Link to comment Share on other sites More sharing options...
Janett Posted May 7, 2019 Share Posted May 7, 2019 Did you use this code inside your Module class or in a ModuleAdminController ? Link to comment Share on other sites More sharing options...
dvi Posted May 7, 2019 Author Share Posted May 7, 2019 Sorry but i'm newbie in PrestaShop. I made a module with a class. I don't touch the AdminController.. class Pedidos extends Module Link to comment Share on other sites More sharing options...
Janett Posted May 7, 2019 Share Posted May 7, 2019 Ok, the HelperList inside a Module::getContent() is not a good idea because search and filters are handled in AdminController::initProcess(), when you are in a Module::getContent() your assignment of list is done after AdminController::init() so it's not working. See https://github.com/PrestaShop/PrestaShop/blob/70d12a5ffbd9f1123e76cded1be8d2f78d5f015c/classes/controller/AdminController.php#L2853 You should create an ModuleAdminController to access all useful method available for helpers. I don't use Module::getContent() anymore in my modules, in fact I just use it to make a redirection to my ModuleAdminController. If you use an HelperList inside a Module::getContent() you cannot use advanced features of this helper which is designed to be used in an AdminController, usage in Module::getContent() is tricky, I think it's a bad practice. Did you know how to create an ModuleAdminController ? Link to comment Share on other sites More sharing options...
dvi Posted May 7, 2019 Author Share Posted May 7, 2019 (edited) I don't know how to do that. You can see this: the helper its not in the getcontent.. public function getContent() { $this->_html .= $this->initListPedidos(); return $this->_html; } Edited May 7, 2019 by dvi (see edit history) Link to comment Share on other sites More sharing options...
Janett Posted May 7, 2019 Share Posted May 7, 2019 In fact you call HelperList inside Module::getContent() with $this->_html .= $this->initListPedidos(); 😉 You can't use filters of HelperList in a Module class 😔 Link to comment Share on other sites More sharing options...
dvi Posted May 7, 2019 Author Share Posted May 7, 2019 What do you recommend me?? How can I fix the filters?? or routes.. Link to comment Share on other sites More sharing options...
Janett Posted May 7, 2019 Share Posted May 7, 2019 You have to create a ModuleAdminController inside your module to proper use HelperList 1 Link to comment Share on other sites More sharing options...
dvi Posted May 7, 2019 Author Share Posted May 7, 2019 Ok I will try it, and then in class Pedidos extends ModuleAdminController { here in the ModuleAdminController I have to put all the helper list, right?? Link to comment Share on other sites More sharing options...
Janett Posted May 7, 2019 Share Posted May 7, 2019 (edited) You still need to have a class Module inside your module and you have to create a new file in /modules/pedidos/controllers/admin/AdminPedidosController.php class AdminPedidosController extends ModuleAdminController [Your code here] Here some example of code you have to write inside your Module class if (!defined('_PS_VERSION_')) { exit; } class Pedidos extends Module { /** * Name of your ModuleAdminController */ const MODULE_ADMIN_CONTROLLER = 'AdminPedidos'; /** * @var array List of hooks you use */ public $hooks = array( 'displayHome', // For example ); /** * Constructor */ public function __construct() { $this->name = 'pedidos'; $this->tab = 'administration'; $this->version = '1.0.0'; $this->author = 'Pedidos'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Pedidos'); $this->description = $this->l('Pedidos description'); } /** * Install Module * * @return bool */ public function install() { return parent::install() && $this->registerHook($this->hooks) && $this->installTabs() ; } /** * Install Tabs * * @return bool */ public function installTabs() { if (Tab::getIdFromClassName(static::MODULE_ADMIN_CONTROLLER)) { return true; } $tab = new Tab(); $tab->class_name = static::MODULE_ADMIN_CONTROLLER; $tab->module = $this->name; $tab->active = true; $tab->id_parent = -1; $tab->name = array_fill_keys( Language::getIDs(false), $this->displayName ); return $tab->add(); } /** * Uninstall Module * * @return bool */ public function uninstall() { return parent::uninstall() && $this->uninstallTabs() ; } /** * Uninstall Tabs * * @return bool */ public function uninstallTabs() { $id_tab = (int) Tab::getIdFromClassName(static::MODULE_ADMIN_CONTROLLER); if ($id_tab) { $tab = new Tab($id_tab); return $tab->delete(); } return true; } /** * Redirect to your ModuleAdminController when click on Configure button */ public function getContent() { Tools::redirectAdmin($this->context->link->getAdminLink(static::MODULE_ADMIN_CONTROLLER)); } /** * Display something on homepage * * @param array $params * * @return string */ public function hookDisplayHome($params) { $this->smarty->assign(array( 'hook_name' => 'hookDisplayHome', // For example )); return $this->display(__FILE__, 'displayHome.tpl'); } } Edited May 7, 2019 by Janett (see edit history) 1 Link to comment Share on other sites More sharing options...
dvi Posted May 8, 2019 Author Share Posted May 8, 2019 Thank you for your patience. I already have a class with like type of example code, but I miss the ModuleAdminController, what code put here? This is a fragment of class code: class Pedidos extends Module { protected $_html = ''; public function __construct() { $this->name = 'sgrsh'; $this->tab = 'thhth'; $this->version = '1.6.1'; $this->author = 'tddhdt'; $this->need_instance = 0; $this->secure_key = Tools::encrypt($this->name); $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('dhthtdhdt'); $this->description = $this->l('Consulta.'); $this->ps_versions_compliancy = array('min' => '1.6.0.4', 'max' => '1.6.99.99'); } /** * @see Module::install() */ public function install() { /* Adds Module */ if (parent::install()) { } return true; } /** * @see Module::uninstall() */ public function uninstall() { return true; } Link to comment Share on other sites More sharing options...
Janett Posted May 8, 2019 Share Posted May 8, 2019 Depends what you need to display, did you create a table to save data or you want to display existing data ? Link to comment Share on other sites More sharing options...
dvi Posted May 8, 2019 Author Share Posted May 8, 2019 Only display existing data of prestashop orders. Now when I enter at the module and use the filters to search, the page reload or goes back to the modules page. But never applies and show the data. The only thing that works, is the DESC and ORDER BY. if (Tools::getValue('configurationOrderby')) { $orderway = Tools::getValue('configurationOrderway'); $orderby = Tools::getValue('configurationOrderby'); $sql .= ' ORDER BY ' . $orderby . ' ' . $orderway; } else { $sql .= ' ORDER BY ps_orders.id_order DESC'; } $pedidos = Db::getInstance()->executeS($sql); Link to comment Share on other sites More sharing options...
Janett Posted May 8, 2019 Share Posted May 8, 2019 (edited) In this case, you just have to looks in AdminOrders.php to get your inspiration, like this : /modules/pedidos/controllers/admin/AdminPedidosController.php <?php class AdminPedidosController extends ModuleAdminController { /** * Constructor. */ public function __construct() { $this->bootstrap = true; $this->table = 'order'; $this->className = 'Order'; $this->lang = false; $this->explicitSelect = true; $this->allow_export = true; $this->deleted = false; $this->addRowAction('view'); parent::__construct(); $this->_select = ' a.id_currency, CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, osl.`name` AS `osname`, os.`color`, IF(a.valid, 1, 0) badge_success'; $this->_join = ' LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON (c.`id_customer` = a.`id_customer`) LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON (os.`id_order_state` = a.`current_state`) LEFT JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = ' . (int) $this->context->language->id . ')'; $this->_orderBy = 'id_order'; $this->_orderWay = 'DESC'; $this->_use_found_rows = true; $statuses = []; foreach (OrderState::getOrderStates((int) $this->context->language->id) as $status) { $statuses[(int) $status['id_order_state']] = $status['name']; } $this->fields_list = array( 'id_order' => array( 'title' => $this->l('ID'), 'align' => 'text-center', 'class' => 'fixed-width-xs', ), 'reference' => array( 'title' => $this->l('Reference'), ), 'customer' => array( 'title' => $this->l('Customer'), 'havingFilter' => true, ), 'total_paid_tax_incl' => array( 'title' => $this->l('Total'), 'align' => 'text-right', 'type' => 'price', 'currency' => true, 'callback' => 'setOrderCurrency', 'badge_success' => true, ), 'payment' => array( 'title' => $this->l('Payment'), ), 'osname' => array( 'title' => $this->l('Status'), 'type' => 'select', 'color' => 'color', 'list' => $statuses, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'order_key' => 'osname', ), 'date_add' => array( 'title' => $this->l('Date'), 'align' => 'text-right', 'type' => 'datetime', 'filter_key' => 'a!date_add', ), ); $this->shopLinkType = 'shop'; $this->shopShareDatas = Shop::SHARE_ORDER; } /** * Callback for total_paid_tax_incl column to display price * * @param string $echo Value of this column * @param array $tr All columns of this row * * @return string */ public static function setOrderCurrency($echo, $tr) { if (!empty($tr['id_currency'])) { $idCurrency = (int) $tr['id_currency']; } else { $order = new Order($tr['id_order']); $idCurrency = (int) $order->id_currency; } return Tools::displayPrice($echo, $idCurrency); } } Edited May 8, 2019 by Janett (see edit history) Link to comment Share on other sites More sharing options...
dvi Posted May 15, 2019 Author Share Posted May 15, 2019 Hi, I still need some help... I'm confused about what code put in the controller of my module. Can I attach you my private code and check it together? Thank you!! Link to comment Share on other sites More sharing options...
Janett Posted May 15, 2019 Share Posted May 15, 2019 Yes, but please note I'm in vacation, I don't have computer, so I can reply really slowly especially for this type of demand. I can only do that on my free time. So please be explicit in order to not lose my time to ask information. Link to comment Share on other sites More sharing options...
dvi Posted May 15, 2019 Author Share Posted May 15, 2019 (edited) 30 minutes ago, Janett said: Yes, but please note I'm in vacation, I don't have computer, so I can reply really slowly especially for this type of demand. I can only do that on my free time. So please be explicit in order to not lose my time to ask information. Oh thank you in advance. This is my code of pedidos.php, then I only need an idea to continue and do the controller. Note my level of PHP is null. Remember that in my case when I do a search in the order list of module, the filters not works and the page redirect to index, the same with pagination, etc. When you have time and you want please check it. Thank you!! sent it by inbox Edited May 15, 2019 by dvi private (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now