Skip to content

Commit 1a0d957

Browse files
committed
Merge remote-tracking branch 'origin/2.4-develop' into ACPT-99-2
2 parents 4ccff3b + eb1e3a0 commit 1a0d957

File tree

37 files changed

+1431
-211
lines changed

37 files changed

+1431
-211
lines changed

app/code/Magento/Bundle/Test/Mftf/Test/AdminBundleProductPriceSymbolValidationInGridTest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
</actionGroup>
8181
<!-- Asserting with the special price value contains the percentage value -->
8282
<actionGroup ref="AdminAssertSpecialPriceAttributeValueOnProductGridPageActionGroup" stepKey="assertSpecialPricePercentageSymbol">
83-
<argument name="expectedValue" value="90.00%"/>
83+
<argument name="expectedValue" value="90.000000%"/>
8484
</actionGroup>
85-
</test>
85+
</test>
8686
</tests>
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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\Bundle\Test\Unit\Ui\DataProvider\Product\Modifier;
9+
10+
use Magento\Bundle\Model\Product\Type;
11+
use Magento\Bundle\Ui\DataProvider\Product\Modifier\SpecialPriceAttributes;
12+
use Magento\Directory\Model\Currency as DirectoryCurrency;
13+
use Magento\Framework\Locale\ResolverInterface;
14+
use Magento\Framework\NumberFormatter;
15+
use Magento\Framework\NumberFormatterFactory;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
18+
19+
class SpecialPriceAttributesTest extends TestCase
20+
{
21+
/**
22+
* @var ResolverInterface|MockObject
23+
*/
24+
private $localResolver;
25+
26+
/**
27+
* @var NumberFormatterFactory|MockObject
28+
*/
29+
private $numberFormatterFactory;
30+
31+
/**
32+
* @var SpecialPriceAttributes
33+
*/
34+
private $model;
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
protected function setUp(): void
40+
{
41+
parent::setUp();
42+
$this->localResolver = $this->createMock(ResolverInterface::class);
43+
$this->numberFormatterFactory = $this->createMock(NumberFormatterFactory::class);
44+
$this->model = new SpecialPriceAttributes(
45+
$this->createMock(DirectoryCurrency::class),
46+
$this->localResolver,
47+
['attr1'],
48+
$this->numberFormatterFactory
49+
);
50+
}
51+
52+
/**
53+
* @param string $locale
54+
* @param array $input
55+
* @param array $output
56+
* @return void
57+
* @dataProvider modifyDataProvider
58+
*/
59+
public function testModifyData(string $locale, array $input, array $output): void
60+
{
61+
$this->localResolver->method('getLocale')
62+
->willReturn($locale);
63+
$this->numberFormatterFactory->method('create')
64+
->willReturnCallback(
65+
function (array $args) {
66+
return new NumberFormatter(...array_values($args));
67+
}
68+
);
69+
$this->assertEquals($output, $this->model->modifyData($input));
70+
}
71+
72+
/**
73+
* @return array
74+
*/
75+
public function modifyDataProvider(): array
76+
{
77+
return [
78+
[
79+
'en_US',
80+
[
81+
'items' => [
82+
[
83+
'type_id' => 'simple',
84+
'attr1' => '99',
85+
]
86+
]
87+
],
88+
[
89+
'items' => [
90+
[
91+
'type_id' => 'simple',
92+
'attr1' => '99',
93+
]
94+
]
95+
],
96+
],
97+
[
98+
'en_US',
99+
[
100+
'items' => [
101+
[
102+
'type_id' => 'simple',
103+
'attr1' => '99',
104+
],
105+
[
106+
'type_id' => Type::TYPE_CODE,
107+
'attr1' => '99',
108+
]
109+
]
110+
],
111+
[
112+
'items' => [
113+
[
114+
'type_id' => 'simple',
115+
'attr1' => '99',
116+
],
117+
[
118+
'type_id' => Type::TYPE_CODE,
119+
'attr1' => '99.000000%',
120+
]
121+
]
122+
],
123+
],
124+
[
125+
'en_US',
126+
[
127+
'items' => [
128+
[
129+
'type_id' => Type::TYPE_CODE,
130+
'attr1' => '9999',
131+
]
132+
]
133+
],
134+
[
135+
'items' => [
136+
[
137+
'type_id' => Type::TYPE_CODE,
138+
'attr1' => '9,999.000000%',
139+
]
140+
]
141+
],
142+
],
143+
[
144+
'de_DE',
145+
[
146+
'items' => [
147+
[
148+
'type_id' => Type::TYPE_CODE,
149+
'attr1' => '9999',
150+
]
151+
]
152+
],
153+
[
154+
'items' => [
155+
[
156+
'type_id' => Type::TYPE_CODE,
157+
'attr1' => '9.999,000000 %',
158+
]
159+
]
160+
],
161+
]
162+
];
163+
}
164+
}

