From 9b77f928d9bf638e3d7ace7184204502f5cc4917 Mon Sep 17 00:00:00 2001 From: Rus0 Date: Thu, 4 Dec 2025 14:52:03 -0600 Subject: [PATCH 1/2] Adding validation for avoiding cleaning the 'cat_p' cache when saving a product in frontend --- app/code/Magento/Catalog/Model/Product.php | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index 8417219424044..bd6b6e271d023 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -13,6 +13,7 @@ use Magento\Catalog\Model\Product\Attribute\Source\Status; use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface; use Magento\Framework\Api\AttributeValueFactory; +use Magento\Framework\App\Area; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\ObjectManager; use Magento\Framework\DataObject\IdentityInterface; @@ -157,6 +158,12 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements */ protected $_links = null; + /** + * Adds the default Cache Tag in Frontend + * @var bool + */ + protected $_addDefaultCacheTag = true; + /** * Flag for available duplicate function * @@ -988,7 +995,6 @@ public function getCacheTags() { $identities = $this->getIdentities(); $cacheTags = !empty($identities) ? (array) $identities : parent::getCacheTags(); - return $cacheTags; } @@ -2405,7 +2411,11 @@ public function getIdentities() } } - if ($this->_appState->getAreaCode() == \Magento\Framework\App\Area::AREA_FRONTEND) { + if ($this->hasDataChanges()) { + $this->_addDefaultCacheTag = false; + } + + if ($this->_appState->getAreaCode() == Area::AREA_FRONTEND && $this->_addDefaultCacheTag) { $identities[] = self::CACHE_TAG; } @@ -2419,6 +2429,15 @@ public function getIdentities() return array_unique($identities); } + /** + * @inheritdoc + */ + public function afterCommitCallback() + { + $this->_addDefaultCacheTag = false; + return parent::afterCommitCallback(); + } + /** * Check whether stock status changed * From 3f151c65c5c25bcb9b6acf81f44244f0b4405468 Mon Sep 17 00:00:00 2001 From: Rus0 Date: Tue, 23 Dec 2025 14:30:50 -0600 Subject: [PATCH 2/2] changed variable to be a dynamic one --- app/code/Magento/Catalog/Model/Product.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index bd6b6e271d023..07ed224e5daf9 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -158,12 +158,6 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements */ protected $_links = null; - /** - * Adds the default Cache Tag in Frontend - * @var bool - */ - protected $_addDefaultCacheTag = true; - /** * Flag for available duplicate function * @@ -2411,11 +2405,12 @@ public function getIdentities() } } + $this->setAddDefaultCacheTag(true); if ($this->hasDataChanges()) { - $this->_addDefaultCacheTag = false; + $this->setAddDefaultCacheTag(false); } - if ($this->_appState->getAreaCode() == Area::AREA_FRONTEND && $this->_addDefaultCacheTag) { + if ($this->_appState->getAreaCode() == Area::AREA_FRONTEND && $this->getAddDefaultCacheTag()) { $identities[] = self::CACHE_TAG; } @@ -2434,7 +2429,7 @@ public function getIdentities() */ public function afterCommitCallback() { - $this->_addDefaultCacheTag = false; + $this->setAddDefaultCacheTag(false); return parent::afterCommitCallback(); }