Skip to content

Commit de47a2f

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-99152' into 2.3-develop-pr21
2 parents e2389ee + f7d70bc commit de47a2f

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
namespace Magento\Catalog\Model\Product\Attribute\Backend\TierPrice;
99

10-
use Magento\Framework\EntityManager\Operation\ExtensionInterface;
1110
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Locale\FormatInterface;
1213
use Magento\Store\Model\StoreManagerInterface;
1314
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
1415
use Magento\Customer\Api\GroupManagementInterface;
@@ -40,26 +41,34 @@ class UpdateHandler extends AbstractHandler
4041
*/
4142
private $tierPriceResource;
4243

44+
/**
45+
* @var FormatInterface
46+
*/
47+
private $localeFormat;
48+
4349
/**
4450
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4551
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository
4652
* @param \Magento\Customer\Api\GroupManagementInterface $groupManagement
4753
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
4854
* @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice $tierPriceResource
55+
* @param FormatInterface|null $localeFormat
4956
*/
5057
public function __construct(
5158
StoreManagerInterface $storeManager,
5259
ProductAttributeRepositoryInterface $attributeRepository,
5360
GroupManagementInterface $groupManagement,
5461
MetadataPool $metadataPool,
55-
Tierprice $tierPriceResource
62+
Tierprice $tierPriceResource,
63+
FormatInterface $localeFormat = null
5664
) {
5765
parent::__construct($groupManagement);
5866

5967
$this->storeManager = $storeManager;
6068
$this->attributeRepository = $attributeRepository;
6169
$this->metadataPoll = $metadataPool;
6270
$this->tierPriceResource = $tierPriceResource;
71+
$this->localeFormat = $localeFormat ?: ObjectManager::getInstance()->get(FormatInterface::class);
6372
}
6473

6574
/**
@@ -125,8 +134,9 @@ private function updateValues(array $valuesToUpdate, array $oldValues): bool
125134
{
126135
$isChanged = false;
127136
foreach ($valuesToUpdate as $key => $value) {
128-
if ((!empty($value['value']) && (float)$oldValues[$key]['price'] !== (float)$value['value'])
129-
|| $this->getPercentage($oldValues[$key]) !== $this->getPercentage($value)
137+
if ((!empty($value['value'])
138+
&& (float)$oldValues[$key]['price'] !== $this->localeFormat->getNumber($value['value'])
139+
) || $this->getPercentage($oldValues[$key]) !== $this->getPercentage($value)
130140
) {
131141
$price = new \Magento\Framework\DataObject(
132142
[

lib/internal/Magento/Framework/Locale/Format.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
*/
1111
class Format implements \Magento\Framework\Locale\FormatInterface
1212
{
13+
/**
14+
* Japan locale code
15+
*/
16+
private const JAPAN_LOCALE_CODE = 'ja_JP';
17+
1318
/**
1419
* @var \Magento\Framework\App\ScopeResolverInterface
1520
*/
@@ -81,7 +86,16 @@ public function getNumber($value)
8186
$value = str_replace(',', '', $value);
8287
}
8388
} elseif ($separatorComa !== false) {
84-
$value = str_replace(',', '.', $value);
89+
$locale = $this->_localeResolver->getLocale();
90+
/**
91+
* It's hard code for Japan locale.
92+
* Comma separator uses as group separator: 4,000 saves as 4,000.00
93+
*/
94+
$value = str_replace(
95+
',',
96+
$locale === self::JAPAN_LOCALE_CODE ? '' : '.',
97+
$value
98+
);
8599
}
86100

87101
return (float)$value;

lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\Framework\Locale\Test\Unit;
88

9+
/**
10+
* Tests class for Number locale format
11+
*/
912
class FormatTest extends \PHPUnit\Framework\TestCase
1013
{
1114
/**
@@ -103,10 +106,14 @@ public function getPriceFormatDataProvider(): array
103106
*
104107
* @param mixed $value
105108
* @param float $expected
109+
* @param string $locale
106110
* @dataProvider provideNumbers
107111
*/
108-
public function testGetNumber($value, $expected): void
112+
public function testGetNumber(string $value, float $expected, string $locale = null): void
109113
{
114+
if ($locale !== null) {
115+
$this->localeResolver->method('getLocale')->willReturn($locale);
116+
}
110117
$this->assertEquals($expected, $this->formatModel->getNumber($value));
111118
}
112119

@@ -127,6 +134,8 @@ public function provideNumbers(): array
127134
['2 054.52', 2054.52],
128135
['2,46 GB', 2.46],
129136
['2,054.00', 2054],
137+
['4,000', 4000.0, 'ja_JP'],
138+
['4,000', 4.0, 'en_US'],
130139
];
131140
}
132141
}

0 commit comments

Comments
 (0)