Skip to content

Commit 01a525c

Browse files
committed
Merge branch 'ACP2E-2621' of https://github.com/magento-l3/magento2ce into PR-01-26-2024
2 parents ff5d733 + 2b1085a commit 01a525c

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

app/code/Magento/Catalog/Block/Product/NewProduct.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ class NewProduct extends \Magento\Catalog\Block\Product\AbstractProduct implemen
1818
/**
1919
* Default value for products count that will be shown
2020
*/
21-
const DEFAULT_PRODUCTS_COUNT = 10;
21+
public const DEFAULT_PRODUCTS_COUNT = 10;
22+
23+
/**
24+
* Block cache tag
25+
*/
26+
public const CACHE_TAG = 'cat_p_new';
2227

2328
/**
24-
* Products count
25-
*
2629
* @var int
2730
*/
2831
protected $_productsCount;
@@ -33,15 +36,11 @@ class NewProduct extends \Magento\Catalog\Block\Product\AbstractProduct implemen
3336
protected $httpContext;
3437

3538
/**
36-
* Catalog product visibility
37-
*
3839
* @var \Magento\Catalog\Model\Product\Visibility
3940
*/
4041
protected $_catalogProductVisibility;
4142

4243
/**
43-
* Product collection factory
44-
*
4544
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
4645
*/
4746
protected $_productCollectionFactory;
@@ -199,6 +198,6 @@ public function getProductsCount()
199198
*/
200199
public function getIdentities()
201200
{
202-
return [\Magento\Catalog\Model\Product::CACHE_TAG];
201+
return [self::CACHE_TAG];
203202
}
204203
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,7 @@ private function getProductCategoryIdentities(array $categoryIds): array
23802380
* Get identities
23812381
*
23822382
* @return array
2383+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
23832384
*/
23842385
public function getIdentities()
23852386
{
@@ -2406,6 +2407,12 @@ public function getIdentities()
24062407
$identities[] = self::CACHE_TAG;
24072408
}
24082409

2410+
$isProductNew = $this->getOrigData('news_from_date') != $this->getData('news_from_date')
2411+
|| $this->isObjectNew();
2412+
if ($isProductNew && ($isStatusChanged || $this->getStatus() == Status::STATUS_ENABLED)) {
2413+
$identities[] = \Magento\Catalog\Block\Product\NewProduct::CACHE_TAG;
2414+
}
2415+
24092416
return array_unique($identities);
24102417
}
24112418

app/code/Magento/Catalog/Test/Unit/Block/Product/NewProductTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\Catalog\Block\Product\ListProduct;
1111
use Magento\Catalog\Block\Product\NewProduct;
12-
use Magento\Catalog\Model\Product;
1312
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1413
use PHPUnit\Framework\TestCase;
1514

@@ -33,7 +32,7 @@ protected function tearDown(): void
3332

3433
public function testGetIdentities()
3534
{
36-
$this->assertEquals([Product::CACHE_TAG], $this->block->getIdentities());
35+
$this->assertEquals([NewProduct::CACHE_TAG], $this->block->getIdentities());
3736
}
3837

3938
public function testScope()

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ private function getNoStockStatusChangesData(MockObject $extensionAttributesMock
983983
private function getNewProductProviderData(): array
984984
{
985985
return [
986-
['cat_p_1', 'cat_c_p_1'],
986+
['cat_p_1', 'cat_c_p_1', 'cat_p_new'],
987987
null,
988988
[
989989
'id' => 1,

0 commit comments

Comments
 (0)