Skip to content

Commit b004c7a

Browse files
committed
Merge branch '2.2-develop' into 2.2-develop-pr8
2 parents c79dd63 + ef5da4d commit b004c7a

File tree

10 files changed

+93
-51
lines changed

10 files changed

+93
-51
lines changed

app/code/Magento/Catalog/view/frontend/layout/default.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
<item name="syncUrl" xsi:type="url" path="catalog/product/frontend_action_synchronize"/>
2323
</item>
2424
</item>
25+
<item name="product_data_storage" xsi:type="array">
26+
<item name="updateRequestConfig" xsi:type="array">
27+
<item name="url" xsi:type="serviceUrl" path="/products-render-info"/>
28+
</item>
29+
</item>
2530
</argument>
2631
</arguments>
2732
</block>

app/code/Magento/Catalog/view/frontend/web/js/storage-manager.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ define([
6666
'product_data_storage': {
6767
namespace: 'product_data_storage',
6868
className: 'DataStorage',
69-
allowToSendRequest: 0
69+
allowToSendRequest: 0,
70+
updateRequestConfig: {
71+
url: '',
72+
method: 'GET',
73+
dataType: 'json'
74+
}
7075
}
7176
},
7277
requestConfig: {

app/code/Magento/Tax/Block/Adminhtml/Rate/Grid/Renderer/Data.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,4 @@
1717
*/
1818
class Data extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
1919
{
20-
/**
21-
* @param \Magento\Framework\DataObject $row
22-
* @return int|string
23-
*/
24-
protected function _getValue(\Magento\Framework\DataObject $row)
25-
{
26-
$data = parent::_getValue($row);
27-
if (intval($data) == $data) {
28-
return (string)number_format($data, 2);
29-
}
30-
if ($data !== null) {
31-
return $data * 1;
32-
}
33-
return $this->getColumn()->getDefault();
34-
}
3520
}

app/code/Magento/Tax/Model/Calculation/Rate/Converter.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Tax\Model\Calculation\Rate;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\Locale\FormatInterface;
10+
811
/**
912
* Tax Rate Model converter.
1013
*
@@ -22,16 +25,24 @@ class Converter
2225
*/
2326
protected $taxRateTitleDataObjectFactory;
2427

28+
/**
29+
* @var FormatInterface|null
30+
*/
31+
private $format;
32+
2533
/**
2634
* @param \Magento\Tax\Api\Data\TaxRateInterfaceFactory $taxRateDataObjectFactory
27-
* @param \Magento\Tax\Api\Data\TaxRateTitleInterfaceFactory $taxRateTitleDataObjectFactory,
35+
* @param \Magento\Tax\Api\Data\TaxRateTitleInterfaceFactory $taxRateTitleDataObjectFactory
36+
* @param FormatInterface|null $format
2837
*/
2938
public function __construct(
3039
\Magento\Tax\Api\Data\TaxRateInterfaceFactory $taxRateDataObjectFactory,
31-
\Magento\Tax\Api\Data\TaxRateTitleInterfaceFactory $taxRateTitleDataObjectFactory
40+
\Magento\Tax\Api\Data\TaxRateTitleInterfaceFactory $taxRateTitleDataObjectFactory,
41+
FormatInterface $format = null
3242
) {
3343
$this->taxRateDataObjectFactory = $taxRateDataObjectFactory;
3444
$this->taxRateTitleDataObjectFactory = $taxRateTitleDataObjectFactory;
45+
$this->format = $format ?: ObjectManager::getInstance()->get(FormatInterface::class);
3546
}
3647

3748
/**
@@ -124,7 +135,7 @@ public function populateTaxRateData($formData)
124135
->setTaxRegionId($this->extractFormData($formData, 'tax_region_id'))
125136
->setTaxPostcode($this->extractFormData($formData, 'tax_postcode'))
126137
->setCode($this->extractFormData($formData, 'code'))
127-
->setRate($this->extractFormData($formData, 'rate'));
138+
->setRate($this->format->getNumber($this->extractFormData($formData, 'rate')));
128139
if (isset($formData['zip_is_range']) && $formData['zip_is_range']) {
129140
$taxRate->setZipFrom($this->extractFormData($formData, 'zip_from'))
130141
->setZipTo($this->extractFormData($formData, 'zip_to'))->setZipIsRange(1);

app/code/Magento/Tax/Model/Calculation/RateRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ private function validate(\Magento\Tax\Api\Data\TaxRateInterface $taxRate)
264264
);
265265
}
266266

267-
if (!\Zend_Validate::is($taxRate->getRate(), 'Float')) {
267+
if (!is_numeric($taxRate->getRate()) || $taxRate->getRate() < 0) {
268268
$exception->addError(__('%fieldName is a required field.', ['fieldName' => 'percentage_rate']));
269269
}
270270

app/code/Magento/Tax/Setup/UpgradeData.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,13 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
8686
$taxRateList = $this->taxRateRepository->getList($this->searchCriteriaFactory->create());
8787
/** @var \Magento\Tax\Api\Data\TaxRateInterface $taxRateData */
8888
foreach ($taxRateList->getItems() as $taxRateData) {
89-
if (!empty($taxRateData->getData('percentage_rate'))) {
90-
$regionCode = $this->parseRegionFromTaxCode($taxRateData->getCode());
91-
if ($regionCode) {
92-
/** @var \Magento\Directory\Model\Region $region */
93-
$region = $this->directoryRegionFactory->create();
94-
$region->loadByCode($regionCode, $taxRateData->getTaxCountryId());
95-
$taxRateData->setTaxRegionId($region->getRegionId());
96-
$this->taxRateRepository->save($taxRateData);
97-
}
89+
$regionCode = $this->parseRegionFromTaxCode($taxRateData->getCode());
90+
if ($regionCode) {
91+
/** @var \Magento\Directory\Model\Region $region */
92+
$region = $this->directoryRegionFactory->create();
93+
$region->loadByCode($regionCode, $taxRateData->getTaxCountryId());
94+
$taxRateData->setTaxRegionId($region->getRegionId());
95+
$this->taxRateRepository->save($taxRateData);
9896
}
9997
}
10098
}

app/code/Magento/Tax/Test/Unit/Model/Calculation/Rate/ConverterTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@ class ConverterTest extends \PHPUnit\Framework\TestCase
1515
protected $converter;
1616

1717
/**
18-
* @var \Magento\Tax\Api\Data\TaxRateInterfaceFactory
18+
* @var \Magento\Tax\Api\Data\TaxRateInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
1919
*/
2020
protected $taxRateDataObjectFactory;
2121

2222
/**
23-
* @var \Magento\Tax\Api\Data\TaxRateTitleInterfaceFactory
23+
* @var \Magento\Tax\Api\Data\TaxRateTitleInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
2424
*/
2525
protected $taxRateTitleDataObjectFactory;
2626

27+
/**
28+
* @var \Magento\Framework\Locale\FormatInterface|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $format;
31+
2732
/**
2833
* @var \Magento\Framework\TestFramework\Unit\Helper
2934
*/
@@ -45,12 +50,16 @@ protected function setUp()
4550
->setMethods(['create'])
4651
->getMock();
4752

53+
$this->format = $this->getMockBuilder(\Magento\Framework\Locale\FormatInterface::class)
54+
->getMock();
55+
4856
$this->objectManager = new ObjectManager($this);
4957
$this->converter = $this->objectManager->getObject(
5058
\Magento\Tax\Model\Calculation\Rate\Converter::class,
5159
[
5260
'taxRateDataObjectFactory' => $this->taxRateDataObjectFactory,
5361
'taxRateTitleDataObjectFactory' => $this->taxRateTitleDataObjectFactory,
62+
'format' => $this->format,
5463
]
5564
);
5665
}
@@ -109,12 +118,14 @@ public function testPopulateTaxRateData()
109118
$taxRate = $this->objectManager->getObject(
110119
\Magento\Tax\Model\Calculation\Rate::class,
111120
[
112-
'data' =>$dataArray,
121+
'data' => $dataArray,
113122
]
114123
);
115124

116125
$this->taxRateDataObjectFactory->expects($this->once())->method('create')->willReturn($taxRate);
117126

127+
$this->format->expects($this->once())->method('getNumber')->willReturnArgument(0);
128+
118129
$this->assertSame($taxRate, $this->converter->populateTaxRateData($dataArray));
119130
$this->assertEquals($taxRate->getTitles(), $rateTitles);
120131
}

