Brille24 / SyliusCustomOptionsPlugin

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

CustomerOption targetEntity must be the CustomerOptionInterface on CustomerOptionTranslation Entity #152

Closed mbutl closed 4 months ago

mbutl commented 4 months ago

To be able to add custom fields on CustomerOptionValue and CustomerOption entiies, i overwrite these classes and use the following doctrine configuration to use my new entities :

        resolve_target_entities:
            Brille24\SyliusCustomerOptionsPlugin\Entity\CustomerOptions\CustomerOptionValueInterface: App\Entity\CustomerOption\CustomerOptionValue
            Brille24\SyliusCustomerOptionsPlugin\Entity\CustomerOptions\CustomerOptionInterface: App\Entity\CustomerOption\CustomerOption

However, for the CustomerOption, i have this error :

[Doctrine\ORM\ORMInvalidArgumentException]                                                                                                                                                               
  Expected value of type "Brille24\SyliusCustomerOptionsPlugin\Entity\CustomerOptions\CustomerOption" for association field "Brille24\SyliusCustomerOptionsPlugin\Entity\CustomerOptions\CustomerOptionTr  
  anslation#$translatable", got "App\Entity\CustomerOption\CustomerOption" instead.

After checking join configuration in CustomerOptionTranslation entity, i see that:

#[ORM\ManyToOne(targetEntity: CustomerOption::class, inversedBy: 'translations')]
#[ORM\JoinColumn(onDelete: 'CASCADE')]
protected ?TranslatableInterface $translatable = null;

The CustomerOptionInterface must be used here

#[ORM\ManyToOne(targetEntity: CustomerOptionInterface::class, inversedBy: 'translations')]
#[ORM\JoinColumn(onDelete: 'CASCADE')]
protected ?TranslatableInterface $translatable = null;
mamazu commented 4 months ago

Hey thank you for reporting this bug. We haven't tested this use case. But if you have made it work with your setup like this feel free to create a pull request. I'd be happy to merge it.

mbutl commented 4 months ago

Hello, thank you for your answer.

I was actually able to test this modification with my setup (directly in vendor ^^)

I would like to create the pull request, but I don't have the permissions to do so.

mamazu commented 4 months ago

That's good to hear. While working in the vendor directory is great for testing changes its a little tricky to push from there. Because by default composer clones this repository into the vendor directory (which you don't have write access to). What you would need to do is fork this repository, put the changes in the fork and then create a pull request from your fork to this repository.

If you need any further explanation feel free to say so.

mbutl commented 4 months ago

Thanks for the explanation.

There is the pull request https://github.com/Brille24/SyliusCustomOptionsPlugin/pull/153

mamazu commented 4 months ago

Closing this here as the PR is merged. If you still have issues with it feel free to open this again.