Skip to content

Commit 8752f42

Browse files
committed
Merge remote-tracking branches 'perf/pr-2.2-develop' and 'mpi/MPI-PR-Regression2' into perf_mpi
2 parents ad99cc2 + 8958b13 commit 8752f42

File tree

12 files changed

+256
-78
lines changed

12 files changed

+256
-78
lines changed

app/bootstrap.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@
6262

6363
date_default_timezone_set('UTC');
6464

65-
/* Adjustment of precision value for several versions of PHP */
66-
ini_set('precision', 17);
67-
ini_set('serialize_precision', 17);
65+
/* For data consistency between displaying (printing) and serialization a float number */
66+
ini_set('precision', 14);
67+
ini_set('serialize_precision', 14);

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,9 @@ public function applyCoupon($code)
15861586
public function setAccountData($accountData)
15871587
{
15881588
$customer = $this->getQuote()->getCustomer();
1589+
if (empty($accountData['email'])) {
1590+
$accountData['email'] = $customer->getEmail();
1591+
}
15891592
$form = $this->_createCustomerForm($customer);
15901593

15911594
// emulate request

app/code/Magento/Sales/view/adminhtml/templates/order/create/billing/method/form.phtml

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,62 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
?>
10-
<?php if ($block->hasMethods()): ?>
8+
<?php if ($block->hasMethods()) : ?>
119
<div id="order-billing_method_form">
1210
<dl class="admin__payment-methods">
1311
<?php
14-
$_methods = $block->getMethods();
15-
$_methodsCount = count($_methods);
12+
$_methods = $block->getMethods();
13+
$_methodsCount = count($_methods);
1614
$_counter = 0;
1715
?>
18-
<?php foreach ($_methods as $_method): $_code = $_method->getCode(); $_counter++; ?>
16+
<?php foreach ($_methods as $_method) :
17+
$_code = $_method->getCode();
18+
$_counter++;
19+
?>
1920
<dt class="admin__field-option">
20-
<?php if ($_methodsCount > 1): ?>
21-
<input id="p_method_<?= /* @escapeNotVerified */ $_code ?>" value="<?= /* @escapeNotVerified */ $_code ?>" type="radio" name="payment[method]"
22-
title="<?= $block->escapeHtml($_method->getTitle()) ?>"
23-
onclick="payment.switchMethod('<?= /* @escapeNotVerified */ $_code ?>')"<?php if ($block->getSelectedMethodCode() == $_code): ?> checked="checked"<?php endif; ?>
24-
class="admin__control-radio<?php if ($_counter == $_methodsCount) : ?> validate-one-required-by-name<?php endif; ?>"/>
21+
<?php if ($_methodsCount > 1) : ?>
22+
<input id="p_method_<?= $block->escapeHtml($_code); ?>"
23+
value="<?= $block->escapeHtml($_code); ?>"
24+
type="radio" name="payment[method]"
25+
title="<?= $block->escapeHtml($_method->getTitle()); ?>"
26+
onclick="payment.switchMethod('<?= $block->escapeHtml($_code); ?>')"
27+
<?php if ($block->getSelectedMethodCode() == $_code) : ?>
28+
checked="checked"
29+
<?php endif; ?>
30+
<?php $className = ($_counter == $_methodsCount) ? ' validate-one-required-by-name' : ''; ?>
31+
class="admin__control-radio<?= $block->escapeHtml($className); ?>"/>
2532
<?php else :?>
2633
<span class="no-display">
27-
<input id="p_method_<?= /* @escapeNotVerified */ $_code ?>" value="<?= /* @escapeNotVerified */ $_code ?>" type="radio"
34+
<input id="p_method_<?= $block->escapeHtml($_code); ?>"
35+
value="<?= $block->escapeHtml($_code); ?>"
36+
type="radio"
2837
name="payment[method]" class="admin__control-radio"
2938
checked="checked"/>
3039
</span>
3140
<?php endif;?>
3241

33-
<label class="admin__field-label" for="p_method_<?= /* @escapeNotVerified */ $_code ?>"><?= $block->escapeHtml($_method->getTitle()) ?></label>
42+
<label class="admin__field-label"
43+
for="p_method_<?= $block->escapeHtml($_code); ?>"><?= $block->escapeHtml($_method->getTitle()) ?>
44+
</label>
3445
</dt>
3546
<dd class="admin__payment-method-wrapper">
36-
<?= /* @escapeNotVerified */ $block->getChildHtml('payment.method.' . $_code) ?>
47+
<?= /* @noEscape */ $block->getChildHtml('payment.method.' . $_code) ?>
3748
</dd>
3849
<?php endforeach; ?>
3950
</dl>
4051
</div>
4152
<script>
42-
require(["Magento_Sales/order/create/form"], function(){
43-
<?php if ($_methodsCount != 1):?>
44-
order.setPaymentMethod('<?= /* @escapeNotVerified */ $block->getSelectedMethodCode() ?>');
53+
require([
54+
'mage/apply/main',
55+
'Magento_Sales/order/create/form'
56+
], function(mage) {
57+
mage.apply();
58+
<?php if ($_methodsCount != 1) : ?>
59+
order.setPaymentMethod('<?= $block->escapeHtml($block->getSelectedMethodCode()); ?>');
4560
<?php endif; ?>
4661
});
4762
</script>
48-
<?php else: ?>
49-
<div class="admin__message-empty"><?= /* @escapeNotVerified */ __('No Payment Methods') ?></div>
63+
<?php else : ?>
64+
<div class="admin__message-empty"><?= $block->escapeHtml(__('No Payment Methods')); ?></div>
5065
<?php endif; ?>

app/code/Magento/Usps/Model/Carrier.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ public function getCode($type, $code = '')
643643
'method' => [
644644
'0_FCLE' => __('First-Class Mail Large Envelope'),
645645
'0_FCL' => __('First-Class Mail Letter'),
646-
'0_FCP' => __('First-Class Mail Parcel'),
646+
'0_FCP' => __('First-Class Package Service - Retail'),
647647
'0_FCPC' => __('First-Class Mail Postcards'),
648648
'1' => __('Priority Mail'),
649649
'2' => __('Priority Mail Express Hold For Pickup'),
@@ -795,7 +795,7 @@ public function getCode($type, $code = '')
795795
'method_to_code' => [
796796
'First-Class Mail Large Envelope' => '0_FCLE',
797797
'First-Class Mail Letter' => '0_FCL',
798-
'First-Class Mail Parcel' => '0_FCP',
798+
'First-Class Package Service - Retail' => '0_FCP',
799799
],
800800
'first_class_mail_type' => ['LETTER' => __('Letter'), 'FLAT' => __('Flat'), 'PARCEL' => __('Parcel')],
801801
'container' => [
@@ -1795,10 +1795,10 @@ protected function _formIntlShipmentRequest(\Magento\Framework\DataObject $reque
17951795
}
17961796
$individualItemWeight = $itemWeight / $ceiledQty;
17971797
$itemDetail->addChild('Quantity', $ceiledQty);
1798-
$itemDetail->addChild('Value', $item->getCustomsValue() * $item->getQty());
1798+
$itemDetail->addChild('Value', sprintf('%.2F', $item->getCustomsValue() * $item->getQty()));
17991799
list($individualPoundsWeight, $individualOuncesWeight) = $this->_convertPoundOunces($individualItemWeight);
18001800
$itemDetail->addChild('NetPounds', $individualPoundsWeight);
1801-
$itemDetail->addChild('NetOunces', $individualOuncesWeight);
1801+
$itemDetail->addChild('NetOunces', sprintf('%.2F', $individualOuncesWeight));
18021802
$itemDetail->addChild('HSTariffNumber', 0);
18031803
$itemDetail->addChild('CountryOfOrigin', $countryOfManufacture);
18041804

app/code/Magento/Usps/Setup/InstallData.php renamed to app/code/Magento/Usps/Setup/UpgradeData.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,29 @@
66

77
namespace Magento\Usps\Setup;
88

9-
use Magento\Framework\Setup\InstallDataInterface;
109
use Magento\Framework\Setup\ModuleContextInterface;
1110
use Magento\Framework\Setup\ModuleDataSetupInterface;
11+
use Magento\Framework\Setup\UpgradeDataInterface;
1212

13-
/**
14-
* @codeCoverageIgnore
15-
*/
16-
class InstallData implements InstallDataInterface
13+
class UpgradeData implements UpgradeDataInterface
1714
{
1815
/**
19-
* {@inheritdoc}
16+
* @inheritdoc
17+
*/
18+
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
19+
{
20+
if (version_compare($context->getVersion(), '2.0.1', '<')) {
21+
$this->updateAllowedMethods($setup);
22+
}
23+
}
24+
25+
/**
26+
* Replaces titles of allowed shipping methods to their codes.
27+
*
28+
* @param ModuleDataSetupInterface $setup
29+
* @return void
2030
*/
21-
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
31+
private function updateAllowedMethods(ModuleDataSetupInterface $setup)
2232
{
2333
$installer = $setup;
2434
$configDataTable = $installer->getTable('core_config_data');
@@ -39,6 +49,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
3949
'First-Class Mail Letter' => '0_FCL',
4050
'First-Class Mail Parcel' => '0_FCP',
4151
'First-Class Mail Package' => '0_FCP',
52+
'First-Class Package Service - Retail' => '0_FCP',
4253
'Parcel Post' => '4',
4354
'Retail Ground' => '4',
4455
'Media Mail' => '6',
@@ -68,12 +79,12 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
6879
'Priority Mail International Large Flat Rate Box' => 'INT_11',
6980
];
7081

71-
$select = $connection->select()->from(
72-
$configDataTable
73-
)->where(
74-
'path IN (?)',
75-
['carriers/usps/free_method', 'carriers/usps/allowed_methods']
76-
);
82+
$select = $connection->select()
83+
->from($configDataTable)
84+
->where(
85+
'path IN (?)',
86+
['carriers/usps/free_method', 'carriers/usps/allowed_methods']
87+
);
7788
$oldConfigValues = $connection->fetchAll($select);
7889

7990
foreach ($oldConfigValues as $oldValue) {

app/code/Magento/Usps/Test/Unit/Model/CarrierTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Usps\Test\Unit\Model;
77

8+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
89
use Magento\Framework\HTTP\ZendClient;
910
use Magento\Framework\HTTP\ZendClientFactory;
1011
use Magento\Quote\Model\Quote\Address\RateRequest;
@@ -162,6 +163,22 @@ function ($data) {
162163
]
163164
);
164165

166+
$productCollection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection::class)
167+
->disableOriginalConstructor()
168+
->getMock();
169+
$productCollection->method('addStoreFilter')
170+
->willReturnSelf();
171+
$productCollection->method('addFieldToFilter')
172+
->willReturnSelf();
173+
$productCollection->method('addAttributeToSelect')
174+
->willReturn([]);
175+
176+
$productCollectionFactory = $this->getMockBuilder(CollectionFactory::class)
177+
->disableOriginalConstructor()
178+
->getMock();
179+
$productCollectionFactory->method('create')
180+
->willReturn($productCollection);
181+
165182
$arguments = [
166183
'scopeConfig' => $this->scope,
167184
'xmlSecurity' => new \Magento\Framework\Xml\Security(),
@@ -172,6 +189,7 @@ function ($data) {
172189
'data' => $data,
173190
'rateErrorFactory' => $this->errorFactory,
174191
'carrierHelper' => $carrierHelper,
192+
'productCollectionFactory' => $productCollectionFactory,
175193
];
176194

177195
$this->dataHelper = $this->getMockBuilder(DataHelper::class)
@@ -265,6 +283,31 @@ public function testReturnOfShipment()
265283
$this->assertNotEmpty($this->carrier->returnOfShipment($request)->getInfo()[0]['tracking_number']);
266284
}
267285

286+
public function testFormattingFloatValuesForIntlShipmentRequest()
287+
{
288+
$this->httpResponse->method('getBody')
289+
->willReturn(
290+
file_get_contents(__DIR__ . '/_files/success_usps_response_return_shipment.xml')
291+
);
292+
$request = $this->objectManager->getObject(
293+
\Magento\Shipping\Model\Shipment\ReturnShipment::class,
294+
require __DIR__ . '/_files/return_shipment_request_data.php'
295+
);
296+
297+
$request->setRecipientAddressCountryCode('UK');
298+
$formattedValuesRegex = '(<Value>5.00<\/Value>).*';
299+
$formattedValuesRegex .= '(<NetOunces>0.00<\/NetOunces>)';
300+
301+
$this->httpClient->expects($this->exactly(2))
302+
->method('setParameterGet')
303+
->withConsecutive(
304+
['API', 'ExpressMailIntl'],
305+
['XML', $this->matchesRegularExpression('/' . $formattedValuesRegex . '/')]
306+
);
307+
308+
$this->carrier->returnOfShipment($request);
309+
}
310+
268311
/**
269312
* Emulates the config's `getValue` method.
270313
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
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_Usps" setup_version="2.0.0">
9+
<module name="Magento_Usps" setup_version="2.0.1">
1010
</module>
1111
</config>

app/code/Magento/Usps/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"First-Class Mail Large Envelope","First-Class Mail Large Envelope"
22
"First-Class Mail Letter","First-Class Mail Letter"
3-
"First-Class Mail Parcel","First-Class Mail Parcel"
3+
"First-Class Package Service - Retail","First-Class Package Service - Retail"
44
"First-Class Mail Postcards","First-Class Mail Postcards"
55
"Priority Mail","Priority Mail"
66
"Priority Mail Express Hold For Pickup","Priority Mail Express Hold For Pickup"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Block\Adminhtml\Order\Create\Billing\Method;
7+
8+
use Magento\Framework\ObjectManagerInterface;
9+
use Magento\Framework\View\LayoutInterface;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
12+
/**
13+
* Test for order billing method form.
14+
*
15+
* @magentoAppArea adminhtml
16+
*/
17+
class FormTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* @var ObjectManagerInterface
21+
*/
22+
private $objectManager;
23+
24+
/**
25+
* @var LayoutInterface
26+
*/
27+
private $layout;
28+
29+
/**
30+
* @inheritdoc
31+
*/
32+
protected function setUp()
33+
{
34+
$this->objectManager = Bootstrap::getObjectManager();
35+
$this->layout = $this->objectManager->get(LayoutInterface::class);
36+
}
37+
38+
/**
39+
* Checks if billing method form generates contentUpdated event
40+
* to parse elements with data-mage-init attributes.
41+
*/
42+
public function testContentUpdated()
43+
{
44+
/** @var Form $block */
45+
$block = $this->layout->createBlock(Form::class, 'order_billing_method');
46+
$block->setTemplate('Magento_Sales::order/create/billing/method/form.phtml');
47+
48+
$this->assertContains('mage.apply()', $block->toHtml());
49+
}
50+
}

0 commit comments

Comments
 (0)