Hi,
I would like to override a function inside OrderController located in src/PrestaShopBundle/Controller/Admin/Sell/Order using the following Prestashop DevDocs and the "Remap the route" section :
So I created a new module and put the routes.yml in a config folder :
admin_orders_send_process_order_email:
path: /process-order-email
methods: [POST]
defaults:
_controller: 'MaterCartTracker\Controller\Admin\CartTrackerOrderController::sendProcessOrderEmailAction'
_legacy_controller: 'AdminOrders'
_disable_module_prefix: true
I then proceeded to recreate the controller in src/Controller/Admin called CartTrackerOrderController.php, I used the original logic in this example to check if my override works :
<?php namespace MaterCartTracker\Controller\Admin; use PrestaShop\PrestaShop\Core\Domain\Order\Command\SendProcessOrderEmailCommand; use PrestaShop\PrestaShop\Adapter\Logger\LoggerInterface; use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Exception; class CartTrackerOrderController extends FrameworkBundleAdminController { /** * Sends email with process order link to customer * * @AdminSecurity("is_granted('update', request.get('_legacy_controller')) || is_granted('create', 'AdminOrders')") * * @param Request $request * * @return JsonResponse */ public function sendProcessOrderEmailAction(Request $request): JsonResponse { try { $this->getCommandBus()->handle(new SendProcessOrderEmailCommand($request->request->getInt('cartId'))); return $this->json([ 'message' => $this->trans('The email was sent to your customer.', 'Admin.Orderscustomers.Notification'), ]); } catch (Exception $e) { return $this->json( ['message' => $this->getErrorMessageForException($e, $this->getErrorMessages($e))], Response::HTTP_INTERNAL_SERVER_ERROR ); } } }
After clearing symfony cache using php bin/console cache:clear the route seems to be redirected (verified using php bin/console debug:router)
However when I try to create a cart and then proceed to send an email to the customer, the message is empty and no email is sent :
Can someone tell me if I made a mistake or if I am doing something wrong ?
Kind Regards,
PatoPest0