Skip to content

Commit 9d6e30f

Browse files
committed
Merge branch 'MC-38719' of https://github.com/magento-mpi/magento2ce into TANGO-PR-11-05-2020_24
2 parents bb4b489 + 8cc8480 commit 9d6e30f

File tree

5 files changed

+498
-6
lines changed

5 files changed

+498
-6
lines changed
Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier;
9+
10+
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\CurrencySymbolProvider;
11+
use Magento\Catalog\Model\Locator\LocatorInterface;
12+
use Magento\Catalog\Model\Product;
13+
use Magento\Directory\Model\Currency as CurrencyModel;
14+
use Magento\Framework\App\Config\ScopeConfigInterface;
15+
use Magento\Framework\Locale\CurrencyInterface;
16+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
17+
use Magento\Store\Api\Data\StoreInterface;
18+
use Magento\Store\Api\Data\WebsiteInterface;
19+
use Magento\Store\Model\StoreManagerInterface;
20+
use PHPUnit\Framework\MockObject\MockObject;
21+
use PHPUnit\Framework\TestCase;
22+
use Zend_Currency;
23+
24+
/**
25+
* Test class for Website Currency Symbol provider
26+
*/
27+
class CurrencySymbolProviderTest extends TestCase
28+
{
29+
/**
30+
* @var CurrencySymbolProvider|MockObject
31+
*/
32+
private $currencySymbolProvider;
33+
34+
/**
35+
* @var ScopeConfigInterface|MockObject
36+
*/
37+
private $scopeConfigMock;
38+
39+
/**
40+
* @var StoreManagerInterface|MockObject
41+
*/
42+
private $storeManagerMock;
43+
44+
/**
45+
* @var LocatorInterface|MockObject
46+
*/
47+
private $locatorMock;
48+
49+
/**
50+
* @var CurrencyInterface|MockObject
51+
*/
52+
private $localeCurrencyMock;
53+
54+
/**
55+
* @var StoreInterface|MockObject
56+
*/
57+
private $currentStoreMock;
58+
59+
/**
60+
* @var CurrencyModel|MockObject
61+
*/
62+
private $currencyMock;
63+
64+
/**
65+
* @var Zend_Currency|MockObject
66+
*/
67+
private $websiteCurrencyMock;
68+
69+
/**
70+
* @var Product|MockObject
71+
*/
72+
private $productMock;
73+
74+
protected function setUp(): void
75+
{
76+
$objectManager = new ObjectManager($this);
77+
78+
$this->scopeConfigMock = $this->getMockForAbstractClass(
79+
ScopeConfigInterface::class,
80+
[],
81+
'',
82+
true,
83+
true,
84+
true,
85+
['getValue']
86+
);
87+
$this->storeManagerMock = $this->getMockForAbstractClass(
88+
StoreManagerInterface::class,
89+
[],
90+
'',
91+
true,
92+
true,
93+
true,
94+
['getWebsites']
95+
);
96+
$this->currentStoreMock = $this->getMockForAbstractClass(
97+
StoreInterface::class,
98+
[],
99+
'',
100+
true,
101+
true,
102+
true,
103+
['getBaseCurrency']
104+
);
105+
$this->currencyMock = $this->createMock(CurrencyModel::class);
106+
$this->websiteCurrencyMock = $this->createMock(Zend_Currency::class);
107+
$this->productMock = $this->createMock(Product::class);
108+
$this->locatorMock = $this->getMockForAbstractClass(
109+
LocatorInterface::class,
110+
[],
111+
'',
112+
true,
113+
true,
114+
true,
115+
['getStore', 'getProduct']
116+
);
117+
$this->localeCurrencyMock = $this->getMockForAbstractClass(
118+
CurrencyInterface::class,
119+
[],
120+
'',
121+
true,
122+
true,
123+
true,
124+
['getWebsites', 'getCurrency']
125+
);
126+
$this->currencySymbolProvider = $objectManager->getObject(
127+
CurrencySymbolProvider::class,
128+
[
129+
'scopeConfig' => $this->scopeConfigMock,
130+
'storeManager' => $this->storeManagerMock,
131+
'locator' => $this->locatorMock,
132+
'localeCurrency' => $this->localeCurrencyMock
133+
]
134+
);
135+
}
136+
137+
/**
138+
* Test for Get option array of currency symbol prefixes.
139+
*
140+
* @param int $catalogPriceScope
141+
* @param string $defaultStoreCurrencySymbol
142+
* @param array $listOfWebsites
143+
* @param array $productWebsiteIds
144+
* @param array $currencySymbols
145+
* @param array $actualResult
146+
* @dataProvider getWebsiteCurrencySymbolDataProvider
147+
*/
148+
public function testGetCurrenciesPerWebsite(
149+
int $catalogPriceScope,
150+
string $defaultStoreCurrencySymbol,
151+
array $listOfWebsites,
152+
array $productWebsiteIds,
153+
array $currencySymbols,
154+
array $actualResult
155+
): void {
156+
$this->locatorMock->expects($this->any())
157+
->method('getStore')
158+
->willReturn($this->currentStoreMock);
159+
$this->currentStoreMock->expects($this->any())
160+
->method('getBaseCurrency')
161+
->willReturn($this->currencyMock);
162+
$this->currencyMock->expects($this->any())
163+
->method('getCurrencySymbol')
164+
->willReturn($defaultStoreCurrencySymbol);
165+
$this->scopeConfigMock
166+
->expects($this->any())
167+
->method('getValue')
168+
->willReturn($catalogPriceScope);
169+
$this->locatorMock->expects($this->any())
170+
->method('getProduct')
171+
->willReturn($this->productMock);
172+
$this->storeManagerMock->expects($this->any())
173+
->method('getWebsites')
174+
->willReturn($listOfWebsites);
175+
$this->productMock->expects($this->any())
176+
->method('getWebsiteIds')
177+
->willReturn($productWebsiteIds);
178+
$this->localeCurrencyMock->expects($this->any())
179+
->method('getCurrency')
180+
->willReturn($this->websiteCurrencyMock);
181+
foreach ($currencySymbols as $currencySymbol) {
182+
$this->websiteCurrencyMock->expects($this->any())
183+
->method('getSymbol')
184+
->willReturn($currencySymbol);
185+
}
186+
$expectedResult = $this->currencySymbolProvider
187+
->getCurrenciesPerWebsite();
188+
$this->assertEquals($expectedResult, $actualResult);
189+
}
190+
191+
/**
192+
* DataProvider for getCurrenciesPerWebsite.
193+
*
194+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
195+
* @return array
196+
*/
197+
public function getWebsiteCurrencySymbolDataProvider(): array
198+
{
199+
return [
200+
'verify website currency with default website and global price scope' => [
201+
'catalogPriceScope' => 0,
202+
'defaultStoreCurrencySymbol' => '$',
203+
'listOfWebsites' => $this->getWebsitesMock(
204+
[
205+
[
206+
'id' => '1',
207+
'name' => 'Main Website',
208+
'code' => 'main_website',
209+
'base_currency_code' => 'USD',
210+
'currency_symbol' => '$'
211+
]
212+
]
213+
),
214+
'productWebsiteIds' => ['1'],
215+
'currencySymbols' => ['$'],
216+
'actualResult' => ['$']
217+
],
218+
'verify website currency with default website and website price scope' => [
219+
'catalogPriceScope' => 1,
220+
'defaultStoreCurrencySymbol' => '$',
221+
'listOfWebsites' => $this->getWebsitesMock(
222+
[
223+
[
224+
'id' => '1',
225+
'name' => 'Main Website',
226+
'code' => 'main_website',
227+
'base_currency_code' => 'USD',
228+
'currency_symbol' => '$'
229+
]
230+
]
231+
),
232+
'productWebsiteIds' => ['1'],
233+
'currencySymbols' => ['$'],
234+
'actualResult' => ['$', '$']
235+
],
236+
'verify website currency with two website and website price scope' => [
237+
'catalogPriceScope' => 1,
238+
'defaultStoreCurrencySymbol' => '$',
239+
'listOfWebsites' => $this->getWebsitesMock(
240+
[
241+
[
242+
'id' => '1',
243+
'name' => 'Main Website',
244+
'code' => 'main_website',
245+
'base_currency_code' => 'USD',
246+
'currency_symbol' => '$'
247+
],
248+
[
249+
'id' => '2',
250+
'name' => 'Indian Website',
251+
'code' => 'indian_website',
252+
'base_currency_code' => 'INR',
253+
'currency_symbol' => ''
254+
]
255+
]
256+
),
257+
'productWebsiteIds' => ['1', '2'],
258+
'currencySymbols' => ['$', ''],
259+
'actualResult' => ['$', '$', '$']
260+
]
261+
];
262+
}
263+
264+
/**
265+
* Get list of websites mock
266+
*
267+
* @param array $websites
268+
* @return array
269+
*/
270+
private function getWebsitesMock(array $websites): array
271+
{
272+
$websitesMock = [];
273+
foreach ($websites as $key => $website) {
274+
$websitesMock[$key] = $this->getMockForAbstractClass(
275+
WebsiteInterface::class,
276+
[],
277+
'',
278+
true,
279+
true,
280+
true,
281+
['getId', 'getBaseCurrencyCode']
282+
);
283+
$websitesMock[$key]->expects($this->any())
284+
->method('getId')
285+
->willReturn($website['id']);
286+
$websitesMock[$key]->expects($this->any())
287+
->method('getBaseCurrencyCode')
288+
->willReturn($website['base_currency_code']);
289+
}
290+
return $websitesMock;
291+
}
292+
293+
protected function tearDown(): void
294+
{
295+
unset($this->scopeConfigMock);
296+
unset($this->storeManagerMock);
297+
unset($this->currentStoreMock);
298+
unset($this->currencyMock);
299+
unset($this->websiteCurrencyMock);
300+
unset($this->productMock);
301+
unset($this->locatorMock);
302+
unset($this->localeCurrencyMock);
303+
}
304+
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ class AdvancedPricing extends AbstractModifier
100100
*/
101101
private $customerGroupSource;
102102

103+
/**
104+
* @var CurrencySymbolProvider
105+
*/
106+
private $currencySymbolProvider;
107+
103108
/**
104109
* @param LocatorInterface $locator
105110
* @param StoreManagerInterface $storeManager
@@ -110,7 +115,8 @@ class AdvancedPricing extends AbstractModifier
110115
* @param Data $directoryHelper
111116
* @param ArrayManager $arrayManager
112117
* @param string $scopeName
113-
* @param GroupSourceInterface $customerGroupSource
118+
* @param GroupSourceInterface|null $customerGroupSource
119+
* @param CurrencySymbolProvider|null $currencySymbolProvider
114120
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
115121
*/
116122
public function __construct(
@@ -123,7 +129,8 @@ public function __construct(
123129
Data $directoryHelper,
124130
ArrayManager $arrayManager,
125131
$scopeName = '',
126-
GroupSourceInterface $customerGroupSource = null
132+
GroupSourceInterface $customerGroupSource = null,
133+
?CurrencySymbolProvider $currencySymbolProvider = null
127134
) {
128135
$this->locator = $locator;
129136
$this->storeManager = $storeManager;
@@ -136,6 +143,8 @@ public function __construct(
136143
$this->scopeName = $scopeName;
137144
$this->customerGroupSource = $customerGroupSource
138145
?: ObjectManager::getInstance()->get(GroupSourceInterface::class);
146+
$this->currencySymbolProvider = $currencySymbolProvider
147+
?: ObjectManager::getInstance()->get(CurrencySymbolProvider::class);
139148
}
140149

141150
/**
@@ -488,6 +497,7 @@ private function getTierPriceStructure($tierPricePath)
488497
'arguments' => [
489498
'data' => [
490499
'config' => [
500+
'component' => 'Magento_Catalog/js/components/website-currency-symbol',
491501
'dataType' => Text::NAME,
492502
'formElement' => Select::NAME,
493503
'componentType' => Field::NAME,
@@ -498,6 +508,10 @@ private function getTierPriceStructure($tierPricePath)
498508
'visible' => $this->isMultiWebsites(),
499509
'disabled' => ($this->isShowWebsiteColumn() && !$this->isAllowChangeWebsite()),
500510
'sortOrder' => 10,
511+
'currenciesForWebsites' => $this->currencySymbolProvider
512+
->getCurrenciesPerWebsite(),
513+
'currency' => $this->currencySymbolProvider
514+
->getDefaultCurrency(),
501515
],
502516
],
503517
],
@@ -548,9 +562,6 @@ private function getTierPriceStructure($tierPricePath)
548562
'label' => __('Price'),
549563
'enableLabel' => true,
550564
'dataScope' => 'price',
551-
'addbefore' => $this->locator->getStore()
552-
->getBaseCurrency()
553-
->getCurrencySymbol(),
554565
'sortOrder' => 40,
555566
'validation' => [
556567
'required-entry' => true,
@@ -559,8 +570,12 @@ private function getTierPriceStructure($tierPricePath)
559570
],
560571
'imports' => [
561572
'priceValue' => '${ $.provider }:data.product.price',
562-
'__disableTmpl' => ['priceValue' => false],
573+
'__disableTmpl' => ['priceValue' => false, 'addbefore' => false],
574+
'addbefore' => '${ $.parentName }:currency'
563575
],
576+
'tracks' => [
577+
'addbefore' => true
578+
]
564579
],
565580
],
566581
],

0 commit comments

Comments
 (0)