Skip to content

Commit 3002ec8

Browse files
committed
Merge branch 'MAGETWO-63987' of github.com:magento-troll/magento2ce into MAGETWO-62334
2 parents c3dd21e + 7ab088b commit 3002ec8

File tree

9 files changed

+105
-33
lines changed

9 files changed

+105
-33
lines changed

app/bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@
5858
}
5959

6060
date_default_timezone_set('UTC');
61+
62+
/* Adjustment of precision value for several versions of PHP */
63+
ini_set('precision', 17);
64+
ini_set('serialize_precision', 17);

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\Sales\Setup;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\DB\FieldDataConverterFactory;
10+
use Magento\Framework\DB\DataConverter\SerializedToJson;
11+
812
/**
913
* Data upgrade script
1014
*/
@@ -27,21 +31,30 @@ class UpgradeData implements \Magento\Framework\Setup\UpgradeDataInterface
2731
*/
2832
private $convertSerializedDataToJsonFactory;
2933

34+
/**
35+
* @var FieldDataConverterFactory
36+
*/
37+
private $fieldDataConverterFactory;
38+
3039
/**
3140
* Constructor
3241
*
3342
* @param \Magento\Sales\Setup\SalesSetupFactory $salesSetupFactory
3443
* @param \Magento\Sales\Setup\ConvertSerializedDataToJsonFactory $convertSerializedDataToJsonFactory
3544
* @param \Magento\Eav\Model\Config $eavConfig
45+
* @param FieldDataConverterFactory $fieldDataConverterFactory
3646
*/
3747
public function __construct(
3848
\Magento\Sales\Setup\SalesSetupFactory $salesSetupFactory,
3949
\Magento\Sales\Setup\ConvertSerializedDataToJsonFactory $convertSerializedDataToJsonFactory,
40-
\Magento\Eav\Model\Config $eavConfig
50+
\Magento\Eav\Model\Config $eavConfig,
51+
FieldDataConverterFactory $fieldDataConverterFactory = null
4152
) {
4253
$this->salesSetupFactory = $salesSetupFactory;
4354
$this->convertSerializedDataToJsonFactory = $convertSerializedDataToJsonFactory;
4455
$this->eavConfig = $eavConfig;
56+
$this->fieldDataConverterFactory = $fieldDataConverterFactory ?: ObjectManager::getInstance()
57+
->get(FieldDataConverterFactory::class);
4558
}
4659

4760
/**
@@ -59,6 +72,21 @@ public function upgrade(
5972
$this->convertSerializedDataToJsonFactory->create(['salesSetup' => $salesSetup])
6073
->convert();
6174
}
75+
if (version_compare($context->getVersion(), '2.0.6', '<')) {
76+
$fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class);
77+
$fieldDataConverter->convert(
78+
$salesSetup->getConnection(),
79+
$salesSetup->getTable('sales_invoice_item'),
80+
'entity_id',
81+
'tax_ratio'
82+
);
83+
$fieldDataConverter->convert(
84+
$salesSetup->getConnection(),
85+
$salesSetup->getTable('sales_creditmemo_item'),
86+
'entity_id',
87+
'tax_ratio'
88+
);
89+
}
6290
$this->eavConfig->clear();
6391
}
6492

app/code/Magento/Sales/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Sales" setup_version="2.0.5">
9+
<module name="Magento_Sales" setup_version="2.0.6">
1010
<sequence>
1111
<module name="Magento_Rule"/>
1212
<module name="Magento_Catalog"/>

app/code/Magento/Weee/Model/Total/Creditmemo/Weee.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,42 @@
88

99
use Magento\Sales\Model\Order\Creditmemo;
1010
use Magento\Weee\Helper\Data as WeeeHelper;
11+
use Magento\Framework\Serialize\Serializer\Json;
12+
use Magento\Framework\App\ObjectManager;
1113

1214
class Weee extends \Magento\Sales\Model\Order\Creditmemo\Total\AbstractTotal
1315
{
1416
/**
1517
* Weee data
1618
*
17-
* @var \Magento\Weee\Helper\Data
19+
* @var WeeeHelper
1820
*/
1921
protected $_weeeData = null;
2022

