Skip to content

Commit 012537c

Browse files
committed
update code
1 parent 99083a8 commit 012537c

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Catalog\Block\Product;
77

88
use Magento\Customer\Model\Context as CustomerContext;
9-
use Magento\Framework\App\Http\Context as HttpContext;
109

1110
/**
1211
* New products block
@@ -19,29 +18,29 @@ class NewProduct extends \Magento\Catalog\Block\Product\AbstractProduct implemen
1918
/**
2019
* Default value for products count that will be shown
2120
*/
22-
public const DEFAULT_PRODUCTS_COUNT = 10;
21+
const DEFAULT_PRODUCTS_COUNT = 10;
2322

2423
/**
25-
* How much product should be displayed at once
24+
* Products count
2625
*
2726
* @var int
2827
*/
2928
protected $_productsCount;
3029

3130
/**
32-
* @var HttpContext
31+
* @var \Magento\Framework\App\Http\Context
3332
*/
3433
protected $httpContext;
3534

3635
/**
37-
* Catalog product visibility model
36+
* Catalog product visibility
3837
*
3938
* @var \Magento\Catalog\Model\Product\Visibility
4039
*/
4140
protected $_catalogProductVisibility;
4241

4342
/**
44-
* Catalog product collection factory
43+
* Product collection factory
4544
*
4645
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
4746
*/
@@ -58,7 +57,7 @@ public function __construct(
5857
\Magento\Catalog\Block\Product\Context $context,
5958
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
6059
\Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
61-
HttpContext $httpContext,
60+
\Magento\Framework\App\Http\Context $httpContext,
6261
array $data = []
6362
) {
6463
$this->_productCollectionFactory = $productCollectionFactory;
@@ -96,15 +95,13 @@ protected function _construct()
9695
*/
9796
public function getCacheKeyInfo()
9897
{
99-
$store = $this->_storeManager->getStore();
10098
return [
10199
'CATALOG_PRODUCT_NEW',
102-
$store->getId(),
100+
$this->_storeManager->getStore()->getId(),
103101
$this->_design->getDesignTheme()->getId(),
104102
$this->httpContext->getValue(CustomerContext::CONTEXT_GROUP),
105103
'template' => $this->getTemplate(),
106-
$this->getProductsCount(),
107-
$this->httpContext->getValue(HttpContext::CONTEXT_CURRENCY) ?: $store->getDefaultCurrency()->getCode()
104+
$this->getProductsCount()
108105
];
109106
}
110107

app/code/Magento/Catalog/Block/Product/Widget/NewWidget.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Block\Product\Widget;
77

8+
use Magento\Framework\App\Http\Context as HttpContext;
9+
810
/**
911
* New products widget
1012
*/
@@ -13,29 +15,29 @@ class NewWidget extends \Magento\Catalog\Block\Product\NewProduct implements \Ma
1315
/**
1416
* Display products type - all products
1517
*/
16-
const DISPLAY_TYPE_ALL_PRODUCTS = 'all_products';
18+
public const DISPLAY_TYPE_ALL_PRODUCTS = 'all_products';
1719

1820
/**
1921
* Display products type - new products
2022
*/
21-
const DISPLAY_TYPE_NEW_PRODUCTS = 'new_products';
23+
public const DISPLAY_TYPE_NEW_PRODUCTS = 'new_products';
2224

2325
/**
2426
* Default value whether show pager or not
2527
*/
26-
const DEFAULT_SHOW_PAGER = false;
28+
public const DEFAULT_SHOW_PAGER = false;
2729

2830
/**
2931
* Default value for products per page
3032
*/
31-
const DEFAULT_PRODUCTS_PER_PAGE = 5;
33+
public const DEFAULT_PRODUCTS_PER_PAGE = 5;
3234

3335
/**
3436
* Name of request parameter for page number value
3537
*
3638
* @deprecated
3739
*/
38-
const PAGE_VAR_NAME = 'np';
40+
public const PAGE_VAR_NAME = 'np';
3941

4042
/**
4143
* Instance of pager block
@@ -134,13 +136,15 @@ public function getCurrentPage()
134136
*/
135137
public function getCacheKeyInfo()
136138
{
139+
$store = $this->_storeManager->getStore();
137140
return array_merge(
138141
parent::getCacheKeyInfo(),
139142
[
140143
$this->getDisplayType(),
141144
$this->getProductsPerPage(),
142145
(int) $this->getRequest()->getParam($this->getData('page_var_name'), 1),
143-
$this->serializer->serialize($this->getRequest()->getParams())
146+
$this->serializer->serialize($this->getRequest()->getParams()),
147+
$this->httpContext->getValue(HttpContext::CONTEXT_CURRENCY) ?: $store->getDefaultCurrency()->getCode()
144148
]
145149
);
146150
}
@@ -268,7 +272,7 @@ public function getProductPriceHtml(
268272
? $arguments['display_minimal_price']
269273
: true;
270274

271-
/** @var \Magento\Framework\Pricing\Render $priceRender */
275+
/** @var \Magento\Framework\Pricing\Render $priceRender */
272276
$priceRender = $this->getLayout()->getBlock('product.price.render.default');
273277

274278
$price = '';

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/NewTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ public function testGetCacheKeyInfo()
5353
$this->assertEquals('CATALOG_PRODUCT_NEW', $info[0]);
5454

5555
$this->assertSame(1, array_shift($keys));
56-
57-
$currentStore = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
58-
\Magento\Store\Model\StoreManagerInterface::class
59-
)->getStore();
6056
$this->assertEquals(
61-
$currentStore->getId(),
57+
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
58+
\Magento\Store\Model\StoreManagerInterface::class
59+
)->getStore()->getId(),
6260
$info[1]
6361
);
6462

@@ -86,9 +84,6 @@ public function testGetCacheKeyInfo()
8684
*/
8785
$this->assertSame(4, array_shift($keys));
8886
$this->assertNotEquals('', $info[4]);
89-
90-
$this->assertSame(5, array_shift($keys));
91-
$this->assertSame($currentStore->getDefaultCurrency()->getCode(), $info[5]);
9287
}
9388

9489
public function testSetGetProductsCount()
@@ -141,5 +136,11 @@ public function testNewWidgetGetCacheKeyInfo()
141136

142137
$this->assertEquals('CATALOG_PRODUCT_NEW', $info[0]);
143138
$this->assertEquals(json_encode($requestParams), $info[8]);
139+
140+
$currentStore = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
141+
\Magento\Store\Model\StoreManagerInterface::class
142+
)->getStore();
143+
144+
$this->assertSame($currentStore->getDefaultCurrency()->getCode(), $info[9]);
144145
}
145146
}

0 commit comments

Comments
 (0)