Shishir Dabhi Posted February 15, 2022 Share Posted February 15, 2022 I had implemented with override AdminOrder index page and unable to add custom block in view indexhtml.twig file and file is getting replace with new .html.twig file. Please anyone can help me out on showing custom block on order view page Below has been implemented with folder and file structure in modules. 1. config > routes.yml 2. module.php 3. src > Controller > Admin > CustomOrdersController.php 4. views>templates>admin>sell>order>index.html.twig 1. Routes.yml admin_orders_index: path: /sell/orders/ # POST is required because admin_order_index is also setup as the grid reset return route. methods: [GET,POST] defaults: _controller: 'module\Controller\Admin\CustomOrdersController::indexAction' _disable_module_prefix: true 2. CustomOrdersController.php <?php namespace module\Controller\Admin; if (!defined('_PS_VERSION_')) { die; } use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; use PrestaShopBundle\Security\Annotation\AdminSecurity; use PrestaShopBundle\Security\Annotation\ModuleActivated; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; class CustomOrdersController extends FrameworkBundleAdminController { /** * Shows list of orders * * @param Request $request * @param OrderFilters $filters * * @return Response */ public function indexAction(Request $request) { return $this->render( '@Modules/module/views/templates/admin/sell/order/index.html.twig', [ 'enableSidebar' => true, ] ); } } 3. index.html.twig {{ 'Hello world!' }} Link to comment Share on other sites More sharing options...
Rhobur Posted February 16, 2022 Share Posted February 16, 2022 You have to do it like describes in the docs here, https://devdocs.prestashop.com/1.7/modules/concepts/controllers/admin-controllers/override-decorate-controller/ Link to comment Share on other sites More sharing options...
Shishir Dabhi Posted February 16, 2022 Author Share Posted February 16, 2022 Thanks rhobur, can you help me out for services.yml file what contains need to be placed Link to comment Share on other sites More sharing options...
Rhobur Posted February 16, 2022 Share Posted February 16, 2022 services.yml: namespace.custom_order: class: 'PrestaShop\Module\ModuleName\Controller\Admin\Sell\Order\CustomOrderController' decorates: 'PrestaShopBundle\Controller\Admin\Sell\Order\OrderController' arguments: [ '@namespace.custom_order.inner' ] where namespace is your module namespace from composer and ModuleName is your module's name. CustomOrderController: /** * @var OrderController */ private $decoratedController; /** * CustomOrderController constructor. * * @param OrderController $decoratedController */ public function __construct(OrderController $decoratedController) { $this -> decoratedController = $decoratedController; } then follow up with the rest of the parent controller's methods and your own methods. Link to comment Share on other sites More sharing options...
Shishir Dabhi Posted February 16, 2022 Author Share Posted February 16, 2022 Thanks Rhobur... still not able to add custom block into it because controller is not getting called, please find below structure and respective file code, can you help and let me know what need to be corrected. Namespace = ABC moduleName = xyz --composer.json --config --services.yml --src --Controller --Admin --Sell --Order --CustomOrderController.php --views --templates --admin --sell --order --view.html.twig 1. composer.json { "name": "xyz/testmodule", "description": "Showcases how to override a Symfony controller route", "type": "prestashop-module", "authors": [ { "name": "XYZ", "email": "[email protected]" } ], "autoload": { "psr-4": { "xyz\\": "src/" }, "classmap": [ "xyz.php" ], "exclude-from-classmap": [] }, "config": { "preferred-install": "dist", "prepend-autoloader": false } } 2.services.yml ABC.custom_order: class: 'xyz\Controller\Admin\Sell\Order\CustomOrderController' decorates: 'PrestaShopBundle\Controller\Admin\Sell\Order\OrderController' arguments: [ '@ABC.custom_order.inner' ] 3. CustomOrderController.php ABC xyz\Controller\Admin\Sell\Order; if (!defined('_PS_VERSION_')) { die; } use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; use PrestaShopBundle\Security\Annotation\AdminSecurity; use PrestaShopBundle\Security\Annotation\ModuleActivated; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; class CustomOrdersController extends FrameworkBundleAdminController { /** * @var OrderController */ private $decoratedController; /** * CustomOrderController constructor. * * @param OrderController $decoratedController */ public function __construct(OrderController $decoratedController) { echo "sasas"; exit; $this->decoratedController = $decoratedController; } public function viewAction(int $orderId, Request $request) { echo $orderId; exit; return $this->render( '@Modules/xyz/views/templates/admin/view.html.twig' ); } } Link to comment Share on other sites More sharing options...
Rhobur Posted February 16, 2022 Share Posted February 16, 2022 you need to extend the core view.html.twig in your own view.html.twig by adding there your module's twig file; your viewAction should return the extended view.html.twig Link to comment Share on other sites More sharing options...
Shishir Dabhi Posted February 17, 2022 Author Share Posted February 17, 2022 I am unable to get into override Controller into __contruct() by services.yml file. Link to comment Share on other sites More sharing options...
Shishir Dabhi Posted February 17, 2022 Author Share Posted February 17, 2022 I want to override product_list.html.twig file, can you help me how we can do it. 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