/** * @param \Magento\CatalogRule\Model\Indexer\Product\ProductRuleIndexer $subject * @param \Closure $proceed * @param array $ids * * @return void */ public function aroundExecuteList(\Magento\CatalogRule\Model\Indexer\Product\ProductRuleIndexer $subject, \Closure $proceed, array $ids) { $configurableProductIds = $this->configurableProductsProvider->getIds($ids); $subProducts = $this->reindexSubProducts($configurableProductIds, $subject); $ids = array_diff($ids, $configurableProductIds, $subProducts); if ($ids) { $proceed($ids); } }
/** * @param \Magento\CatalogRule\Model\Rule $rule * @param array $productIds * @return array */ public function afterGetMatchingProductIds(\Magento\CatalogRule\Model\Rule $rule, array $productIds) { $configurableProductIds = $this->configurableProductsProvider->getIds(array_keys($productIds)); foreach ($configurableProductIds as $productId) { $subProductsIds = $this->configurable->getChildrenIds($productId)[0]; $parentValidationResult = $productIds[$productId]; foreach ($subProductsIds as $subProductsId) { $productIds[$subProductsId] = $this->getSubProductValidationResult($rule->getId(), $subProductsId, $parentValidationResult); } unset($productIds[$productId]); } return $productIds; }
/** * @param \Magento\CatalogRule\Model\Rule $rule * @param array $productIds * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetMatchingProductIds(\Magento\CatalogRule\Model\Rule $rule, array $productIds) { $configurableProductIds = $this->configurableProductsProvider->getIds(array_keys($productIds)); foreach ($configurableProductIds as $productId) { if (!isset($this->childrenProducts[$productId])) { $this->childrenProducts[$productId] = $this->configurable->getChildrenIds($productId)[0]; } $subProductIds = $this->childrenProducts[$productId]; $parentValidationResult = isset($productIds[$productId]) ? array_filter($productIds[$productId]) : []; foreach ($subProductIds as $subProductId) { $childValidationResult = isset($productIds[$subProductId]) ? array_filter($productIds[$subProductId]) : []; $productIds[$subProductId] = $parentValidationResult + $childValidationResult; } unset($productIds[$productId]); } return $productIds; }
/** * @return void */ public function testAfterGetMatchingProductIdsWithConfigurableProduct() { $this->configurableProductsProviderMock->expects($this->once())->method('getIds')->willReturn(['conf1', 'conf2']); $this->configurableMock->expects($this->any())->method('getChildrenIds')->willReturnMap([['conf1', true, [0 => ['simple1']]], ['conf2', true, [0 => ['simple1', 'simple2']]]]); $this->assertEquals(['simple1' => [0 => true, 1 => true, 3 => true, 4 => false], 'simple2' => [0 => false, 1 => false, 3 => true, 4 => false]], $this->configurableProductHandler->afterGetMatchingProductIds($this->ruleMock, ['conf1' => [0 => true, 1 => true], 'conf2' => [0 => false, 1 => false, 3 => true, 4 => false]])); }