6 declare(strict_types=1);
11 use Magento\Bundle\Model\OptionFactory;
23 private $bundleOptionFactory;
28 private $extensionAttributesJoinProcessor;
33 private $storeManager;
43 private $optionMap = [];
51 OptionFactory $bundleOptionFactory,
56 $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
68 $this->skuMap[$parentId] = [
'sku' => $sku,
'entity_id' => $parentEntityId];
92 private function fetch() : array
94 if (empty($this->skuMap) || !empty($this->optionMap)) {
95 return $this->optionMap;
99 $optionsCollection = $this->bundleOptionFactory->create()->getResourceCollection();
101 $optionsCollection->joinValues($this->storeManager->getStore()->getId());
103 $productTable = $optionsCollection->getTable(
'catalog_product_entity');
104 $linkField = $optionsCollection->getConnection()->getAutoIncrementField($productTable);
105 $optionsCollection->getSelect()->join(
106 [
'cpe' => $productTable],
107 'cpe.'.$linkField.
' = main_table.parent_id',
110 "cpe.entity_id IN (?)",
113 $optionsCollection->setPositionOrder();
115 $this->extensionAttributesJoinProcessor->process($optionsCollection);
116 if (empty($optionsCollection->getData())) {
121 foreach ($optionsCollection as
$option) {
122 if (!isset($this->optionMap[
$option->getParentId()])) {
123 $this->optionMap[
$option->getParentId()] = [];
126 $this->optionMap[
$option->getParentId()][
$option->getId()][
'title']
129 = $this->skuMap[
$option->getParentId()][
'sku'];
132 return $this->optionMap;
addParentFilterData(int $parentId, int $parentEntityId, string $sku)
__construct(OptionFactory $bundleOptionFactory, JoinProcessorInterface $extensionAttributesJoinProcessor, StoreManagerInterface $storeManager)
getOptionsByParentId(int $parentId)