23+
/**
24+
* Instance of serializer.
25+
*
26+
* @var Json
27+
*/
28+
private $serializer;
29+
2130
/**
2231
* Constructor
2332
*
2433
* By default is looking for first argument as array and assigns it as object
2534
* attributes This behavior may change in child classes
2635
*
27-
* @param \Magento\Weee\Helper\Data $weeeData
28-
* @param array $data
36+
* @param WeeeHelper $weeeData
37+
* @param array $data
38+
* @param Json|null $serializer
2939
*/
30-
public function __construct(\Magento\Weee\Helper\Data $weeeData, array $data = [])
31-
{
40+
public function __construct(
41+
WeeeHelper $weeeData,
42+
array $data = [],
43+
Json $serializer = null
44+
) {
3245
$this->_weeeData = $weeeData;
46+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
3347
parent::__construct($data);
3448
}
3549

@@ -113,10 +127,10 @@ public function collect(Creditmemo $creditmemo)
113127
if ($orderItemTaxAmount != 0) {
114128
$taxRatio = [];
115129
if ($item->getTaxRatio()) {
116-
$taxRatio = unserialize($item->getTaxRatio());
130+
$taxRatio = $this->serializer->unserialize($item->getTaxRatio());
117131
}
118132
$taxRatio[\Magento\Weee\Model\Total\Quote\Weee::ITEM_TYPE] = $itemTaxAmount / $orderItemTaxAmount;
119-
$item->setTaxRatio(serialize($taxRatio));
133+
$item->setTaxRatio($this->serializer->serialize($taxRatio));
120134
}
121135

122136
$totalWeeeAmountInclTax += $weeeAmountInclTax;
@@ -126,11 +140,11 @@ public function collect(Creditmemo $creditmemo)
126140
$applied = $this->_weeeData->getApplied($orderItem);
127141
foreach ($applied as $one) {
128142
$title = (string)$one['title'];
129-
$one['base_row_amount'] = $creditmemo->roundPrice($one['base_row_amount'] * $ratio, $title.'_base');
143+
$one['base_row_amount'] = $creditmemo->roundPrice($one['base_row_amount'] * $ratio, $title . '_base');
130144
$one['row_amount'] = $creditmemo->roundPrice($one['row_amount'] * $ratio, $title);
131145
$one['base_row_amount_incl_tax'] = $creditmemo->roundPrice(
132146
$one['base_row_amount_incl_tax'] * $ratio,
133-
$title.'_base'
147+
$title . '_base'
134148
);
135149
$one['row_amount_incl_tax'] = $creditmemo->roundPrice($one['row_amount_incl_tax'] * $ratio, $title);
136150

app/code/Magento/Weee/Model/Total/Invoice/Weee.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,42 @@
66
namespace Magento\Weee\Model\Total\Invoice;
77

88
use Magento\Weee\Helper\Data as WeeeHelper;
9+
use Magento\Framework\Serialize\Serializer\Json;
10+
use Magento\Framework\App\ObjectManager;
911

1012
class Weee extends \Magento\Sales\Model\Order\Invoice\Total\AbstractTotal
1113
{
1214
/**
1315
* Weee data
1416
*
15-
* @var \Magento\Weee\Helper\Data
17+
* @var WeeeHelper
1618
*/
1719
protected $_weeeData = null;
1820

21+
/**
22+
* Instance of serializer.
23+
*
24+
* @var Json
25+
*/
26+
private $serializer;
27+
1928
/**
2029
* Constructor
2130
*
2231
* By default is looking for first argument as array and assigns it as object
2332
* attributes This behavior may change in child classes
2433
*
25-
* @param \Magento\Weee\Helper\Data $weeeData
26-
* @param array $data
34+
* @param WeeeHelper $weeeData
35+
* @param array $data
36+
* @param Json|null $serializer
2737
*/
28-
public function __construct(\Magento\Weee\Helper\Data $weeeData, array $data = [])
29-
{
38+
public function __construct(
39+
WeeeHelper $weeeData,
40+
array $data = [],
41+
Json $serializer = null
42+
) {
3043
$this->_weeeData = $weeeData;
44+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
3145
parent::__construct($data);
3246
}
3347

@@ -94,10 +108,10 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
94108
if ($orderItemWeeeTax != 0) {
95109
$taxRatio = [];
96110
if ($item->getTaxRatio()) {
97-
$taxRatio = unserialize($item->getTaxRatio());
111+
$taxRatio = $this->serializer->unserialize($item->getTaxRatio());
98112
}
99113
$taxRatio[\Magento\Weee\Model\Total\Quote\Weee::ITEM_TYPE] = $itemWeeeTax / $orderItemWeeeTax;
100-
$item->setTaxRatio(serialize($taxRatio));
114+
$item->setTaxRatio($this->serializer->serialize($taxRatio));
101115
}
102116

103117
$item->setWeeeTaxAppliedRowAmount($weeeAmount);

app/code/Magento/Weee/Test/Unit/Model/Total/Creditmemo/WeeeTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Weee\Test\Unit\Model\Total\Creditmemo;
77

8+
use Magento\Framework\Serialize\Serializer\Json;
9+
810
class WeeeTest extends \PHPUnit_Framework_TestCase
911
{
1012
/**
@@ -60,11 +62,13 @@ protected function setUp()
6062
->getMock();
6163

6264
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
65+
$serializer = $this->getMock(Json::class, null);
6366
/** @var \Magento\Sales\Model\Order\Invoice\Total\Tax $model */
6467
$this->model = $this->objectManager->getObject(
6568
\Magento\Weee\Model\Total\Creditmemo\Weee::class,
6669
[
6770
'weeeData' => $this->weeeData,
71+
'serializer' => $serializer
6872
]
6973
);
7074

@@ -148,9 +152,8 @@ function ($price, $type) use (&$roundingDelta) {
148152
$creditmemoItem = $creditmemoItems[$itemKey];
149153
foreach ($itemData as $key => $value) {
150154
if ($key == 'tax_ratio') {
151-
$taxRatio = unserialize($creditmemoItem->getData($key));
152-
$expectedTaxRatio = unserialize($itemData[$key]);
153-
$this->assertEquals($expectedTaxRatio['weee'], $taxRatio['weee'], "Tax ratio is incorrect");
155+
$taxRatio = json_decode($creditmemoItem->getData($key), true);
156+
$this->assertEquals($value['weee'], $taxRatio['weee'], "Tax ratio is incorrect");
154157
} else {
155158
$this->assertEquals(
156159
$value,
@@ -234,7 +237,7 @@ public function collectDataProvider()
234237
'row_amount_incl_tax' => 32.47,
235238
],
236239
],
237-
'tax_ratio' => serialize(['weee' => 1.0]),
240+
'tax_ratio' => ["weee" => 1.0],
238241
'weee_tax_applied_row_amount' => 30,
239242
'base_weee_tax_applied_row_amount' => 30,
240243
],
@@ -316,7 +319,7 @@ public function collectDataProvider()
316319
'row_amount_incl_tax' => 21.65,
317320
],
318321
],
319-
'tax_ratio' => serialize(['weee' => 1.65 / 2.47]),
322+
'tax_ratio' => ['weee' => 1.65 / 2.47],
320323
'weee_tax_applied_row_amount' => 20,
321324
'base_weee_tax_applied_row_amount' => 20,
322325
],
@@ -398,7 +401,7 @@ public function collectDataProvider()
398401
'row_amount_incl_tax' => 10.82,
399402
],
400403
],
401-
'tax_ratio' => serialize(['weee' => 0.83 / 2.47]),
404+
'tax_ratio' => ['weee' => 0.83 / 2.47],
402405
'weee_tax_applied_row_amount' => 10,
403406
'base_weee_tax_applied_row_amount' => 10,
404407
],

