Skip to content

Commit

Permalink
Merge pull request #10 from aligent/feature/BEG-143_trigger_recaching…
Browse files Browse the repository at this point in the history
…_when_child_variant_is_edited

BEG-143: Trigger re-caching when child variant is edited #9
  • Loading branch information
aligent-lturner authored Feb 21, 2024
2 parents 372584e + c46f848 commit 0204925
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Model/Indexer/Category/ProductIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Aligent\Prerender\Helper\Config;
use Aligent\Prerender\Model\Indexer\DataProvider\ProductCategories;
use Aligent\Prerender\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;
Expand Down Expand Up @@ -38,6 +39,8 @@ class ProductIndexer implements IndexerActionInterface, MviewActionInterface, Di
private DeploymentConfig $eploymentConfig;
/** @var Config */
private Config $prerenderConfigHelper;
/** @var Configurable */
private Configurable $configurable;
/** @var int|null */
private ?int $batchSize;

Expand All @@ -49,6 +52,7 @@ 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(
Expand All @@ -58,6 +62,7 @@ public function __construct(
PrerenderClientInterface $prerenderClient,
DeploymentConfig $deploymentConfig,
Config $prerenderConfigHelper,
Configurable $configurable,
?int $batchSize = 1000
) {
$this->dimensionProvider = $dimensionProvider;
Expand All @@ -67,6 +72,7 @@ public function __construct(
$this->deploymentConfig = $deploymentConfig;
$this->batchSize = $batchSize;
$this->prerenderConfigHelper = $prerenderConfigHelper;
$this->configurable = $configurable;
}

/**
Expand Down Expand Up @@ -144,6 +150,11 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds):
}

$entityIds = iterator_to_array($entityIds);

// Include configurable product id(s) if the edited product is simple
$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);

Expand Down
10 changes: 10 additions & 0 deletions Model/Indexer/Product/ProductIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Aligent\Prerender\Api\PrerenderClientInterface;
use Aligent\Prerender\Helper\Config;
use Aligent\Prerender\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;
Expand All @@ -35,6 +36,8 @@ class ProductIndexer implements IndexerActionInterface, MviewActionInterface, Di
private DeploymentConfig $eploymentConfig;
/** @var Config */
private Config $prerenderConfigHelper;
/** @var Configurable */
private Configurable $configurable;
/** @var int|null */
private ?int $batchSize;

Expand All @@ -45,6 +48,7 @@ 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(
Expand All @@ -53,6 +57,7 @@ public function __construct(
PrerenderClientInterface $prerenderClient,
DeploymentConfig $deploymentConfig,
Config $prerenderConfigHelper,
Configurable $configurable,
?int $batchSize = 1000
) {
$this->dimensionProvider = $dimensionProvider;
Expand All @@ -61,6 +66,7 @@ public function __construct(
$this->deploymentConfig = $deploymentConfig;
$this->batchSize = $batchSize;
$this->prerenderConfigHelper = $prerenderConfigHelper;
$this->configurable = $configurable;
}

/**
Expand Down Expand Up @@ -138,6 +144,10 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds):
}

$entityIds = iterator_to_array($entityIds);

$parentIds = $this->configurable->getParentIdsByChild($entityIds);
$entityIds = array_unique(array_merge($entityIds, $parentIds));

// get urls for the products
$urls = $this->getUrlsForProducts->execute($entityIds, $storeId);

Expand Down

0 comments on commit 0204925

Please sign in to comment.