From 9b77f928d9bf638e3d7ace7184204502f5cc4917 Mon Sep 17 00:00:00 2001 From: Rus0 Date: Thu, 4 Dec 2025 14:52:03 -0600 Subject: [PATCH] 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 *