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 associated entities with same type in repository requests #89

Open
Kai-Dittberner opened this issue Jun 16, 2024 · 0 comments
Open

Comments

@Kai-Dittberner
Copy link

Kai-Dittberner commented Jun 16, 2024

Simple example: Loading categories from Shopware API, children array is empty, even with child categories in Shopware.
Example categories in Shopware are: "Home" and 12 child categories: "Bäume", "Sträucher", "Bodendecker" etc.

If I load the categories with paging like this:

$grantType = new ClientCredentialsGrantType($clientId, $clientSecret);
$adminClient = new AdminAuthenticator($grantType, $shopUrl);
$accessToken=$adminClient->fetchAccessToken();

$context=new Context($shopUrl, $accessToken);
$repository = RepositoryFactory::create(CategoryDefinition::ENTITY_NAME);

$criteria = new Criteria();
$criteria->setLimit(100);
$criteria->setPage(1);
$criteria->setTotalCountMode(Criteria::TOTAL_COUNT_MODE_NEXT_PAGES);

$criteria->addAssociation("children");
$criteria->getAssociation("children")->setLimit(null);

$result=$repository->search($criteria, $context);
echo("Count: ".$result->count(). PHP_EOL. PHP_EOL);
$categoryCollection = $result->getEntities();
foreach ($categoryCollection as $category) {
    echo("Category-ID:" . $category->id . ", Name: ".$category->name . PHP_EOL);
    if($category->children) {
       foreach ($category->children as $child) {
           echo("Child-Category-ID:" . $child->id . ", Name: ".$child->name . PHP_EOL);
       }
    } else {
        echo("no childs".PHP_EOL);
    }
    echo(PHP_EOL);
}

The result looks like

Count: 13

Category-ID:018e84ee474e73fdbe3c7e74717acecc, Name: Home

Category-ID:018f86ee17a97a83aa229b36903cf952, Name: Bäume
no childs

Category-ID:018f86ee7ac772a7b4b93b1cd19c1bbf, Name: Sträucher
no childs

Category-ID:018f86ee80ff7ed989aa2aa7dfc0ddb3, Name: Bodendecker
no childs

Category-ID:018f86ee9a337ae4abad16e97e2eb3d9, Name: Heckenpflanzen
no childs

Category-ID:018f86eeb0db750a8b5118b195a3fc93, Name: Wasserpflanzen
no childs

Category-ID:018f86eeca2271d0b4e337ed212b2a27, Name: Kräuter
no childs

Category-ID:018f86eedaf171c9bf5cd6a047adac4e, Name: Stauden
no childs

Category-ID:018f86eeeb5279f081c59b67b67a4947, Name: Blumenzwiebeln
no childs

Category-ID:018f86ef08f072868c97c4ccd085f8db, Name: Kletterpflanzen
no childs

Category-ID:018f86ef1f1d7e7383ad7ceec97fab2a, Name: Obstgehölze
no childs

Category-ID:018f86ef4bfa7610902d5b9876908222, Name: Ziergehölze
no childs

Category-ID:018f86ef5a2e7c0ab515c67dcc3cc1a5, Name: Zimmerpflanzen
no childs

The first children array should contain the child categories of "Home", but it is empty.

But if I change setLimit to (10) I got this:

Count: 10

Category-ID:018e84ee474e73fdbe3c7e74717acecc, Name: Home
Child-Category-ID:018f86ef1f1d7e7383ad7ceec97fab2a, Name: Obstgehölze
Child-Category-ID:018f86ef4bfa7610902d5b9876908222, Name: Ziergehölze
Child-Category-ID:018f86ef5a2e7c0ab515c67dcc3cc1a5, Name: Zimmerpflanzen

Category-ID:018f86ee17a97a83aa229b36903cf952, Name: Bäume
no childs

Category-ID:018f86ee7ac772a7b4b93b1cd19c1bbf, Name: Sträucher
no childs

Category-ID:018f86ee80ff7ed989aa2aa7dfc0ddb3, Name: Bodendecker
no childs

Category-ID:018f86ee9a337ae4abad16e97e2eb3d9, Name: Heckenpflanzen
no childs

Category-ID:018f86eeb0db750a8b5118b195a3fc93, Name: Wasserpflanzen
no childs

Category-ID:018f86eeca2271d0b4e337ed212b2a27, Name: Kräuter
no childs

Category-ID:018f86eedaf171c9bf5cd6a047adac4e, Name: Stauden
no childs

Category-ID:018f86eeeb5279f081c59b67b67a4947, Name: Blumenzwiebeln
no childs

Category-ID:018f86ef08f072868c97c4ccd085f8db, Name: Kletterpflanzen
no childs

And if I only load the first category with setLimit(1), all children are included.

Possible reason?
In the response from Shopware, the "included" key only includes category objects, which are not already in the "data" key. And the hydrateToMany function only hydrate the "included" json objects.
This is maybe very special, because the included entities are from the same type (both Category). But this can also occur in other requests with linked entities from same type, like in products.

Or did I missed something?

Thanks and best regards
Kai

@Kai-Dittberner Kai-Dittberner changed the title Missing associated entities in repository requests with limit set Missing associated entities with same type in repository requests Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant