diff --git a/Helper/ProductIndexer.php b/Helper/ProductIndexer.php deleted file mode 100644 index df7af83..0000000 --- a/Helper/ProductIndexer.php +++ /dev/null @@ -1,51 +0,0 @@ -configurable = $configurable; - $this->productFactory = $productFactory; - } - - /** - * Returns parent entity id(s) - * - * @param $simpleProductId - * @return array - */ - public function getParentEntityId($simpleProductId): array - { - $parentIds = []; - $simpleProduct = $this->productFactory->create()->load($simpleProductId); - if ($simpleProduct->getTypeId() == 'simple') { - // Get the parent IDs of the simple product (configurable product IDs) - $parentIds = $this->configurable->getParentIdsByChild($simpleProductId); - } - return $parentIds; - } -} diff --git a/Model/Indexer/Category/ProductIndexer.php b/Model/Indexer/Category/ProductIndexer.php index f5d0c16..9c85fc6 100644 --- a/Model/Indexer/Category/ProductIndexer.php +++ b/Model/Indexer/Category/ProductIndexer.php @@ -9,9 +9,9 @@ use Aligent\PrerenderIo\Api\PrerenderClientInterface; use Aligent\PrerenderIo\Helper\Config; -use Aligent\PrerenderIo\Helper\ProductIndexer as ProductIndexerHelper; use Aligent\PrerenderIo\Model\Indexer\DataProvider\ProductCategories; use Aligent\PrerenderIo\Model\Url\GetUrlsForCategories; +use Magento\ConfigurableProduct\Model\Product\Type\Configurable; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Exception\LocalizedException; @@ -39,10 +39,8 @@ class ProductIndexer implements IndexerActionInterface, MviewActionInterface, Di private DeploymentConfig $eploymentConfig; /** @var Config */ private Config $prerenderConfigHelper; - /** - * @var ProductIndexerHelper - */ - private ProductIndexerHelper $productIndexerHelper; + /** @var Configurable */ + private Configurable $configurable; /** @var int|null */ private ?int $batchSize; @@ -63,7 +61,7 @@ public function __construct( PrerenderClientInterface $prerenderClient, DeploymentConfig $deploymentConfig, Config $prerenderConfigHelper, - ProductIndexerHelper $productIndexerHelper, + Configurable $configurable, ?int $batchSize = 1000 ) { $this->dimensionProvider = $dimensionProvider; @@ -73,7 +71,7 @@ public function __construct( $this->deploymentConfig = $deploymentConfig; $this->batchSize = $batchSize; $this->prerenderConfigHelper = $prerenderConfigHelper; - $this->productIndexerHelper = $this->productIndexerHelper; + $this->configurable = $configurable; } /** @@ -151,13 +149,11 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds): } $entityIds = iterator_to_array($entityIds); + // Include configurable product id(s) if the edited product is simple - foreach ($entityIds as $entityId) { - $parentEntityIds = $this->productIndexerHelper->getParentEntityId($entityId); - if (!empty($parentEntityIds)) { - $entityIds = array_merge($entityIds, $parentEntityIds); - } - } + $parentIds = $this->configurable->getParentIdsByChild($entityIds); + $entityIds = array_unique(array_merge($entityIds, $parentIds)); + // get list of category ids for the products $categoryIds = $this->productCategoriesDataProvider->getCategoryIdsForProducts($entityIds, $storeId); diff --git a/Model/Indexer/Product/ProductIndexer.php b/Model/Indexer/Product/ProductIndexer.php index 4c95e3e..0239eb8 100644 --- a/Model/Indexer/Product/ProductIndexer.php +++ b/Model/Indexer/Product/ProductIndexer.php @@ -9,8 +9,8 @@ use Aligent\PrerenderIo\Api\PrerenderClientInterface; use Aligent\PrerenderIo\Helper\Config; -use Aligent\PrerenderIo\Helper\ProductIndexer as ProductIndexerHelper; use Aligent\PrerenderIo\Model\Url\GetUrlsForProducts; +use Magento\ConfigurableProduct\Model\Product\Type\Configurable; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Exception\LocalizedException; @@ -36,10 +36,8 @@ class ProductIndexer implements IndexerActionInterface, MviewActionInterface, Di private DeploymentConfig $eploymentConfig; /** @var Config */ private Config $prerenderConfigHelper; - /** - * @var ProductIndexerHelper - */ - private ProductIndexerHelper $productIndexerHelper; + /** @var Configurable */ + private Configurable $configurable; /** @var int|null */ private ?int $batchSize; @@ -50,6 +48,8 @@ class ProductIndexer implements IndexerActionInterface, MviewActionInterface, Di * @param PrerenderClientInterface $prerenderClient * @param DeploymentConfig $deploymentConfig * @param Config $prerenderConfigHelper + * @param Configurable $configurable + * * @param int|null $batchSize */ public function __construct( @@ -58,7 +58,7 @@ public function __construct( PrerenderClientInterface $prerenderClient, DeploymentConfig $deploymentConfig, Config $prerenderConfigHelper, - ProductIndexerHelper $productIndexerHelper, + Configurable $configurable, ?int $batchSize = 1000 ) { $this->dimensionProvider = $dimensionProvider; @@ -67,7 +67,7 @@ public function __construct( $this->deploymentConfig = $deploymentConfig; $this->batchSize = $batchSize; $this->prerenderConfigHelper = $prerenderConfigHelper; - $this->productIndexerHelper = $productIndexerHelper; + $this->configurable = $configurable; } /** @@ -145,13 +145,11 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds): } $entityIds = iterator_to_array($entityIds); + // Include configurable product id(s) if the edited product is simple - foreach ($entityIds as $entityId) { - $parentEntityIds = $this->productIndexerHelper->getParentEntityId($entityId); - if (!empty($parentEntityIds)) { - $entityIds = array_merge($entityIds, $parentEntityIds); - } - } + $parentIds = $this->configurable->getParentIdsByChild($entityIds); + $entityIds = array_unique(array_merge($entityIds, $parentIds)); + // get urls for the products $urls = $this->getUrlsForProducts->execute($entityIds, $storeId);