Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BEG-143: Trigger re-caching when child variant is edited #15 #16

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 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\PrerenderIo\Helper\Config;
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;
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 @@ -58,6 +61,7 @@ public function __construct(
PrerenderClientInterface $prerenderClient,
DeploymentConfig $deploymentConfig,
Config $prerenderConfigHelper,
Configurable $configurable,
?int $batchSize = 1000
) {
$this->dimensionProvider = $dimensionProvider;
Expand All @@ -67,6 +71,7 @@ public function __construct(
$this->deploymentConfig = $deploymentConfig;
$this->batchSize = $batchSize;
$this->prerenderConfigHelper = $prerenderConfigHelper;
$this->configurable = $configurable;
}

/**
Expand Down Expand Up @@ -144,6 +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
$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
12 changes: 12 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\PrerenderIo\Api\PrerenderClientInterface;
use Aligent\PrerenderIo\Helper\Config;
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;
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,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(
Expand All @@ -53,6 +58,7 @@ public function __construct(
PrerenderClientInterface $prerenderClient,
DeploymentConfig $deploymentConfig,
Config $prerenderConfigHelper,
Configurable $configurable,
?int $batchSize = 1000
) {
$this->dimensionProvider = $dimensionProvider;
Expand All @@ -61,6 +67,7 @@ public function __construct(
$this->deploymentConfig = $deploymentConfig;
$this->batchSize = $batchSize;
$this->prerenderConfigHelper = $prerenderConfigHelper;
$this->configurable = $configurable;
}

/**
Expand Down Expand Up @@ -138,6 +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
aligent-lturner marked this conversation as resolved.
Show resolved Hide resolved
$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
Loading