app/code/Magento/Bundle/Ui/DataProvider/Product/Modifier/SpecialPriceAttributes.php

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
namespace Magento\Bundle\Ui\DataProvider\Product\Modifier;
99

1010
use Magento\Bundle\Model\Product\Type;
11+
use Magento\Catalog\Api\Data\ProductInterface;
1112
use Magento\Directory\Model\Currency as DirectoryCurrency;
12-
use Magento\Framework\Currency\Data\Currency as CurrencyData;
13+
use Magento\Framework\App\ObjectManager;
1314
use Magento\Framework\Locale\ResolverInterface;
15+
use Magento\Framework\NumberFormatterFactory;
1416
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
1517
use NumberFormatter;
1618

@@ -19,8 +21,6 @@
1921
*/
2022
class SpecialPriceAttributes implements ModifierInterface
2123
{
22-
public const LOCALE_USING_DECIMAL_COMMA = ['nl_BE', 'nl_NL'];
23-
2424
/**
2525
* @var ResolverInterface
2626
*/
@@ -32,25 +32,29 @@ class SpecialPriceAttributes implements ModifierInterface
3232
private $priceAttributeList;
3333

3434
/**
35-
* @var DirectoryCurrency
35+
* @var NumberFormatterFactory
3636
*/
37-
private $directoryCurrency;
37+
private $numberFormatterFactory;
3838

3939
/**
4040
* PriceAttributes constructor.
4141
*
4242
* @param DirectoryCurrency $directoryCurrency
4343
* @param ResolverInterface $localeResolver
4444
* @param array $priceAttributeList
45+
* @param NumberFormatterFactory|null $numberFormatterFactory
46+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4547
*/
4648
public function __construct(
4749
DirectoryCurrency $directoryCurrency,
4850
ResolverInterface $localeResolver,
49-
array $priceAttributeList = []
51+
array $priceAttributeList = [],
52+
?NumberFormatterFactory $numberFormatterFactory = null
5053
) {
51-
$this->directoryCurrency = $directoryCurrency;
5254
$this->localeResolver = $localeResolver;
5355
$this->priceAttributeList = $priceAttributeList;
56+
$this->numberFormatterFactory = $numberFormatterFactory
57+
?? ObjectManager::getInstance()->get(NumberFormatterFactory::class);
5458
}
5559

5660
/**
@@ -61,24 +65,15 @@ public function modifyData(array $data): array
6165
if (empty($data) || empty($this->priceAttributeList)) {
6266
return $data;
6367
}
64-
$numberFormatter = new NumberFormatter(
65-
$this->localeResolver->getLocale(),
66-
NumberFormatter::PERCENT
67-
);
68-
$numberFormatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, 2);
68+
$numberFormatter = $this->numberFormatterFactory->create([
69+
'locale' => $this->localeResolver->getLocale(),
70+
'style' => NumberFormatter::PERCENT
71+
]);
72+
$numberFormatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, 6);
6973
foreach ($data['items'] as &$item) {
7074
foreach ($this->priceAttributeList as $priceAttribute) {
71-
if (isset($item[$priceAttribute]) && $item['type_id'] == Type::TYPE_CODE) {
72-
$item[$priceAttribute] =
73-
$this->directoryCurrency->format(
74-
$item[$priceAttribute],
75-
['display' => CurrencyData::NO_SYMBOL],
76-
false
77-
);
78-
if (in_array($this->localeResolver->getLocale(), self::LOCALE_USING_DECIMAL_COMMA)) {
79-
$item[$priceAttribute] = str_replace(['.',','], ['','.'], $item[$priceAttribute]);
80-
}
81-
$item[$priceAttribute] = $numberFormatter->format($item[$priceAttribute] / 100);
75+
if (isset($item[$priceAttribute]) && $item[ProductInterface::TYPE_ID] === Type::TYPE_CODE) {
76+
$item[$priceAttribute] = $numberFormatter->format((float) $item[$priceAttribute] / 100);
8277
}
8378
}
8479
}

app/code/Magento/Bundle/etc/adminhtml/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,11 @@
6969
<type name="Magento\Framework\Data\Form\Element\Fieldset">
7070
<plugin name="Bundle" type="Magento\Bundle\Plugin\Framework\Data\Form\Element\FieldsetPlugin"/>
7171
</type>
72+
<type name="Magento\Catalog\Ui\DataProvider\Product\Modifier\PriceAttributes">
73+
<arguments>
74+
<argument name="excludeProductTypes" xsi:type="array">
75+
<item name="bundle" xsi:type="const">Magento\Bundle\Model\Product\Type::TYPE_CODE</item>
76+
</argument>
77+
</arguments>
78+
</type>
7279
</config>

0 commit comments

Comments
 (0)