From b240eaa0220a0f2509969a9969a2b244d43517ba Mon Sep 17 00:00:00 2001 From: NavaneethVijay Date: Thu, 15 Sep 2022 22:51:36 +0530 Subject: [PATCH 1/4] used product link from metadataPool instead of getId for Adobe commerce --- src/Model/Variant/Collection.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Model/Variant/Collection.php b/src/Model/Variant/Collection.php index 307006f..0f10bca 100755 --- a/src/Model/Variant/Collection.php +++ b/src/Model/Variant/Collection.php @@ -255,7 +255,8 @@ protected function getChildCollectionMapAndList(): array { $childProductsList = []; $parentIds = array_map(function ($product) { - return $product->getId(); + $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); + return $product->getData($linkField); }, $this->parentProducts); $conn = $this->connection->getConnection(); @@ -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] = []; @@ -420,6 +422,8 @@ protected function fetchPlp($info) : array { return $this->childrenMap; } + $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); + [ $childProductsList, $childCollectionMap @@ -467,7 +471,7 @@ protected function fetchPlp($info) : array { continue; } - $productId = $product->getId(); + $productId = $product->getData($linkField); $productIds[] = $productId; // Create storage for future attributes @@ -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] = []; From f0ce207a713b86e73afd3e36e814d4a355d98c47 Mon Sep 17 00:00:00 2001 From: NavaneethVijay Date: Thu, 22 Sep 2022 12:02:54 +0530 Subject: [PATCH 2/4] moved fetching of link type out from array loops --- src/Model/Variant/Collection.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Model/Variant/Collection.php b/src/Model/Variant/Collection.php index 0f10bca..9ea8fe9 100755 --- a/src/Model/Variant/Collection.php +++ b/src/Model/Variant/Collection.php @@ -253,9 +253,8 @@ protected function getIsReturnSingleChild($includeFilters = false) { protected function getChildCollectionMapAndList(): array { $childCollectionMap = []; $childProductsList = []; - - $parentIds = array_map(function ($product) { - $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); + $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); + $parentIds = array_map(function ($product) use($linkField) { return $product->getData($linkField); }, $this->parentProducts); @@ -386,11 +385,11 @@ protected function fetch($info) : array { ['isSingleProduct' => CriteriaCheck::isSingleProductFilter($this->searchCriteria)] ); + $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); + foreach ($this->parentProducts as $product) { - $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); $parentId = $product->getData($linkField); $childIds = $childCollectionMap[$parentId]; - $this->childrenMap[$parentId] = []; foreach ($childIds as $childId) { From 82efafba78b02e4a25aad1dbbd4a057eb9dafce1 Mon Sep 17 00:00:00 2001 From: NavaneethVijay Date: Fri, 23 Sep 2022 10:20:27 +0530 Subject: [PATCH 3/4] fixed wrong mapping for variants in plp query --- src/Model/Variant/Collection.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Model/Variant/Collection.php b/src/Model/Variant/Collection.php index 9ea8fe9..e1ad2ef 100755 --- a/src/Model/Variant/Collection.php +++ b/src/Model/Variant/Collection.php @@ -364,11 +364,11 @@ protected function fetch($info) : array { if ($isReturnSingleChild) { foreach ($this->parentProducts as $parentProduct) { - $parentId = $parentProduct->getId(); + $parentId = $parentProduct->getData('row_id'); $childIds = $childCollectionMap[$parentId]; foreach ($products as $childProduct) { - if (in_array($childProduct->getId(), $childIds, true)) { + if (in_array($childProduct->getData("row_id"), $childIds, true)) { $productsToProcess[] = $childProduct; break; } @@ -421,6 +421,8 @@ protected function fetchPlp($info) : array { return $this->childrenMap; } + + $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); [ @@ -496,7 +498,7 @@ protected function fetchPlp($info) : array { $stockStatusCallback($product); - $productsData[$product->getData($linkField)] = $product->getData() + [ + $productsData[$product->getId()] = $product->getData() + [ 'model' => $product, 's_attributes' => $productAttributes[$productId] ]; @@ -505,7 +507,6 @@ protected function fetchPlp($info) : array { foreach ($this->parentProducts as $product) { $parentId = $product->getData($linkField); $childIds = $childCollectionMap[$parentId]; - $this->childrenMap[$parentId] = []; foreach ($childIds as $childId) { From 2759ec3bc959fe783b045fbbbaef56ddbef724e6 Mon Sep 17 00:00:00 2001 From: NavaneethVijay Date: Fri, 23 Sep 2022 10:27:12 +0530 Subject: [PATCH 4/4] added missing linktype --- src/Model/Variant/Collection.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Model/Variant/Collection.php b/src/Model/Variant/Collection.php index e1ad2ef..1749d0a 100755 --- a/src/Model/Variant/Collection.php +++ b/src/Model/Variant/Collection.php @@ -336,6 +336,7 @@ protected function fetch($info) : array { $childCollectionMap ] = $this->getChildCollectionMapAndList(); + $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); $collection = $this->collectionFactory->create(); $isReturnSingleChild = $this->getIsReturnSingleChild(true); $searchCriteria = $this->getSearchCriteria($childProductsList, $isReturnSingleChild); @@ -364,11 +365,11 @@ protected function fetch($info) : array { if ($isReturnSingleChild) { foreach ($this->parentProducts as $parentProduct) { - $parentId = $parentProduct->getData('row_id'); + $parentId = $parentProduct->getData($linkField); $childIds = $childCollectionMap[$parentId]; foreach ($products as $childProduct) { - if (in_array($childProduct->getData("row_id"), $childIds, true)) { + if (in_array($childProduct->getData($linkField), $childIds, true)) { $productsToProcess[] = $childProduct; break; } @@ -385,7 +386,6 @@ protected function fetch($info) : array { ['isSingleProduct' => CriteriaCheck::isSingleProductFilter($this->searchCriteria)] ); - $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); foreach ($this->parentProducts as $product) { $parentId = $product->getData($linkField);