Busted Posted March 3, 2021 Share Posted March 3, 2021 Hello everyone I would like to know if anybody has tried to decorate a controller ? I made a test with the symfony way to decorate a core controller in a custom module. The point was to caught the "toggleStatusAction" when you click on the active icon in the customers list (BO) . I followed the prestashop documentation to do so. So as precised I wrote a service.yml in a config folder: services: custom_controller: class: Test\CustomerDecoration\Controller\NotificationController decorates: PrestaShopBundle\Controller\Admin\Sell\Customer\CustomerController arguments: ['@custom_controller.inner'] Here's my class : <?php namespace Test\CustomerDecoration\Controller; use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; use PrestaShopBundle\Controller\Admin\Sell\Customer\CustomerController; /* Here every others use statements but I removed them for clarity */ class NotificationController extends FrameworkBundleAdminController { /** * @var CustomerController */ private $decoratedController; public function __construct(CustomerController $decoratedController) { $this->decoratedController = $decoratedController; } public function toggleStatusAction($customerId) { var_dump($customerId);die; return $this->decoratedController->toggleStatusAction($customerId); } } I use composer to load my Class and... it worked fine. Somehow. Except this error on the Customer index in the BO : When I declare this method in my NotificationController it works : public function indexAction(Request $request, CustomerFilters $filters) { return $this->decoratedController->indexAction($request, $filters); } But for every other action (edit, view etc) I have to re-declare every methods. So two differents situations : 1 ) I did something wrong with my code. My bad. 2 ) I did well, which means that everytime we have to decorate a controller, we have to declare again almost every methods ? With "old" override system we just have to extends the Class, and add/modify methods and/or attributes. Again if I did right, it's going to be a pain to code in my opinion. So now I'm stuck between those two statements, and I don't know which one is the good one. If anybody has an answer to that, I'll very interested. Link to comment Share on other sites More sharing options...
dichkovsky Posted May 12, 2021 Share Posted May 12, 2021 It could be that you need to extend CustomerController instead of FrameworkBundleAdminController Link to comment Share on other sites More sharing options...
Guillaume73 Posted December 31, 2021 Share Posted December 31, 2021 Hi Busted, I'm facing the same problem. Did you solve it ? Thanks for your help. Guillaume Link to comment Share on other sites More sharing options...
Busted Posted January 3, 2022 Author Share Posted January 3, 2022 (edited) On 12/31/2021 at 8:46 PM, Guillaume73 said: Hi Busted, I'm facing the same problem. Did you solve it ? Thanks for your help. Guillaume Hi Guillaume, Not yet but I'm going to take a course for a prestashop symfony/backend formation this month, and I'll ask the formator about that. I'll update my answer here, but you'll have to wait at least three weeks Edited January 3, 2022 by Busted (see edit history) Link to comment Share on other sites More sharing options...
Inform-All Posted January 28, 2022 Share Posted January 28, 2022 Please share your module composer.json Link to comment Share on other sites More sharing options...
RémiM Posted April 8, 2022 Share Posted April 8, 2022 Hi Busted, I have the same problem. Do you have any new information ? Thanks for your help. Rémi Link to comment Share on other sites More sharing options...
Busted Posted April 29, 2022 Author Share Posted April 29, 2022 On 12/31/2021 at 8:46 PM, Guillaume73 said: Hi Busted, I'm facing the same problem. Did you solve it ? Thanks for your help. Guillaume On 12/31/2021 at 8:46 PM, Guillaume73 said: Hi Busted, I'm facing the same problem. Did you solve it ? Thanks for your help. Guillaume Sorry I totally forgot, and the notification went in my spam box. So it seems that based in my example, you have to extend CustomerController instead of FrameworkBundleAdminController. So yeah, Dichkovky got the right answer but I haven't tested yet, you can try it by yourself. If I have the needs to do the same, I'll post my results 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