Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctrine enable_lazy_ghost_objects option breaks Sylius translation #901

Open
jbcr opened this issue Jun 25, 2024 · 0 comments
Open

Doctrine enable_lazy_ghost_objects option breaks Sylius translation #901

jbcr opened this issue Jun 25, 2024 · 0 comments
Labels
Bug Confirmed bugs or bugfixes.

Comments

@jbcr
Copy link

jbcr commented Jun 25, 2024

Sylius version affected: 1.12.0 to 1.13.2

Description

Hello, I'm upgrading a project from Sylius 1.12 to 1.13.2.

During the upgrade, I have set the enable_lazy_ghost_objects to true to remove deprecation.

But, if enable_lazy_ghost_objects is true I have an error when I try to access Sylius Ressource translation from a relation.

Related Issue : doctrine/DoctrineBundle#1809

Steps to reproduce

I added a new entity (resource) named Tag with a one-to-many relation to Product.

When I execute $tag->getFirstProduct()->getTranslation()->getName(); the exception is thrown because the product is not loaded.

When enable_lazy_ghost_objects is false, the proxy has a method to initialize the product entity on getTranslation() call.

When enable_lazy_ghost_objects is true, the proxy does not intercept the function call and the object is not loaded.
I must call a getter manually to force the object data loading before call getTranslation().

Possible Solution

Check if the object is initialized and try access to the translations property to force data loading.

Work when I add this code into vendor/sylius/resource-bundle/src/Component/Model/TranslatableTrait.php line 50

        if (!isset($this->currentLocale)) {
            $this->getTranslations();
        }
@mpysiak mpysiak transferred this issue from Sylius/Sylius Jul 12, 2024
@mpysiak mpysiak added the Bug Confirmed bugs or bugfixes. label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed bugs or bugfixes.
Projects
None yet
Development

No branches or pull requests

2 participants