Skip to content

Commit 9326a96

Browse files
author
Magento CICD
authored
merge magento/2.2-develop into magento-performance/MAGETWO-83560
2 parents 0b08b61 + 325b430 commit 9326a96

File tree

8 files changed

+109
-47
lines changed

8 files changed

+109
-47
lines changed

app/code/Magento/Braintree/view/adminhtml/web/js/braintree.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ define([
145145
_initBraintree: function () {
146146
var self = this;
147147

148+
this.disableEventListeners();
149+
148150
self.braintree.setup(self.clientToken, 'custom', {
149151
id: self.selector,
150152
hostedFields: self.getHostedFields(),
@@ -154,6 +156,7 @@ define([
154156
*/
155157
onReady: function () {
156158
$('body').trigger('processStop');
159+
self.enableEventListeners();
157160
},
158161

159162
/**

app/code/Magento/Sales/Model/Order/Shipment/TrackRepository.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Sales\Api\Data\ShipmentTrackSearchResultInterfaceFactory;
1515
use Magento\Sales\Api\ShipmentTrackRepositoryInterface;
1616
use Magento\Sales\Model\Spi\ShipmentTrackResourceInterface;
17+
use Psr\Log\LoggerInterface;
1718

1819
class TrackRepository implements ShipmentTrackRepositoryInterface
1920
{
@@ -37,23 +38,30 @@ class TrackRepository implements ShipmentTrackRepositoryInterface
3738
*/
3839
private $collectionProcessor;
3940

41+
/**
42+
* @var LoggerInterface
43+
*/
44+
private $logger;
45+
4046
/**
4147
* @param ShipmentTrackResourceInterface $trackResource
4248
* @param ShipmentTrackInterfaceFactory $trackFactory
4349
* @param ShipmentTrackSearchResultInterfaceFactory $searchResultFactory
4450
* @param CollectionProcessorInterface $collectionProcessor
51+
* @param LoggerInterface|null $logger
4552
*/
4653
public function __construct(
4754
ShipmentTrackResourceInterface $trackResource,
4855
ShipmentTrackInterfaceFactory $trackFactory,
4956
ShipmentTrackSearchResultInterfaceFactory $searchResultFactory,
50-
CollectionProcessorInterface $collectionProcessor
57+
CollectionProcessorInterface $collectionProcessor,
58+
LoggerInterface $logger = null
5159
) {
52-
5360
$this->trackResource = $trackResource;
5461
$this->trackFactory = $trackFactory;
5562
$this->searchResultFactory = $searchResultFactory;
5663
$this->collectionProcessor = $collectionProcessor;
64+
$this->logger = $logger ?: \Magento\Framework\App\ObjectManager::getInstance()->get(LoggerInterface::class);
5765
}
5866

5967
/**
@@ -64,6 +72,7 @@ public function getList(SearchCriteriaInterface $searchCriteria)
6472
$searchResult = $this->searchResultFactory->create();
6573
$this->collectionProcessor->process($searchCriteria, $searchResult);
6674
$searchResult->setSearchCriteria($searchCriteria);
75+
6776
return $searchResult;
6877
}
6978

@@ -74,6 +83,7 @@ public function get($id)
7483
{
7584
$entity = $this->trackFactory->create();
7685
$this->trackResource->load($entity, $id);
86+
7787
return $entity;
7888
}
7989

@@ -85,8 +95,10 @@ public function delete(ShipmentTrackInterface $entity)
8595
try {
8696
$this->trackResource->delete($entity);
8797
} catch (\Exception $e) {
98+
$this->logger->error($e->getMessage());
8899
throw new CouldNotDeleteException(__('Could not delete the shipment tracking.'), $e);
89100
}
101+
90102
return true;
91103
}
92104

@@ -98,8 +110,10 @@ public function save(ShipmentTrackInterface $entity)
98110
try {
99111
$this->trackResource->save($entity);
100112
} catch (\Exception $e) {
113+
$this->logger->error($e->getMessage());
101114
throw new CouldNotSaveException(__('Could not save the shipment tracking.'), $e);
102115
}
116+
103117
return $entity;
104118
}
105119

@@ -109,6 +123,7 @@ public function save(ShipmentTrackInterface $entity)
109123
public function deleteById($id)
110124
{
111125
$entity = $this->get($id);
126+
112127
return $this->delete($entity);
113128
}
114129
}

app/code/Magento/Sales/Model/ResourceModel/Order/Shipment/Track.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Sales\Model\ResourceModel\Order\Shipment;
77

8+
use Magento\Framework\Exception\LocalizedException;
89
use Magento\Sales\Model\ResourceModel\EntityAbstract as SalesResource;
910
use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot;
1011
use Magento\Sales\Model\Spi\ShipmentTrackResourceInterface;
@@ -74,7 +75,7 @@ protected function _construct()
7475
*
7576
* @param \Magento\Framework\Model\AbstractModel $object
7677
* @return $this
77-
* @throws \Magento\Framework\Exception\LocalizedException
78+
* @throws LocalizedException
7879
*/
7980
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
8081
{
@@ -86,11 +87,16 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
8687
parent::_beforeSave($object);
8788
$errors = $this->validator->validate($object);
8889
if (!empty($errors)) {
89-
throw new \Magento\Framework\Exception\LocalizedException(
90+
throw new LocalizedException(
9091
__("Cannot save track:\n%1", implode("\n", $errors))
9192
);
9293
}
9394

95+
if ($object->getShipment()->getOrder()->getId() != $object->getOrderId()) {
96+
$errorMessage = 'Shipment with requested ID %1 doesn\'t correspond with Order with requested ID %2.';
97+
throw new LocalizedException(__($errorMessage, $object->getParentId(), $object->getOrderId()));
98+
}
99+
94100
return $this;
95101
}
96102
}

app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/TrackTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ protected function setUp()
8989
*/
9090
public function testSave()
9191
{
92+
$shipmentMock = $this->createMock(\Magento\Sales\Model\Order\Shipment::class);
93+
$orderMock = $this->createMock(\Magento\Sales\Model\Order::class);
9294
$this->entitySnapshotMock->expects($this->once())
9395
->method('isModified')
9496
->with($this->trackModelMock)
@@ -98,6 +100,8 @@ public function testSave()
98100
->with($this->equalTo($this->trackModelMock))
99101
->will($this->returnValue([]));
100102
$this->trackModelMock->expects($this->any())->method('getData')->willReturn([]);
103+
$this->trackModelMock->expects($this->atLeastOnce())->method('getShipment')->willReturn($shipmentMock);
104+
$shipmentMock->expects($this->atLeastOnce())->method('getOrder')->willReturn($orderMock);
101105
$this->trackResource->save($this->trackModelMock);
102106
$this->assertTrue(true);
103107
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,4 @@ Created,Created
803803
"PDF Shipments","PDF Shipments"
804804
"PDF Creditmemos","PDF Creditmemos"
805805
Refunds,Refunds
806+
"Shipment with requested ID %1 doesn't correspond with Order with requested ID %2.","Shipment with requested ID %1 doesn't correspond with Order with requested ID %2."

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

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,60 @@
66

77
?>
88
<?php if ($block->hasMethods()) : ?>
9-
<div id="order-billing_method_form">
10-
<dl class="admin__payment-methods">
11-
<?php
12-
$_methods = $block->getMethods();
13-
$_methodsCount = count($_methods);
14-
$_counter = 0;
15-
?>
16-
<?php foreach ($_methods as $_method) :
17-
$_code = $_method->getCode();
18-
$_counter++;
19-
?>
20-
<dt class="admin__field-option">
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"
9+
<div id="order-billing_method_form">
10+
<dl class="admin__payment-methods">
11+
<?php
12+
$_methods = $block->getMethods();
13+
$_methodsCount = count($_methods);
14+
$_counter = 0;
15+
$currentSelectedMethod = $block->getSelectedMethodCode();
16+
?>
17+
<?php foreach ($_methods as $_method) :
18+
$_code = $_method->getCode();
19+
$_counter++;
20+
?>
21+
<dt class="admin__field-option">
22+
<?php if ($_methodsCount > 1) : ?>
23+
<input id="p_method_<?= $block->escapeHtml($_code); ?>"
24+
value="<?= $block->escapeHtml($_code); ?>"
25+
type="radio" name="payment[method]"
26+
title="<?= $block->escapeHtml($_method->getTitle()); ?>"
27+
onclick="payment.switchMethod('<?= $block->escapeHtml($_code); ?>')"
28+
<?php if ($block->getSelectedMethodCode() == $_code) : ?>
29+
checked="checked"
30+
<?php endif; ?>
31+
<?php $className = ($_counter == $_methodsCount) ? ' validate-one-required-by-name' : ''; ?>
32+
class="admin__control-radio<?= $block->escapeHtml($className); ?>"/>
33+
<?php else : ?>
34+
<span class="no-display">
35+
<input id="p_method_<?= $block->escapeHtml($_code); ?>"
36+
value="<?= $block->escapeHtml($_code); ?>"
37+
type="radio"
38+
name="payment[method]" class="admin__control-radio"
39+
checked="checked"/>
40+
</span>
2941
<?php endif; ?>
30-
<?php $className = ($_counter == $_methodsCount) ? ' validate-one-required-by-name' : ''; ?>
31-
class="admin__control-radio<?= $block->escapeHtml($className); ?>"/>
32-
<?php else :?>
33-
<span class="no-display">
34-
<input id="p_method_<?= $block->escapeHtml($_code); ?>"
35-
value="<?= $block->escapeHtml($_code); ?>"
36-
type="radio"
37-
name="payment[method]" class="admin__control-radio"
38-
checked="checked"/>
39-
</span>
40-
<?php endif;?>
4142

42-
<label class="admin__field-label"
43-
for="p_method_<?= $block->escapeHtml($_code); ?>"><?= $block->escapeHtml($_method->getTitle()) ?>
44-
</label>
45-
</dt>
46-
<dd class="admin__payment-method-wrapper">
47-
<?= /* @noEscape */ $block->getChildHtml('payment.method.' . $_code) ?>
48-
</dd>
49-
<?php endforeach; ?>
50-
</dl>
51-
</div>
43+
<label class="admin__field-label" for="p_method_<?= $block->escapeHtml($_code); ?>">
44+
<?= $block->escapeHtml($_method->getTitle()) ?>
45+
</label>
46+
</dt>
47+
<dd class="admin__payment-method-wrapper">
48+
<?= /* @noEscape */ $block->getChildHtml('payment.method.' . $_code) ?>
49+
</dd>
50+
<?php endforeach; ?>
51+
</dl>
52+
</div>
5253
<script>
5354
require([
5455
'mage/apply/main',
5556
'Magento_Sales/order/create/form'
5657
], function(mage) {
5758
mage.apply();
5859
<?php if ($_methodsCount != 1) : ?>
59-
order.setPaymentMethod('<?= $block->escapeHtml($block->getSelectedMethodCode()); ?>');
60+
order.setPaymentMethod('<?= $block->escapeHtml($currentSelectedMethod); ?>');
61+
<?php else : ?>
62+
payment.switchMethod('<?= $block->escapeHtml($currentSelectedMethod); ?>');
6063
<?php endif; ?>
6164
});
6265
</script>

dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipmentAddTrackTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,36 @@ public function testShipmentAddTrack()
7474
self::assertNotEmpty($result[ShipmentTrackInterface::ENTITY_ID]);
7575
self::assertEquals($shipment->getId(), $result[ShipmentTrackInterface::PARENT_ID]);
7676
}
77+
78+
/**
79+
* Try to create track with wrong order ID.
80+
*
81+
* @magentoApiDataFixture Magento/Sales/_files/shipment.php
82+
*
83+
* @expectedException \Exception
84+
* @expectedExceptionMessage Could not save the shipment tracking.
85+
*/
86+
public function testShipmentAddTrackThrowsError()
87+
{
88+
$shipmentCollection = $this->objectManager->get(Collection::class);
89+
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
90+
$shipment = $shipmentCollection->getFirstItem();
91+
92+
$trackData = [
93+
ShipmentTrackInterface::ENTITY_ID => null,
94+
ShipmentTrackInterface::ORDER_ID => $shipment->getOrderId() + 1,
95+
ShipmentTrackInterface::PARENT_ID => $shipment->getId(),
96+
ShipmentTrackInterface::WEIGHT => 20,
97+
ShipmentTrackInterface::QTY => 5,
98+
ShipmentTrackInterface::TRACK_NUMBER => 2,
99+
ShipmentTrackInterface::DESCRIPTION => 'Shipment description',
100+
ShipmentTrackInterface::TITLE => 'Shipment title',
101+
ShipmentTrackInterface::CARRIER_CODE => Track::CUSTOM_CARRIER_CODE,
102+
];
103+
104+
$this->_webApiCall($this->getServiceInfo(), ['entity' => $trackData]);
105+
}
106+
77107
/**
78108
* Returns details about API endpoints and services.
79109
*

lib/internal/Magento/Framework/Data/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public function clear()
492492
*
493493
* Returns array with results of callback for each item
494494
*
495-
* @param string $callback
495+
* @param callable $callback
496496
* @param array $args
497497
* @return array
498498
*/

0 commit comments

Comments
 (0)