app/code/Magento/Tax/Test/Unit/Model/Calculation/RateRepositoryTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,4 +426,42 @@ public function testValidateWithNoRate()
426426
);
427427
$this->model->save($rateMock);
428428
}
429+
430+
/**
431+
* @expectedException \Magento\Framework\Exception\InputException
432+
* @expectedExceptionMessage percentage_rate is a required field.
433+
*/
434+
public function testValidateWithWrongRate()
435+
{
436+
$rateTitles = ['Label 1', 'Label 2'];
437+
438+
$countryCode = 'US';
439+
$countryMock = $this->createMock(\Magento\Directory\Model\Country::class);
440+
$countryMock->expects($this->any())->method('getId')->will($this->returnValue(1));
441+
$countryMock->expects($this->any())->method('loadByCode')->with($countryCode)->will($this->returnSelf());
442+
$this->countryFactoryMock->expects($this->once())->method('create')->will($this->returnValue($countryMock));
443+
444+
$regionId = 2;
445+
$regionMock = $this->createMock(\Magento\Directory\Model\Region::class);
446+
$regionMock->expects($this->any())->method('getId')->will($this->returnValue($regionId));
447+
$regionMock->expects($this->any())->method('load')->with($regionId)->will($this->returnSelf());
448+
$this->regionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($regionMock));
449+
450+
$rateMock = $this->getTaxRateMock(
451+
[
452+
'id' => null,
453+
'tax_country_id' => $countryCode,
454+
'tax_region_id' => $regionId,
455+
'region_name' => null,
456+
'tax_postcode' => null,
457+
'zip_is_range' => true,
458+
'zip_from' => 90000,
459+
'zip_to' => 90005,
460+
'rate' => '7,9',
461+
'code' => 'Tax Rate Code',
462+
'titles' => $rateTitles,
463+
]
464+
);
465+
$this->model->save($rateMock);
466+
}
429467
}

