Brille24 / SyliusCustomOptionsPlugin

A Sylius plugin that adds customer options
MIT License
46 stars 34 forks source link

Import prices URL in Admin is broken #135

Closed bellu closed 11 months ago

bellu commented 1 year ago

I'm using Sylius 1.10.9 with php 7.4.20.

I tried to upload the prices from this URL -> /admin/customer-options/import-prices but i got this error:

"brille24.sylius_customer_options_plugin.controller.price_import_controller" has no container set, did you forget to define it as a service subscriber?

I saw that there's a similar issue https://github.com/Brille24/SyliusCustomOptionsPlugin/issues/111 but it refers to another URL.

How can i solve this?

mamazu commented 1 year ago

Hey, thanks for bringing this up. It looks like you are using an older version of php and Sylius. Would you mind checking for me which Symfony version you are running?

We definitely need to update this class anyways to not require a container but that is probably not going to help you right now.

bellu commented 1 year ago

The Symfony version is the 5.4.22. We've already scheduled an update for this e-commerce, in the meantime can you give any clue to fix this? Thanks

mamazu commented 1 year ago

Hm strange, it should work with 5.4.22.

What you could do as a quick and dirty fix is to add a method call to this service and set the container. You will probably have to copy the configuration from the bundle for this service and add a call to setContainer like described here: https://symfony.com/doc/5.4/service_container/calls.html

bellu commented 1 year ago

@mamazu Thanks for your suggestions, but the service container call seems not working

    Brille24\SyliusCustomerOptionsPlugin\Importer\CustomerOptionPriceImporterInterface: '@brille24.sylius_customer_options_plugin.importer.customer_option_price_importer'
    Brille24\SyliusCustomerOptionsPlugin\Handler\ImportErrorHandlerInterface: '@brille24.sylius_customer_options_plugin.handler.csv_import_error_handler'

    brille24_customer_option_price_import:
        class: Brille24\SyliusCustomerOptionsPlugin\Controller\PriceImportController
        arguments:
            $csvExampleFilePath: '%brille24.sylius_customer_options.price_import_example_file_path%'
        calls:
            - [ setContainer, [ "@service_container" ] ]

So i created a new controller, just a copy paste in my project with this configuration:

    Brille24\SyliusCustomerOptionsPlugin\Importer\CustomerOptionPriceImporterInterface: '@brille24.sylius_customer_options_plugin.importer.customer_option_price_importer'
    Brille24\SyliusCustomerOptionsPlugin\Handler\ImportErrorHandlerInterface: '@brille24.sylius_customer_options_plugin.handler.csv_import_error_handler'

       App\Controller\Admin\CustomPriceImportController:
        arguments:
            $csvExampleFilePath: '%brille24.sylius_customer_options.price_import_example_file_path%'
        autowire: true 

PS: you need to add the annotations to the controller, something like this:

/**
 * @Route("/admin/customer-options/import-prices", name="admin_custom_import_prices")
 */
class CustomPriceImportController extends AbstractController
...

I know that it's a dirty trick, but it's working.

seizan8 commented 1 year ago

@bellu what version of SyliusCustomerOptionsPlugin are you using?

mamazu commented 1 year ago

Thanks for sharing the solution to your problem (that's what I had in mind as well. We definitely want to move to autowiring, auto configuring and route attributes in the future. If you want you can contribute this change in a PR that would be nice.

bellu commented 1 year ago

@seizan8 i'm using v3.0.1. @mamazu yes i can, i think i can do this in the next week.

mamazu commented 1 year ago

If you want you can also try out this MR there I moved some of the routes to the new attribute configuration. #137