Mehdib92 Posted September 19, 2022 Share Posted September 19, 2022 Hi, I'd like to know if it's possible to decorate a Presenter. I'd like to override a function in the CartPresenter (I think for my need it will be easier than using the hook) but when I do it I have the message Quote You have requested a non-existent service "PrestaShop\PrestaShop\Adapter\Presenter\Cart\CartPresenter". Is there a way to do that ? Thanks Link to comment Share on other sites More sharing options...
ps8modules Posted September 21, 2022 Share Posted September 21, 2022 use PrestaShop\PrestaShop\Adapter\Cart\CartPresenter; Link to comment Share on other sites More sharing options...
Mehdib92 Posted September 22, 2022 Author Share Posted September 22, 2022 It doesn't work, I have the message Quote You have requested a non-existent service "PrestaShop\PrestaShop\Adapter\Cart\CartPresenter". When I use bin/console debug:container, the CartPresenter is not listed, I think this is why it doesn't work Link to comment Share on other sites More sharing options...
ps8modules Posted September 22, 2022 Share Posted September 22, 2022 Hi. In order to get the correct answer, it is necessary to specify the exact version of Prestashop. Link to comment Share on other sites More sharing options...
Mehdib92 Posted September 22, 2022 Author Share Posted September 22, 2022 Sorry, I'm ont Prestashop 1.7.8.6 Link to comment Share on other sites More sharing options...
ps8modules Posted September 22, 2022 Share Posted September 22, 2022 Link to comment Share on other sites More sharing options...
ps8modules Posted September 22, 2022 Share Posted September 22, 2022 namespace = use use PrestaShop\PrestaShop\Adapter\Cart; Link to comment Share on other sites More sharing options...
Mehdib92 Posted September 22, 2022 Author Share Posted September 22, 2022 I will try thank you Link to comment Share on other sites More sharing options...
Mehdib92 Posted September 22, 2022 Author Share Posted September 22, 2022 (edited) I think I don't understand 100% how it works. I have created mymodule/src/Presenter/CartPresenter.php namespace Mfacilities\OrderExtras\Presenter; use Currency; use Order as PrestashopOrder; use OrderState; //use PrestaShop\PrestaShop\Adapter\Cart; class CartPresenter extends \PrestaShop\PrestaShop\Adapter\Presenter\Cart { public $cartPresenter; public function __construct(CartPresenter $cartPresenter) { $this->cartPresenter = $cartPresenter; } /** * @param Cart $cart * @param bool $shouldSeparateGifts * * @return array * * @throws \Exception */ public function present($cart, $shouldSeparateGifts = false) { die('TEST'); } } If in my config/services.yml I add : mycompany.mymodule.presenter.custom_cartpresenter: class: 'MyCompany\MyModule\Presenter\CartPresenter' arguments: - 'PrestaShop\PrestaShop\Adapter\Presenter\Cart\CartPresenter' If I try like that (with a composer dumpautoload and a cache clear before), nothing happen. Edited September 22, 2022 by Mehdib92 (see edit history) 1 Link to comment Share on other sites More sharing options...
ps8modules Posted September 22, 2022 Share Posted September 22, 2022 Hi. Please write me what you need to do so that we don't get confused 😉 1 Link to comment Share on other sites More sharing options...
Mehdib92 Posted September 22, 2022 Author Share Posted September 22, 2022 I added the filetype when a customer upload a file for the customization. And I need to modify the display depending the filetype. What I want to do is override the function addCustomizedData() in the PrestaShop\PrestaShop\Adapter\Presenter\Cart\CartPresenter to add the data everywhere. I could do it with the hook actionPresentCart but I also need it on several pages of the site that's why I want to override/decorate the CartPresenter 1 Link to comment Share on other sites More sharing options...
ps8modules Posted September 23, 2022 Share Posted September 23, 2022 I'm probably going to disappoint you, but it's unreal. Presenter cannot be overwritten like this. Even leading developers prefer to choose the path of using hooks and their own controllers. Here is a sample of how others solve it, for example: https://addons.prestashop.com/en/additional-information-product-tab/21373-files-upload-by-customer-from-product-cart-checkout.html 2 Link to comment Share on other sites More sharing options...
Mehdib92 Posted September 23, 2022 Author Share Posted September 23, 2022 Don't worry, you don't disappoint me, you just confirm what I was thinking. I just hoped that I was wrong And do you think it's the same for the PrestaShop\PrestaShop\Core\Domain\Order\QueryResult\OrderProductCustomizationForViewing ? 1 Link to comment Share on other sites More sharing options...
ps8modules Posted September 23, 2022 Share Posted September 23, 2022 Yes, same problem. Only hooks can be used. 1 Link to comment Share on other sites More sharing options...
Mehdib92 Posted September 23, 2022 Author Share Posted September 23, 2022 Ok thanks you 1 Link to comment Share on other sites More sharing options...
piotrmerton Posted April 20, 2023 Share Posted April 20, 2023 Hey @Mehdib92, have you had any progress with this approach? I am struggling to decorate Product Presenter and looking for some references to study how it can be achieved, since official docs don't cover this. Link to comment Share on other sites More sharing options...
JBW Posted April 25, 2023 Share Posted April 25, 2023 On 4/20/2023 at 3:08 PM, piotrmerton said: decorate Product Presenter a What exactly do you wanna do? Did you check hook actionPresentProduct? 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