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

used product link from metadataPool instead of getId for Adobe commerce #142

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/Model/Variant/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ protected function getChildCollectionMapAndList(): array {
$childProductsList = [];

$parentIds = array_map(function ($product) {
return $product->getId();
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and in other places: only load $linkField ones, there is no need to check it inside each array/foreach iteration, it will not change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aleksandrsm Updated the changes, please check

return $product->getData($linkField);
}, $this->parentProducts);

$conn = $this->connection->getConnection();
Expand Down Expand Up @@ -386,7 +387,8 @@ protected function fetch($info) : array {
);

foreach ($this->parentProducts as $product) {
$parentId = $product->getId();
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$parentId = $product->getData($linkField);
$childIds = $childCollectionMap[$parentId];

$this->childrenMap[$parentId] = [];
Expand Down Expand Up @@ -420,6 +422,8 @@ protected function fetchPlp($info) : array {
return $this->childrenMap;
}

$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();

[
$childProductsList,
$childCollectionMap
Expand Down Expand Up @@ -467,7 +471,7 @@ protected function fetchPlp($info) : array {
continue;
}

$productId = $product->getId();
$productId = $product->getData($linkField);
$productIds[] = $productId;

// Create storage for future attributes
Expand All @@ -492,14 +496,15 @@ protected function fetchPlp($info) : array {
// Set stock status
$stockStatusCallback($product);

$productsData[$product->getId()] = $product->getData() + [
'model' => $product,
's_attributes' => $productAttributes[$productId]
];

$productsData[$product->getData($linkField)] = $product->getData() + [
'model' => $product,
's_attributes' => $productAttributes[$productId]
];
}

foreach ($this->parentProducts as $product) {
$parentId = $product->getId();
$parentId = $product->getData($linkField);
$childIds = $childCollectionMap[$parentId];

$this->childrenMap[$parentId] = [];
Expand Down