Skip to content

Commit a7d9ba5

Browse files
committed
ACP2E-3190: [Cloud] Products graphql having error when same simple product has assigned to multiple configurable products
- Initial Commit
1 parent 8fb1699 commit a7d9ba5

File tree

1 file changed

+12
-16
lines changed
  • app/code/Magento/ConfigurableProductGraphQl/Model/Variant

1 file changed

+12
-16
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use Exception;
1111
use Magento\Catalog\Api\Data\ProductInterface;
1212
use Magento\Catalog\Model\Product;
13-
use Magento\Catalog\Model\ResourceModel\Product\Collection as ChildCollection;
14-
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
13+
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection as ChildCollection;
14+
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\CollectionFactory;
1515
use Magento\Framework\EntityManager\MetadataPool;
1616
use Magento\Framework\Api\SearchCriteriaBuilder;
1717
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
@@ -126,7 +126,6 @@ public function addEavAttributes(array $attributeCodes) : void
126126
* @param ContextInterface $context
127127
* @param array $attributeCodes
128128
* @return array
129-
* @throws Exception
130129
*/
131130
public function getChildProductsByParentId(int $id, ContextInterface $context, array $attributeCodes) : array
132131
{
@@ -155,18 +154,16 @@ private function fetch(ContextInterface $context, array $attributeCodes) : array
155154

156155
/** @var ChildCollection $childCollection */
157156
$childCollection = $this->childCollectionFactory->create();
158-
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
157+
foreach ($this->parentProducts as $product) {
158+
$childCollection->setProductFilter($product);
159+
}
159160
$childCollection->addWebsiteFilter($context->getExtensionAttributes()->getStore()->getWebsiteId());
160-
$childCollection->getSelect()
161-
->columns(
162-
['parent_id' => new \Zend_Db_Expr('GROUP_CONCAT(`link_table`.parent_id)')]
163-
)
164-
->join(
165-
['link_table' => $childCollection->getTable('catalog_product_super_link')],
166-
'link_table.product_id = e.entity_id',
167-
[]
168-
)
169-
->group('e.' . $linkField);
161+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
162+
$childCollection->getSelect()->group('e.' . $linkField);
163+
$childCollection->getSelect()->columns([
164+
'parent_ids' => new \Zend_Db_Expr('GROUP_CONCAT(link_table.parent_id)')
165+
]);
166+
170167
$attributeCodes = array_unique(array_merge($this->attributeCodes, $attributeCodes));
171168

172169
$this->collectionProcessor->process(
@@ -183,8 +180,7 @@ private function fetch(ContextInterface $context, array $attributeCodes) : array
183180
continue;
184181
}
185182
$formattedChild = ['model' => $childProduct, 'sku' => $childProduct->getSku()];
186-
187-
$parentIds = preg_split ("/\,/", (string) $childProduct->getParentId());
183+
$parentIds = $childProduct->getParentIds() ? explode(',', $childProduct->getParentIds()) : [];
188184
foreach ($parentIds as $parentId) {
189185
if (!isset($this->childrenMap[$parentId])) {
190186
$this->childrenMap[$parentId] = [];

0 commit comments

Comments
 (0)