Jump to content

Prestashop 1.7.8.11 | Override Admin OrderController


PatoPest0

Recommended Posts

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 :

https://devdocs.prestashop-project.org/1.7/modules/concepts/controllers/admin-controllers/override-decorate-controller/#override-the-controller

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 :

 

image.png.2c18d248994a4c35404a53f4d9f2f943.png

 

Can someone tell me if I made a mistake or if I am doing something wrong ?

Kind Regards,

PatoPest0

Edited by PatoPest0 (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...