Skip to content

Commit

Permalink
Merge branch '27_product-variants' of https://github.com/bricht/comme…
Browse files Browse the repository at this point in the history
…rce-data-export into 27_product-variants
  • Loading branch information
RuslanKostiv1 committed Nov 12, 2020
2 parents c9a6013 + d35fd8b commit 46d2d59
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Catalog\Model\ResourceModel\Product\Relation;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\ProductVariantDataExporter\Model\Indexer\ProductVariantFeedIndexer;
use Magento\ProductVariantDataExporter\Model\Indexer\UpdateChangeLog;

/**
* Plugin to trigger reindex on variants when relations are changed
Expand All @@ -22,13 +23,21 @@ class ReindexVariantsOnRelationsChange
*/
private $indexerRegistry;

/**
* @var UpdateChangeLog
*/
private $updateChangeLog;

/**
* @param IndexerRegistry $indexerRegistry
* @param UpdateChangeLog $updateChangeLog
*/
public function __construct(
IndexerRegistry $indexerRegistry
IndexerRegistry $indexerRegistry,
UpdateChangeLog $updateChangeLog
) {
$this->indexerRegistry = $indexerRegistry;
$this->updateChangeLog = $updateChangeLog;
}

/**
Expand Down Expand Up @@ -78,14 +87,17 @@ public function afterRemoveRelations(
/**
* Reindex product variants
*
* @param int $parentId
* @param int $id
* @return void
*/
private function reindexVariants(int $parentId): void
private function reindexVariants(int $id): void
{
$indexer = $this->indexerRegistry->get(ProductVariantFeedIndexer::INDEXER_ID);
if (!$indexer->isScheduled()) {
$indexer->reindexRow($parentId);

if ($indexer->isScheduled()) {
$this->updateChangeLog->execute($indexer->getViewId(), [$id]);
} else {
$indexer->reindexRow($id);
}
}
}

0 comments on commit 46d2d59

Please sign in to comment.