Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -988,7 +995,6 @@ public function getCacheTags()
{
$identities = $this->getIdentities();
$cacheTags = !empty($identities) ? (array) $identities : parent::getCacheTags();

return $cacheTags;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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
*
Expand Down