Vintelec Posted October 1, 2020 Share Posted October 1, 2020 Hello, I have been trying for several days to develop a module for order preparation. I am under version 1.7.5 and I code according to the new recommendations of PrestaShop for 1.7, so with Symfony. I tried to fix all my errors by myself, but I can't find the cause of this one. At the installation, my module adds a tab in the order parameters. But here's the thing, I have the following result when I click on the tab : However, I followed this documentation to the letter: https://devdocs.prestashop.com/1.7/modules/concepts/controllers/admin-controllers/ Here is my code for the tab, in the main file orderpreparation.php : private function installTab(): bool { $tabId = (int) Tab::getIdFromClassName('AdminOrderPreparation'); if (!$tabId) { $tabId = null; } $tab = new Tab($tabId); $tab->active = 1; $tab->class_name = 'AdminOrderPreparation'; //$tab->route_name = 'admin_order_preparation'; $tab->name = array(); foreach (Language::getLanguages() as $lang) { $tab->name[$lang['id_lang']] = $this->trans('Order Preparation', array(), 'Modules.Orderpreparation.Admin', $lang['locale']); } $tab->id_parent = (int) Tab::getIdFromClassName('AdminParentOrders'); $tab->module = $this->name; return (bool) $tab->save(); } private function uninstallTab() { $tabId = (int) Tab::getIdFromClassName('AdminOrderPreparation'); if (!$tabId) { return true; } $tab = new Tab($tabId); return $tab->delete(); } My controller code : declare(strict_types=1); namespace Kaudaj\Module\OrderPreparation\Controller\Admin; use Doctrine\Common\Cache\CacheProvider; use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; use PrestaShopBundle\Security\Annotation\AdminSecurity; use Kaudaj\Module\OrderPreparation\Model\PreparationLine; use Kaudaj\Module\OrderPreparation\Repository\PreparationLineRepository; class AdminOrderPreparationController extends FrameworkBundleAdminController { private $cache; private $form_filename; /** * @var PreparationLinesRepository */ private $repository; public function __construct(CacheProvider $cache) { $this->cache = $cache; $this->repository = new PreparationLineRepository(); $this->form_filename = _PS_MODULE_DIR_ . $this->module->name . DIRECTORY_SEPARATOR . "orderpreparationform.html"; parent::__construct(); } /** * @AdminSecurity( * "is_granted('read', request.get('_legacy_controller'))", * message="You do not have permission to update this." * ) * * @return Response */ public function indexAction() { return $this->render( '@Modules/orderpreparation/views/templates/admin/orderpreparation.html.twig', array( "ajax_dl_link" => $this->context->link->getAdminLink($this->module->name) ) ); } } My routes.yml file : admin_order_preparation: path: /order-preparation methods: [GET] defaults: _controller: 'Kaudaj\Module\OrderPreparation\Controller\Admin\AdminOrderPreparationController::indexAction' And finally, my composer.json file : { "name": "kaudaj/order-preparation", "description": "Kaudaj - Order Preparation", "autoload": { "psr-4": { "Kaudaj\\Module\\OrderPreparation\\": "src/" }, "config": { "prepend-autoloader": false }, "type": "prestashop-module" } } If you need more information about the context or some code I didn't publish, feel free to ask me. Thank you in advance for your help! Link to comment Share on other sites More sharing options...
Vintelec Posted October 15, 2020 Author Share Posted October 15, 2020 So, I've made progress and here are my results: I tested the demo module "democontrollertabs" with two versions of PrestaShop : The 1.7.5.0, the version I currently use with my store. ==> Same result as with my module, i.e. the error "The controller is missing or invalid". The 1.7.7.0 beta 2, the last version released so far. ==> The demo module works correctly. On the other hand, my module always gives the same error. 🤯 I confess that I don't understand much anymore... I changed a couple of things in my code, precisely to get as close as possible to the demo module. By the way, it seems to me that I should add the vendor folder in the .gitignore ? I'm not going to stop there and keep searching for the science 😂 but any help will be welcome! Link to comment Share on other sites More sharing options...
Vintelec Posted October 23, 2020 Author Share Posted October 23, 2020 (edited) I was waiting to be sure, but it's good: I managed to get my module working! In 1.7.7.0, my template was not good. And for the previous versions, you have to add this for the main route, as specified in the doc : _legacy_controller: AdminOrderPreparation _legacy_link: AdminOrderPreparation I got fooled because the demo module didn't have them, except that it's made for 1.7.7.0 minimum so... my bad. I thought I had already tested with these lines though but there was probably another error at the same time. I didn't test for 1.7.5.0 because I'm using the new Grid system which requires 1.7.6, so I'm going to upgrade my store to 1.7.6.8. But I think it should work too. Good programming to all of you! Edited October 23, 2020 by Vintelec (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