Jump to content

Trouble overriding a Symfony service in PrestaShop 1.7


Recommended Posts

Hello there,

I'm writing a module that needs to override the ProductVirtual class (src/PrestaShopBundle/Form/Admin/Product/ProductVirtual.php).

As it is apparently a Symfony service, I'm trying to override it as instructed in the documentation.

To do that, I copied the original ProductVirtual.php file to modules/mymodule/ProductVirtual.php and replaced the namespace by MyModule and created the file modules/mymodule/config/services.yml with the following content:

services:
    form.type.product.virtual:
        class: MyModule\ProductVirtual
        arguments:
            - "@translator"
            - "@prestashop.adapter.legacy.context"
        parent: 'form.type.common_type'
        public: true
        tags:
            - { name: form.type }

However, what I get is a 500 error and the following exception:

Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Type error: Too few arguments to function PrestaShopBundle\Form\Admin\Product\ProductVirtual::__construct(), 0 passed in /bitnami/prestashop/vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php on line 92 and exactly 2 expected" at /bitnami/prestashop/src/PrestaShopBundle/Form/Admin/Product/ProductVirtual.php line 52

Of course, 2 arguments are expected by the ProductVirtual's constructor but this FormRegistry.getType() method calls the constructor with no argument. I can't find a way to correct the problem and I have no knowledge in Symfony. I really need some advice here.

Thanks! :)

Share this post


Link to post
Share on other sites
  • 2 weeks 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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More