Skip to content

Commit db2c7b2

Browse files
Manjusha.SManjusha.S
authored andcommitted
Merge branch '2.4-develop' of https://github.com/magento-gl/magento2ce into AC-4284
2 parents 5e0bcb2 + 49bd706 commit db2c7b2

File tree

100 files changed

+2794
-367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2794
-367
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ protected function _importData()
316316
} elseif (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $this->getBehavior()) {
317317
$this->saveAdvancedPricing();
318318
}
319-
320319
return true;
321320
}
322321

@@ -342,7 +341,7 @@ public function deleteAdvancedPricing()
342341
{
343342
$this->_cachedSkuToDelete = null;
344343
$listSku = [];
345-
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
344+
while ($bunch = $this->_dataSourceModel->getNextUniqueBunch($this->getIds())) {
346345
foreach ($bunch as $rowNum => $rowData) {
347346
$this->validateRow($rowData, $rowNum);
348347
if (!$this->getErrorAggregator()->isRowInvalid($rowNum)) {
@@ -389,7 +388,7 @@ protected function saveAndReplaceAdvancedPrices()
389388
}
390389
$listSku = [];
391390
$tierPrices = [];
392-
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
391+
while ($bunch = $this->_dataSourceModel->getNextUniqueBunch($this->getIds())) {
393392
$bunchTierPrices = [];
394393
foreach ($bunch as $rowNum => $rowData) {
395394
if (!$this->validateRow($rowData, $rowNum)) {

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Import/AdvancedPricingTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class AdvancedPricingTest extends AbstractImportTestCase
3939
/**
4040
* DB Table data
4141
*/
42-
const TABLE_NAME = 'tableName';
43-
const LINK_FIELD = 'linkField';
42+
public const TABLE_NAME = 'tableName';
43+
public const LINK_FIELD = 'linkField';
4444

4545
/**
4646
* @var ResourceFactory|MockObject
@@ -328,7 +328,7 @@ public function testSaveAndReplaceAdvancedPricesAddRowErrorCall(): void
328328
]
329329
];
330330
$this->dataSourceModel
331-
->method('getNextBunch')
331+
->method('getNextUniqueBunch')
332332
->willReturnOnConsecutiveCalls($testBunch);
333333
$this->advancedPricing->expects($this->once())->method('validateRow')->willReturn(false);
334334
$this->advancedPricing->method('saveProductPrices')->willReturnSelf();
@@ -400,7 +400,7 @@ public function testSaveAndReplaceAdvancedPricesAppendBehaviourDataAndCalls(
400400
->method('getBehavior')
401401
->willReturn(Import::BEHAVIOR_APPEND);
402402
$this->dataSourceModel
403-
->method('getNextBunch')
403+
->method('getNextUniqueBunch')
404404
->willReturnOnConsecutiveCalls($data);
405405
$advancedPricing->method('validateRow')->willReturn(true);
406406

@@ -524,7 +524,7 @@ public function testSaveAndReplaceAdvancedPricesReplaceBehaviourInternalCalls():
524524
Import::BEHAVIOR_REPLACE
525525
);
526526
$this->dataSourceModel
527-
->method('getNextBunch')
527+
->method('getNextUniqueBunch')
528528
->willReturnOnConsecutiveCalls($data);
529529
$this->advancedPricing->expects($this->once())->method('validateRow')->willReturn(true);
530530

@@ -577,7 +577,7 @@ public function testDeleteAdvancedPricingFormListSkuToDelete(): void
577577
];
578578

579579
$this->dataSourceModel
580-
->method('getNextBunch')
580+
->method('getNextUniqueBunch')
581581
->willReturnOnConsecutiveCalls($data);
582582
$this->advancedPricing->method('validateRow')->willReturn(true);
583583
$expectedSkuList = ['sku value'];

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>

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ public function execute()
326326
return $this->returnResult('catalog/*/', [], ['error' => false]);
327327
} catch (\Exception $e) {
328328
$this->messageManager->addErrorMessage($e->getMessage());
329+
if ($attributeId === null) {
330+
unset($data['frontend_input']);
331+
}
329332
$this->_session->setAttributeData($data);
330333
return $this->returnResult(
331334
'catalog/*/edit',

0 commit comments

Comments
 (0)