dev/tests/integration/testsuite/Magento/Tax/Controller/Adminhtml/RateTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,6 @@ public function ajaxSaveActionDataInvalidDataProvider()
154154
],
155155
$expectedData
156156
],
157-
// Rate empty
158-
[
159-
[
160-
'rate' => '',
161-
'tax_country_id' => 'US',
162-
'tax_region_id' => '0',
163-
'code' => 'Rate ' . uniqid(),
164-
'zip_is_range' => '0',
165-
'zip_from' => '10000',
166-
'zip_to' => '20000',
167-
'tax_postcode' => '*',
168-
],
169-
$expectedData
170-
],
171157
// Tax zip code is empty
172158
[
173159
[

lib/internal/Magento/Framework/Session/SessionManager.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ public function start()
183183
// Need to apply the config options so they can be ready by session_start
184184
$this->initIniOptions();
185185
$this->registerSaveHandler();
186-
186+
$sid = $this->sidResolver->getSid($this);
187187
// potential custom logic for session id (ex. switching between hosts)
188-
$this->setSessionId($this->sidResolver->getSid($this));
188+
$this->setSessionId($sid);
189189
session_start();
190190
$this->validator->validate($this);
191-
$this->renewCookie();
191+
$this->renewCookie($sid);
192192

193193
register_shutdown_function([$this, 'writeClose']);
194194

@@ -202,14 +202,17 @@ public function start()
202202
/**
203203
* Renew session cookie to prolong session
204204
*
205+
* @param null|string $sid If we have session id we need to use it instead of old cookie value
205206
* @return $this
206207
*/
207-
private function renewCookie()
208+
private function renewCookie($sid)
208209
{
209210
if (!$this->getCookieLifetime()) {
210211
return $this;
211212
}
212-
$cookieValue = $this->cookieManager->getCookie($this->getName());
213+
//When we renew cookie, we should aware, that any other session client do not
214+
//change cookie too
215+
$cookieValue = $sid ?: $this->cookieManager->getCookie($this->getName());
213216
if ($cookieValue) {
214217
$metadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
215218
$metadata->setPath($this->sessionConfig->getCookiePath());

0 commit comments

Comments
 (0)