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

Missing data on API #2281

Open
Schrank opened this issue Jan 22, 2022 · 0 comments
Open

Missing data on API #2281

Schrank opened this issue Jan 22, 2022 · 0 comments
Labels

Comments

@Schrank
Copy link
Contributor

Schrank commented Jan 22, 2022

PHP Version

PHP 7.4.26 (cli) (built: Nov 22 2021 09:47:55) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.26, Copyright (c), by Zend Technologies with Xdebug v3.0.3, Copyright (c) 2002-2021, by Derick Rethans

Shopware Version

v6.4.7.0 Stable Version

Expected behaviour

When I add an association to a product like this:

criteria.getAssociation('seoUrls').addAssociation('salesChannel.domains')

Then I expect the response from the API to include all domains on the salesChannel.

Actual behaviour

The domain is missing.

How to reproduce

const {Criteria} = Shopware.Data;

Shopware.Component.override('sw-product-detail',
    {
        computed: {
            productCriteria() {
                const criteria = this.$super('productCriteria');
//                criteria.addAssociation('visibilities.salesChannel.domains'); // FIX
                criteria.getAssociation('seoUrls')
                    .addAssociation('salesChannel.domains')
                    .addAssociation('language');

                return criteria;
            }
        }
    }
);

And then have a look into the network tab.

Problem

The problems originates most likely here:

\Shopware\Core\Framework\Api\Serializer\JsonApiEncoder::serializeEntity

If I remove the first lines, then the missing domain is there.

protected function serializeEntity(ResponseFields $fields, Entity $entity, EntityDefinition $definition, JsonApiEncodingResult $result, bool $isRelationship = false): void
{
//        if ($result->containsInData($entity->getUniqueIdentifier(), $definition->getEntityName())
//            || ($isRelationship && $result->containsInIncluded($entity->getUniqueIdentifier(), $definition->getEntityName()))
//        ) {
//            return;
//        }

So I guess you try to avoid serializing an entity twice, but if the first entity doesn't contain the data, then the data is missing down another branch the entity-tree.

E.g. product -> visibilities -> salesChannel does not contain domains
product -> seoUrls -> salesChannel -> domains contain the domains

But because the first salesChannel was already added, the second is skipped.

Workaround

As expected, with criteria.addAssociation('visibilities.salesChannel.domains'); as a workaround the domains are added in the beginning and therefore not a wrong caching instance is used.

@Schrank Schrank added the Bug label Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant