Skip to content

Commit

Permalink
Merge pull request #7894 from magento-l3/PR_20_SEP_2022
Browse files Browse the repository at this point in the history
L3 Bugfix delivery
  • Loading branch information
dhorytskyi authored Oct 4, 2022
2 parents 65c71f2 + ac2b4b5 commit e8f1b89
Show file tree
Hide file tree
Showing 27 changed files with 1,238 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
</actionGroup>
<!-- Asserting with the special price value contains the percentage value -->
<actionGroup ref="AdminAssertSpecialPriceAttributeValueOnProductGridPageActionGroup" stepKey="assertSpecialPricePercentageSymbol">
<argument name="expectedValue" value="90.00%"/>
<argument name="expectedValue" value="90.000000%"/>
</actionGroup>
</test>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Bundle\Test\Unit\Ui\DataProvider\Product\Modifier;

use Magento\Bundle\Model\Product\Type;
use Magento\Bundle\Ui\DataProvider\Product\Modifier\SpecialPriceAttributes;
use Magento\Directory\Model\Currency as DirectoryCurrency;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\NumberFormatter;
use Magento\Framework\NumberFormatterFactory;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class SpecialPriceAttributesTest extends TestCase
{
/**
* @var ResolverInterface|MockObject
*/
private $localResolver;

/**
* @var NumberFormatterFactory|MockObject
*/
private $numberFormatterFactory;

/**
* @var SpecialPriceAttributes
*/
private $model;

/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->localResolver = $this->createMock(ResolverInterface::class);
$this->numberFormatterFactory = $this->createMock(NumberFormatterFactory::class);
$this->model = new SpecialPriceAttributes(
$this->createMock(DirectoryCurrency::class),
$this->localResolver,
['attr1'],
$this->numberFormatterFactory
);
}

/**
* @param string $locale
* @param array $input
* @param array $output
* @return void
* @dataProvider modifyDataProvider
*/
public function testModifyData(string $locale, array $input, array $output): void
{
$this->localResolver->method('getLocale')
->willReturn($locale);
$this->numberFormatterFactory->method('create')
->willReturnCallback(
function (array $args) {
return new NumberFormatter(...array_values($args));
}
);
$this->assertEquals($output, $this->model->modifyData($input));
}

/**
* @return array
*/
public function modifyDataProvider(): array
{
return [
[
'en_US',
[
'items' => [
[
'type_id' => 'simple',
'attr1' => '99',
]
]
],
[
'items' => [
[
'type_id' => 'simple',
'attr1' => '99',
]
]
],
],
[
'en_US',
[
'items' => [
[
'type_id' => 'simple',
'attr1' => '99',
],
[
'type_id' => Type::TYPE_CODE,
'attr1' => '99',
]
]
],
[
'items' => [
[
'type_id' => 'simple',
'attr1' => '99',
],
[
'type_id' => Type::TYPE_CODE,
'attr1' => '99.000000%',
]
]
],
],
[
'en_US',
[
'items' => [
[
'type_id' => Type::TYPE_CODE,
'attr1' => '9999',
]
]
],
[
'items' => [
[
'type_id' => Type::TYPE_CODE,
'attr1' => '9,999.000000%',
]
]
],
],
[
'de_DE',
[
'items' => [
[
'type_id' => Type::TYPE_CODE,
'attr1' => '9999',
]
]
],
[
'items' => [
[
'type_id' => Type::TYPE_CODE,
'attr1' => '9.999,000000 %',
]
]
],
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
namespace Magento\Bundle\Ui\DataProvider\Product\Modifier;

use Magento\Bundle\Model\Product\Type;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Directory\Model\Currency as DirectoryCurrency;
use Magento\Framework\Currency\Data\Currency as CurrencyData;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\NumberFormatterFactory;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
use NumberFormatter;

Expand All @@ -19,8 +21,6 @@
*/
class SpecialPriceAttributes implements ModifierInterface
{
public const LOCALE_USING_DECIMAL_COMMA = ['nl_BE', 'nl_NL'];

/**
* @var ResolverInterface
*/
Expand All @@ -32,25 +32,29 @@ class SpecialPriceAttributes implements ModifierInterface
private $priceAttributeList;

/**
* @var DirectoryCurrency
* @var NumberFormatterFactory
*/
private $directoryCurrency;
private $numberFormatterFactory;

/**
* PriceAttributes constructor.
*
* @param DirectoryCurrency $directoryCurrency
* @param ResolverInterface $localeResolver
* @param array $priceAttributeList
* @param NumberFormatterFactory|null $numberFormatterFactory
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
DirectoryCurrency $directoryCurrency,
ResolverInterface $localeResolver,
array $priceAttributeList = []
array $priceAttributeList = [],
?NumberFormatterFactory $numberFormatterFactory = null
) {
$this->directoryCurrency = $directoryCurrency;
$this->localeResolver = $localeResolver;
$this->priceAttributeList = $priceAttributeList;
$this->numberFormatterFactory = $numberFormatterFactory
?? ObjectManager::getInstance()->get(NumberFormatterFactory::class);
}

/**
Expand All @@ -61,24 +65,15 @@ public function modifyData(array $data): array
if (empty($data) || empty($this->priceAttributeList)) {
return $data;
}
$numberFormatter = new NumberFormatter(
$this->localeResolver->getLocale(),
NumberFormatter::PERCENT
);
$numberFormatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, 2);
$numberFormatter = $this->numberFormatterFactory->create([
'locale' => $this->localeResolver->getLocale(),
'style' => NumberFormatter::PERCENT
]);
$numberFormatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, 6);
foreach ($data['items'] as &$item) {
foreach ($this->priceAttributeList as $priceAttribute) {
if (isset($item[$priceAttribute]) && $item['type_id'] == Type::TYPE_CODE) {
$item[$priceAttribute] =
$this->directoryCurrency->format(
$item[$priceAttribute],
['display' => CurrencyData::NO_SYMBOL],
false
);
if (in_array($this->localeResolver->getLocale(), self::LOCALE_USING_DECIMAL_COMMA)) {
$item[$priceAttribute] = str_replace(['.',','], ['','.'], $item[$priceAttribute]);
}
$item[$priceAttribute] = $numberFormatter->format($item[$priceAttribute] / 100);
if (isset($item[$priceAttribute]) && $item[ProductInterface::TYPE_ID] === Type::TYPE_CODE) {
$item[$priceAttribute] = $numberFormatter->format((float) $item[$priceAttribute] / 100);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/Bundle/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,11 @@
<type name="Magento\Framework\Data\Form\Element\Fieldset">
<plugin name="Bundle" type="Magento\Bundle\Plugin\Framework\Data\Form\Element\FieldsetPlugin"/>
</type>
<type name="Magento\Catalog\Ui\DataProvider\Product\Modifier\PriceAttributes">
<arguments>
<argument name="excludeProductTypes" xsi:type="array">
<item name="bundle" xsi:type="const">Magento\Bundle\Model\Product\Type::TYPE_CODE</item>
</argument>
</arguments>
</type>
</config>
Loading

0 comments on commit e8f1b89

Please sign in to comment.