Skip to content

Commit 99083a8

Browse files
committed
fix currency in new widget
1 parent 9a58794 commit 99083a8

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

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

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

88
use Magento\Customer\Model\Context as CustomerContext;
9+
use Magento\Framework\App\Http\Context as HttpContext;
910

1011
/**
1112
* New products block
@@ -18,29 +19,29 @@ class NewProduct extends \Magento\Catalog\Block\Product\AbstractProduct implemen
1819
/**
1920
* Default value for products count that will be shown
2021
*/
21-
const DEFAULT_PRODUCTS_COUNT = 10;
22+
public const DEFAULT_PRODUCTS_COUNT = 10;
2223

2324
/**
24-
* Products count
25+
* How much product should be displayed at once
2526
*
2627
* @var int
2728
*/
2829
protected $_productsCount;
2930

3031
/**
31-
* @var \Magento\Framework\App\Http\Context
32+
* @var HttpContext
3233
*/
3334
protected $httpContext;
3435

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

4243
/**
43-
* Product collection factory
44+
* Catalog product collection factory
4445
*
4546
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
4647
*/
@@ -57,7 +58,7 @@ public function __construct(
5758
\Magento\Catalog\Block\Product\Context $context,
5859
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
5960
\Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
60-
\Magento\Framework\App\Http\Context $httpContext,
61+
HttpContext $httpContext,
6162
array $data = []
6263
) {
6364
$this->_productCollectionFactory = $productCollectionFactory;
@@ -95,13 +96,15 @@ protected function _construct()
9596
*/
9697
public function getCacheKeyInfo()
9798
{
99+
$store = $this->_storeManager->getStore();
98100
return [
99101
'CATALOG_PRODUCT_NEW',
100-
$this->_storeManager->getStore()->getId(),
102+
$store->getId(),
101103
$this->_design->getDesignTheme()->getId(),
102104
$this->httpContext->getValue(CustomerContext::CONTEXT_GROUP),
103105
'template' => $this->getTemplate(),
104-
$this->getProductsCount()
106+
$this->getProductsCount(),
107+
$this->httpContext->getValue(HttpContext::CONTEXT_CURRENCY) ?: $store->getDefaultCurrency()->getCode()
105108
];
106109
}
107110

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ 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();
5660
$this->assertEquals(
57-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
58-
\Magento\Store\Model\StoreManagerInterface::class
59-
)->getStore()->getId(),
61+
$currentStore->getId(),
6062
$info[1]
6163
);
6264

@@ -84,6 +86,9 @@ public function testGetCacheKeyInfo()
8486
*/
8587
$this->assertSame(4, array_shift($keys));
8688
$this->assertNotEquals('', $info[4]);
89+
90+
$this->assertSame(5, array_shift($keys));
91+
$this->assertSame($currentStore->getDefaultCurrency()->getCode(), $info[5]);
8792
}
8893

8994
public function testSetGetProductsCount()

0 commit comments

Comments
 (0)