Skip to content

Commit 89e16e7

Browse files
committed
Merge pull request #578 from magento-fearless-kiwis/develop
[FearlessKiwis] Sprint 64-c: Bug fixes
2 parents 12efdf6 + 12f5e44 commit 89e16e7

File tree

5 files changed

+79
-9
lines changed

5 files changed

+79
-9
lines changed

app/code/Magento/Directory/Model/Currency.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public function getOutputFormat()
330330
{
331331
$formatted = $this->formatTxt(0);
332332
$number = $this->formatTxt(0, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
333-
return str_replace($number, '%s', $formatted);
333+
return str_replace($this->trimUnicodeDirectionMark($number), '%s', $formatted);
334334
}
335335

336336
/**
@@ -402,4 +402,18 @@ public function saveRates($rates)
402402
$this->_getResource()->saveRates($rates);
403403
return $this;
404404
}
405+
406+
/**
407+
* This method removes LRM and RLM marks from string
408+
*
409+
* @param string $string
410+
* @return $this
411+
*/
412+
private function trimUnicodeDirectionMark($string)
413+
{
414+
if (preg_match('/^(\x{200E}|\x{200F})/u', $string, $match)) {
415+
$string = preg_replace('/^'.$match[1].'/u', '', $string);
416+
}
417+
return $string;
418+
}
405419
}

app/code/Magento/Directory/Test/Unit/Model/CurrencyTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,49 @@ public function testGetCurrencySymbol()
5252
->willReturn($currencyMock);
5353
$this->assertEquals($currencySymbol, $this->currency->getCurrencySymbol());
5454
}
55+
56+
/**
57+
* @dataProvider getOutputFormatDataProvider
58+
* @param $withCurrency
59+
* @param $noCurrency
60+
* @param $expected
61+
*/
62+
public function testGetOutputFormat($withCurrency, $noCurrency, $expected)
63+
{
64+
$currencyMock = $this->getMockBuilder('\Magento\Framework\Currency')
65+
->disableOriginalConstructor()
66+
->getMock();
67+
$currencyMock->expects($this->at(0))
68+
->method('toCurrency')
69+
->willReturn($withCurrency);
70+
$currencyMock->expects($this->at(1))
71+
->method('toCurrency')
72+
->willReturn($noCurrency);
73+
$this->localeCurrencyMock->expects($this->atLeastOnce())
74+
->method('getCurrency')
75+
->with($this->currencyCode)
76+
->willReturn($currencyMock);
77+
$this->assertEquals($expected, $this->currency->getOutputFormat());
78+
}
79+
80+
/**
81+
* Return data sets for testGetCurrencySymbol()
82+
*
83+
* @return array
84+
*/
85+
public function getOutputFormatDataProvider()
86+
{
87+
return [
88+
'no_unicode' => [
89+
'withCurrency' => '$0.00',
90+
'noCurrency' => '0.00',
91+
'expected' => '$%s',
92+
],
93+
'arabic_unicode' => [
94+
'withCurrency' => json_decode('"\u200E"') . '$0.00',
95+
'noCurrency' => json_decode('"\u200E"') . '0.00',
96+
'expected' => json_decode('"\u200E"') . '$%s',
97+
]
98+
];
99+
}
55100
}

app/code/Magento/Rule/Block/Editable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
5454
'" value="' .
5555
$element->getValue() .
5656
'" data-form-part="' .
57-
$element->getDataFormPart() .
57+
$element->getData('data-form-part') .
5858
'"/> ' .
5959
htmlspecialchars(
6060
$valueName

app/code/Magento/Rule/Model/Condition/AbstractCondition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ public function getAttributeElement()
531531
'values' => $this->getAttributeSelectOptions(),
532532
'value' => $this->getAttribute(),
533533
'value_name' => $this->getAttributeName(),
534-
'data_form_part' => $this->getFormName()
534+
'data-form-part' => $this->getFormName()
535535
]
536536
)->setRenderer(
537537
$this->_layout->getBlockSingleton('Magento\Rule\Block\Editable')

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
class Format implements \Magento\Framework\Locale\FormatInterface
1111
{
12+
/**
13+
* @var string
14+
*/
15+
private static $defaultNumberSet = 'latn';
16+
1217
/**
1318
* @var \Magento\Framework\App\ScopeResolverInterface
1419
*/
@@ -104,12 +109,18 @@ public function getPriceFormat($localeCode = null, $currencyCode = null)
104109
$currency = $this->_scopeResolver->getScope()->getCurrentCurrency();
105110
}
106111
$localeData = (new DataBundle())->get($localeCode);
107-
$format = $localeData['NumberElements']['latn']['patterns']['currencyFormat']
108-
?: explode(';', $localeData['NumberPatterns'][1])[0];
109-
$decimalSymbol = $localeData['NumberElements']['latn']['symbols']['decimal']
110-
?: $localeData['NumberElements'][0];
111-
$groupSymbol = $localeData['NumberElements']['latn']['symbols']['group']
112-
?: $localeData['NumberElements'][1];
112+
$defaultSet = $localeData['NumberElements']['default'] ?: self::$defaultNumberSet;
113+
$format = $localeData['NumberElements'][$defaultSet]['patterns']['currencyFormat']
114+
?: ($localeData['NumberElements'][self::$defaultNumberSet]['patterns']['currencyFormat']
115+
?: explode(';', $localeData['NumberPatterns'][1])[0]);
116+
117+
$decimalSymbol = $localeData['NumberElements'][$defaultSet]['symbols']['decimal']
118+
?: ($localeData['NumberElements'][self::$defaultNumberSet]['symbols']['decimal']
119+
?: $localeData['NumberElements'][0]);
120+
121+
$groupSymbol = $localeData['NumberElements'][$defaultSet]['symbols']['group']
122+
?: ($localeData['NumberElements'][self::$defaultNumberSet]['symbols']['group']
123+
?: $localeData['NumberElements'][1]);
113124

114125
$pos = strpos($format, ';');
115126
if ($pos !== false) {

0 commit comments

Comments
 (0)