app/code/Magento/Weee/Test/Unit/Model/Total/Invoice/WeeeTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Weee\Test\Unit\Model\Total\Invoice;
77

8+
use Magento\Framework\Serialize\Serializer\Json;
9+
810
class WeeeTest extends \PHPUnit_Framework_TestCase
911
{
1012
/**
@@ -51,11 +53,13 @@ protected function setUp()
5153
->getMock();
5254

5355
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
56+
$serializer = $this->getMock(Json::class, null);
5457
/** @var \Magento\Sales\Model\Order\Invoice\Total\Tax $model */
5558
$this->model = $this->objectManager->getObject(
5659
\Magento\Weee\Model\Total\Invoice\Weee::class,
5760
[
5861
'weeeData' => $this->weeeData,
62+
'serializer' => $serializer
5963
]
6064
);
6165

@@ -151,9 +155,8 @@ function ($price, $type) use (&$roundingDelta) {
151155
$invoiceItem = $invoiceItems[$itemKey];
152156
foreach ($itemData as $key => $value) {
153157
if ($key == 'tax_ratio') {
154-
$taxRatio = unserialize($invoiceItem->getData($key));
155-
$expectedTaxRatio = unserialize($itemData[$key]);
156-
$this->assertEquals($expectedTaxRatio['weee'], $taxRatio['weee'], "Tax ratio is incorrect");
158+
$taxRatio = json_decode($invoiceItem->getData($key), true);
159+
$this->assertEquals($value['weee'], $taxRatio['weee'], "Tax ratio is incorrect");
157160
} else {
158161
$this->assertEquals(
159162
$value,
@@ -258,7 +261,7 @@ public function collectDataProvider()
258261
],
259262
'weee_tax_applied_row_amount' => 30,
260263
'base_weee_tax_applied_row_amount' => 30,
261-
'tax_ratio' => serialize(['weee' => 1.0]),
264+
'tax_ratio' => ["weee" => 1.0],
262265
],
263266
],
264267
'invoice_data' => [
@@ -357,7 +360,7 @@ public function collectDataProvider()
357360
'row_amount_incl_tax' => 21.65,
358361
],
359362
],
360-
'tax_ratio' => serialize(['weee' => 1.65 / 2.47]),
363+
'tax_ratio' => ['weee' => 1.65 / 2.47],
361364
'weee_tax_applied_row_amount' => 20,
362365
'base_weee_tax_applied_row_amount' => 20,
363366
],
@@ -459,7 +462,7 @@ public function collectDataProvider()
459462
'row_amount_incl_tax' => 10.82,
460463
],
461464
],
462-
'tax_ratio' => serialize(['weee' => 0.82 / 2.47]),
465+
'tax_ratio' => ['weee' => 0.82 / 2.47],
463466
'weee_tax_applied_row_amount' => 10,
464467
'base_weee_tax_applied_row_amount' => 10,
465468
],
@@ -561,7 +564,7 @@ public function collectDataProvider()
561564
'row_amount_incl_tax' => 10.82,
562565
],
563566
],
564-
'tax_ratio' => serialize(['weee' => 0.83 / 2.47]),
567+
'tax_ratio' => ['weee' => 0.83 / 2.47],
565568
'weee_tax_applied_row_amount' => 10,
566569
'base_weee_tax_applied_row_amount' => 10,
567570

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

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

77
namespace Magento\Widget\Setup;
88

9-
use Magento\Framework\App\ObjectManager;
109
use Magento\Framework\Setup\UpgradeDataInterface;
1110
use Magento\Framework\Setup\ModuleContextInterface;
1211
use Magento\Framework\Setup\ModuleDataSetupInterface;

dev/tests/static/testsuite/Magento/Test/Integrity/HhvmCompatibilityTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ class HhvmCompatibilityTest extends \PHPUnit_Framework_TestCase
3737
'display_errors',
3838
'default_socket_timeout',
3939
'pcre.recursion_limit',
40-
'default_charset'
40+
'default_charset',
41+
42+
/*
43+
There is not way to specify calculation/serialization precision in hhvm.
44+
Adding to whitelist in order to align precisions in php.
45+
*/
46+
'precision',
47+
'serialize_precision',
4148
];
4249

4350
public function testAllowedIniGetSetDirectives()

0 commit comments

Comments
 (0)