Jump to content

Decorate a Presenter


Recommended Posts

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

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 by Mehdib92 (see edit history)
  • Like 1
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

  • Like 2
Link to comment
Share on other sites

  • 6 months later...

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...