diff --git a/src/Model/Variant/Collection.php b/src/Model/Variant/Collection.php index 307006f..1749d0a 100755 --- a/src/Model/Variant/Collection.php +++ b/src/Model/Variant/Collection.php @@ -253,9 +253,9 @@ protected function getIsReturnSingleChild($includeFilters = false) { protected function getChildCollectionMapAndList(): array { $childCollectionMap = []; $childProductsList = []; - - $parentIds = array_map(function ($product) { - return $product->getId(); + $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); + $parentIds = array_map(function ($product) use($linkField) { + return $product->getData($linkField); }, $this->parentProducts); $conn = $this->connection->getConnection(); @@ -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->getId(); + $parentId = $parentProduct->getData($linkField); $childIds = $childCollectionMap[$parentId]; foreach ($products as $childProduct) { - if (in_array($childProduct->getId(), $childIds, true)) { + if (in_array($childProduct->getData($linkField), $childIds, true)) { $productsToProcess[] = $childProduct; break; } @@ -385,10 +386,10 @@ protected function fetch($info) : array { ['isSingleProduct' => CriteriaCheck::isSingleProductFilter($this->searchCriteria)] ); + foreach ($this->parentProducts as $product) { - $parentId = $product->getId(); + $parentId = $product->getData($linkField); $childIds = $childCollectionMap[$parentId]; - $this->childrenMap[$parentId] = []; foreach ($childIds as $childId) { @@ -420,6 +421,10 @@ protected function fetchPlp($info) : array { return $this->childrenMap; } + + + $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); + [ $childProductsList, $childCollectionMap @@ -467,7 +472,7 @@ protected function fetchPlp($info) : array { continue; } - $productId = $product->getId(); + $productId = $product->getData($linkField); $productIds[] = $productId; // Create storage for future attributes @@ -492,16 +497,16 @@ protected function fetchPlp($info) : array { // Set stock status $stockStatusCallback($product); + $productsData[$product->getId()] = $product->getData() + [ - 'model' => $product, - 's_attributes' => $productAttributes[$productId] - ]; + 'model' => $product, + 's_attributes' => $productAttributes[$productId] + ]; } foreach ($this->parentProducts as $product) { - $parentId = $product->getId(); + $parentId = $product->getData($linkField); $childIds = $childCollectionMap[$parentId]; - $this->childrenMap[$parentId] = []; foreach ($childIds as $childId) {