6 declare(strict_types=1);
12 use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\CollectionFactory;
14 use Magento\Catalog\Model\ProductFactory;
27 private $childCollectionFactory;
42 private $productDataProvider;
47 private $metadataPool;
52 private $parentIds = [];
57 private $childrenMap = [];
72 CollectionFactory $childCollectionFactory,
78 $this->childCollectionFactory = $childCollectionFactory;
81 $this->productDataProvider = $productDataProvider;
82 $this->metadataPool = $metadataPool;
93 if (!in_array(
$id, $this->parentIds) && !empty($this->childrenMap)) {
94 $this->childrenMap = [];
95 $this->parentIds[] =
$id;
96 }
elseif (!in_array(
$id, $this->parentIds)) {
97 $this->parentIds[] =
$id;
109 $this->attributeCodes = array_replace($this->attributeCodes,
$attributeCodes);
120 $childrenMap = $this->fetch();
122 if (!isset($childrenMap[
$id])) {
126 return $childrenMap[
$id];
134 private function fetch() : array
136 if (empty($this->parentIds) || !empty($this->childrenMap)) {
137 return $this->childrenMap;
140 $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
141 foreach ($this->parentIds as
$id) {
143 $childCollection = $this->childCollectionFactory->create();
145 $product = $this->productFactory->create();
147 $childCollection->setProductFilter(
$product);
153 if (!isset($this->childrenMap[$parentId])) {
154 $this->childrenMap[$parentId] = [];
157 $this->childrenMap[$parentId][] = $formattedChild;
161 return $this->childrenMap;
elseif(isset( $params[ 'redirect_parent']))
addEavAttributes(array $attributeCodes)
__construct(CollectionFactory $childCollectionFactory, ProductFactory $productFactory, SearchCriteriaBuilder $searchCriteriaBuilder, DataProvider $productDataProvider, MetadataPool $metadataPool)
getChildProductsByParentId(int $id)