Skip to content

Commit 14db4ad

Browse files
committed
MC-36835: [Cloud] Adding new disabled products to Magento flushes categories cache
1 parent 4930963 commit 14db4ad

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

app/code/Magento/Catalog/Model/Product.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Api\ProductLinkRepositoryInterface;
1212
use Magento\Catalog\Model\Product\Attribute\Backend\Media\EntryConverterPool;
13+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1314
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
1415
use Magento\Framework\Api\AttributeValueFactory;
1516
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -202,7 +203,7 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
202203
/**
203204
* Catalog product status
204205
*
205-
* @var \Magento\Catalog\Model\Product\Attribute\Source\Status
206+
* @var Status
206207
*/
207208
protected $_catalogProductStatus;
208209

@@ -408,7 +409,7 @@ public function __construct(
408409
\Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory $stockItemFactory,
409410
\Magento\Catalog\Model\Product\OptionFactory $catalogProductOptionFactory,
410411
\Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
411-
\Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus,
412+
Status $catalogProductStatus,
412413
\Magento\Catalog\Model\Product\Media\Config $catalogProductMediaConfig,
413414
Product\Type $catalogProductType,
414415
\Magento\Framework\Module\Manager $moduleManager,
@@ -668,7 +669,7 @@ public function getTypeId()
668669
public function getStatus()
669670
{
670671
$status = $this->_getData(self::STATUS);
671-
return $status !== null ? $status : \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
672+
return $status !== null ? $status : Status::STATUS_ENABLED;
672673
}
673674

674675
/**
@@ -1103,7 +1104,7 @@ public function afterDeleteCommit()
11031104
protected function _afterLoad()
11041105
{
11051106
if (!$this->hasData(self::STATUS)) {
1106-
$this->setData(self::STATUS, \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
1107+
$this->setData(self::STATUS, Status::STATUS_ENABLED);
11071108
}
11081109
parent::_afterLoad();
11091110
return $this;
@@ -1780,7 +1781,7 @@ public function isSaleable()
17801781
*/
17811782
public function isInStock()
17821783
{
1783-
return $this->getStatus() == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
1784+
return $this->getStatus() == Status::STATUS_ENABLED;
17841785
}
17851786

17861787
/**
@@ -2341,7 +2342,7 @@ public function getProductEntitiesInfo($columns = null)
23412342
*/
23422343
public function isDisabled()
23432344
{
2344-
return $this->getStatus() == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED;
2345+
return $this->getStatus() == Status::STATUS_DISABLED;
23452346
}
23462347

23472348
/**
@@ -2365,17 +2366,21 @@ public function getImage()
23652366
public function getIdentities()
23662367
{
23672368
$identities = [self::CACHE_TAG . '_' . $this->getId()];
2368-
if ($this->getIsChangedCategories()) {
2369-
foreach ($this->getAffectedCategoryIds() as $categoryId) {
2370-
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
2369+
2370+
if (!$this->isObjectNew() || $this->getStatus() == Status::STATUS_ENABLED) {
2371+
if ($this->getIsChangedCategories()) {
2372+
foreach ($this->getAffectedCategoryIds() as $categoryId) {
2373+
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
2374+
}
23712375
}
2372-
}
23732376

2374-
if (($this->getOrigData('status') != $this->getData('status')) || $this->isStockStatusChanged()) {
2375-
foreach ($this->getCategoryIds() as $categoryId) {
2376-
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
2377+
if (($this->getOrigData('status') != $this->getData('status')) || $this->isStockStatusChanged()) {
2378+
foreach ($this->getCategoryIds() as $categoryId) {
2379+
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
2380+
}
23772381
}
23782382
}
2383+
23792384
if ($this->_appState->getAreaCode() == \Magento\Framework\App\Area::AREA_FRONTEND) {
23802385
$identities[] = self::CACHE_TAG;
23812386
}

0 commit comments

Comments
 (0)