diff --git a/vendor/magento/module-catalog/Model/Mview/View/Sku/EntityIdResolver.php b/vendor/magento/module-catalog/Model/Mview/View/Sku/EntityIdResolver.php
new file mode 100644
index 00000000000..27f09eb7ea3
--- /dev/null
+++ b/vendor/magento/module-catalog/Model/Mview/View/Sku/EntityIdResolver.php
@@ -0,0 +1,109 @@
+resource = $resource;
+ $this->metadataPool = $metadataPool;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function process(
+ SubscriptionInterface $subscription,
+ ViewInterface $view,
+ string $event,
+ string $statement
+ ): string {
+ if (!$subscription instanceof Subscription) {
+ return $statement;
+ }
+ if (!in_array($event, [Trigger::EVENT_INSERT, Trigger::EVENT_UPDATE, Trigger::EVENT_DELETE])) {
+ return $statement;
+ }
+ $hash = sprintf(
+ '%s__%s',
+ spl_object_hash($subscription),
+ $this->resource->getTriggerName(
+ $this->resource->getTableName($subscription->getTableName()),
+ Trigger::TIME_AFTER,
+ $event
+ )
+ );
+
+ $preStatement = '';
+ if (!isset($this->processed[$hash])) {
+ $connection = $this->resource->getConnection();
+ $metadata = $this->metadataPool->getMetadata(ProductInterface::class);
+ if ($event == Trigger::EVENT_INSERT or $event == Trigger::EVENT_UPDATE) {
+ $column_type = 'NEW';
+ }else{
+ $column_type = 'OLD';
+ }
+ $preStatement = vsprintf(
+ 'SET @entity_id = (SELECT %1$s FROM %2$s WHERE %3$s = %4$s.%5$s LIMIT 1);' . PHP_EOL,
+ [
+ $connection->quoteIdentifier($metadata->getIdentifierField()),
+ $connection->quoteIdentifier($this->resource->getTableName($metadata->getEntityTable())),
+ ProductInterface::SKU,
+ $column_type,
+ $subscription->getColumnName()
+ ]
+ );
+ $this->processed[$hash] = true;
+ }
+ $statement = sprintf(
+ "IF (@entity_id IS NOT NULL) THEN %s END IF;",
+ $statement
+ );
+ return $preStatement . $statement;
+ }
+}
diff --git a/vendor/magento/module-catalog/Model/Mview/View/Sku/Subscription.php b/vendor/magento/module-catalog/Model/Mview/View/Sku/Subscription.php
new file mode 100644
index 00000000000..e0b6cee7974
--- /dev/null
+++ b/vendor/magento/module-catalog/Model/Mview/View/Sku/Subscription.php
@@ -0,0 +1,32 @@
+resourceConnection->getConnection();
+
+ $select = $connection->select();
+ $select->from($this->getCategoryLinkMetadata()->getEntityTable(), ['category_id']);
+ $select->where('product_id IN (?)', $productIds, \Zend_Db::INT_TYPE);
+ $select->distinct(true);
+ return $connection->fetchCol($select);
+ }
}
diff --git a/vendor/magento/module-catalog/etc/di.xml b/vendor/magento/module-catalog/etc/di.xml
index b509debe7ba..c5610710046 100644
--- a/vendor/magento/module-catalog/etc/di.xml
+++ b/vendor/magento/module-catalog/etc/di.xml
@@ -1328,4 +1328,12 @@
+
+
+
+
+ - Magento\Catalog\Model\Mview\View\Sku\EntityIdResolver
+
+
+
diff --git a/vendor/magento/module-indexer/etc/di.xml b/vendor/magento/module-indexer/etc/di.xml
index 9496f29cb1d..43cec04d0df 100644
--- a/vendor/magento/module-indexer/etc/di.xml
+++ b/vendor/magento/module-indexer/etc/di.xml
@@ -36,6 +36,9 @@
Magento\Framework\Mview\View\CollectionInterface
+
+ - updated_at
+
diff --git a/app/etc/di.xml b/app/etc/di.xml
index 078fe71913f..f6da735105d 100644
--- a/app/etc/di.xml
+++ b/app/etc/di.xml
@@ -212,6 +212,7 @@
+
diff --git a/vendor/magento/framework/Mview/View/CompositeSubscriptionStatementPostprocessor.php b/vendor/magento/framework/Mview/View/CompositeSubscriptionStatementPostprocessor.php
new file mode 100644
index 00000000000..9a0623e8a80
--- /dev/null
+++ b/vendor/magento/framework/Mview/View/CompositeSubscriptionStatementPostprocessor.php
@@ -0,0 +1,53 @@
+postprocessors = $postprocessors;
+ foreach ($this->postprocessors as $postprocessor) {
+ if (!$postprocessor instanceof SubscriptionStatementPostprocessorInterface) {
+ throw new \InvalidArgumentException(
+ sprintf(
+ 'Instance of %s is expected, got %s instead',
+ SubscriptionStatementPostprocessorInterface::class,
+ get_class($postprocessor)
+ )
+ );
+ }
+ }
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function process(
+ SubscriptionInterface $subscription,
+ ViewInterface $view,
+ string $event,
+ string $statement
+ ): string {
+ foreach ($this->postprocessors as $postprocessor) {
+ $statement = $postprocessor->process($subscription, $view, $event, $statement);
+ }
+
+ return $statement;
+ }
+}
diff --git a/vendor/magento/framework/Mview/View/Subscription.php b/vendor/magento/framework/Mview/View/Subscription.php
index 03a3bf9615c..b9ea71df69c 100644
--- a/vendor/magento/framework/Mview/View/Subscription.php
+++ b/vendor/magento/framework/Mview/View/Subscription.php
@@ -82,6 +82,11 @@ class Subscription implements SubscriptionInterface
*/
private $mviewConfig;
+ /**
+ * @var SubscriptionStatementPostprocessorInterface
+ */
+ private $statementPostprocessor;
+
/**
* @param ResourceConnection $resource
* @param TriggerFactory $triggerFactory
@@ -92,6 +97,8 @@ class Subscription implements SubscriptionInterface
* @param array $ignoredUpdateColumns
* @param array $ignoredUpdateColumnsBySubscription
* @param Config|null $mviewConfig
+ * @param SubscriptionStatementPostprocessorInterface|null $statementPostprocessor
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
ResourceConnection $resource,
@@ -102,7 +109,8 @@ class Subscription implements SubscriptionInterface
$columnName,
$ignoredUpdateColumns = [],
$ignoredUpdateColumnsBySubscription = [],
- Config $mviewConfig = null
+ ?Config $mviewConfig = null,
+ ?SubscriptionStatementPostprocessorInterface $statementPostprocessor = null
) {
$this->connection = $resource->getConnection();
$this->triggerFactory = $triggerFactory;
@@ -114,6 +122,8 @@ class Subscription implements SubscriptionInterface
$this->ignoredUpdateColumns = $ignoredUpdateColumns;
$this->ignoredUpdateColumnsBySubscription = $ignoredUpdateColumnsBySubscription;
$this->mviewConfig = $mviewConfig ?? ObjectManager::getInstance()->get(Config::class);
+ $this->statementPostprocessor = $statementPostprocessor
+ ?? ObjectManager::getInstance()->get(SubscriptionStatementPostprocessorInterface::class);
}
/**
@@ -287,13 +297,16 @@ class Subscription implements SubscriptionInterface
}
$columns = $this->prepareColumns($view, $event);
- return sprintf(
+ $statement = sprintf(
$trigger,
$this->getProcessor()->getPreStatements(),
$this->connection->quoteIdentifier($this->resource->getTableName($changelog->getName())),
implode(', ', $columns['column_names']),
implode(', ', $columns['column_values'])
);
+ $statement = $this->statementPostprocessor->process($this, $view, $event, $statement);
+
+ return $statement;
}
/**
diff --git a/vendor/magento/framework/Mview/View/SubscriptionStatementPostprocessorInterface.php b/vendor/magento/framework/Mview/View/SubscriptionStatementPostprocessorInterface.php
new file mode 100644
index 00000000000..3a8cab0997f
--- /dev/null
+++ b/vendor/magento/framework/Mview/View/SubscriptionStatementPostprocessorInterface.php
@@ -0,0 +1,29 @@
+