diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index 841721942404..bd6b6e271d02 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 *