diff --git a/vendor/magento/module-catalog/Block/Product/NewProduct.php b/vendor/magento/module-catalog/Block/Product/NewProduct.php index cb0904fe5fa6..838f7d08cd65 100644 --- a/vendor/magento/module-catalog/Block/Product/NewProduct.php +++ b/vendor/magento/module-catalog/Block/Product/NewProduct.php @@ -18,11 +18,14 @@ class NewProduct extends \Magento\Catalog\Block\Product\AbstractProduct implemen /** * Default value for products count that will be shown */ - const DEFAULT_PRODUCTS_COUNT = 10; + public const DEFAULT_PRODUCTS_COUNT = 10; + + /** + * Block cache tag + */ + public const CACHE_TAG = 'cat_p_new'; /** - * Products count - * * @var int */ protected $_productsCount; @@ -33,15 +36,11 @@ class NewProduct extends \Magento\Catalog\Block\Product\AbstractProduct implemen protected $httpContext; /** - * Catalog product visibility - * * @var \Magento\Catalog\Model\Product\Visibility */ protected $_catalogProductVisibility; /** - * Product collection factory - * * @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory */ protected $_productCollectionFactory; @@ -199,6 +198,6 @@ public function getProductsCount() */ public function getIdentities() { - return [\Magento\Catalog\Model\Product::CACHE_TAG]; + return [self::CACHE_TAG]; } } diff --git a/vendor/magento/module-catalog/Model/Product.php b/vendor/magento/module-catalog/Model/Product.php index 0191c0239fc2..70d80b15702c 100644 --- a/vendor/magento/module-catalog/Model/Product.php +++ b/vendor/magento/module-catalog/Model/Product.php @@ -2389,6 +2389,7 @@ private function getProductCategoryIdentities(array $categoryIds): array * Get identities * * @return array + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function getIdentities() { @@ -2415,6 +2416,12 @@ public function getIdentities() $identities[] = self::CACHE_TAG; } + $isProductNew = $this->getOrigData('news_from_date') != $this->getData('news_from_date') + || $this->isObjectNew(); + if ($isProductNew && ($isStatusChanged || $this->getStatus() == Status::STATUS_ENABLED)) { + $identities[] = \Magento\Catalog\Block\Product\NewProduct::CACHE_TAG; + } + return array_unique($identities); }