Skip to content

Commit 959f2a1

Browse files
committed
Merge branch 'develop' into FearlessKiwis-MAGETWO-59089
2 parents 8ec49df + 2cacd80 commit 959f2a1

File tree

13 files changed

+280
-17
lines changed

13 files changed

+280
-17
lines changed

app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
<item name="source" xsi:type="string">catalog_rule</item>
150150
<item name="dataScope" xsi:type="string">customer_group_ids</item>
151151
</item>
152-
<item name="options" xsi:type="object">\Magento\Customer\Model\Customer\Source\GroupSourceInterface</item>
152+
<item name="options" xsi:type="object">\Magento\CatalogRule\Model\Rule\CustomerGroupsOptionsProvider</item>
153153
</argument>
154154
</field>
155155
<field name="from_date">

app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Customer\Controller\Adminhtml\Index;
77

88
use Magento\Framework\Exception\NoSuchEntityException;
9+
use Magento\Framework\Exception\SecurityViolationException;
910

1011
class ResetPassword extends \Magento\Customer\Controller\Adminhtml\Index
1112
{
@@ -40,6 +41,8 @@ public function execute()
4041
$messages = $exception->getMessage();
4142
}
4243
$this->_addSessionErrorMessages($messages);
44+
} catch (SecurityViolationException $exception) {
45+
$this->messageManager->addErrorMessage($exception->getMessage());
4346
} catch (\Exception $exception) {
4447
$this->messageManager->addException(
4548
$exception,

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected function setUp()
143143
$this->messageManager = $this->getMockBuilder(
144144
\Magento\Framework\Message\Manager::class
145145
)->disableOriginalConstructor()->setMethods(
146-
['addSuccess', 'addMessage', 'addException']
146+
['addSuccess', 'addMessage', 'addException', 'addErrorMessage']
147147
)->getMock();
148148

149149
$this->resultRedirectFactoryMock = $this->getMockBuilder(
@@ -332,6 +332,56 @@ public function testResetPasswordActionCoreException()
332332
$this->_testedObject->execute();
333333
}
334334

335+
public function testResetPasswordActionSecurityException()
336+
{
337+
$securityText = 'Security violation.';
338+
$exception = new \Magento\Framework\Exception\SecurityViolationException(__($securityText));
339+
$customerId = 1;
340+
$email = '[email protected]';
341+
$websiteId = 1;
342+
343+
$this->_request->expects(
344+
$this->once()
345+
)->method(
346+
'getParam'
347+
)->with(
348+
$this->equalTo('customer_id'),
349+
$this->equalTo(0)
350+
)->will(
351+
$this->returnValue($customerId)
352+
);
353+
$customer = $this->getMockForAbstractClass(
354+
\Magento\Customer\Api\Data\CustomerInterface::class,
355+
['getId', 'getEmail', 'getWebsiteId']
356+
);
357+
$customer->expects($this->once())->method('getEmail')->will($this->returnValue($email));
358+
$customer->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
359+
$this->_customerRepositoryMock->expects(
360+
$this->once()
361+
)->method(
362+
'getById'
363+
)->with(
364+
$customerId
365+
)->will(
366+
$this->returnValue($customer)
367+
);
368+
$this->_customerAccountManagementMock->expects(
369+
$this->once()
370+
)->method(
371+
'initiatePasswordReset'
372+
)->willThrowException($exception);
373+
374+
$this->messageManager->expects(
375+
$this->once()
376+
)->method(
377+
'addErrorMessage'
378+
)->with(
379+
$this->equalTo($exception->getMessage())
380+
);
381+
382+
$this->_testedObject->execute();
383+
}
384+
335385
public function testResetPasswordActionCoreExceptionWarn()
336386
{
337387
$warningText = 'Warning';

app/code/Magento/Sales/Model/OrderRepository.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ public function deleteById($id)
146146
*/
147147
public function save(\Magento\Sales\Api\Data\OrderInterface $entity)
148148
{
149+
/** @var \Magento\Sales\Api\Data\OrderExtensionInterface $extensionAttributes */
150+
$extensionAttributes = $entity->getExtensionAttributes();
151+
if ($entity->getIsNotVirtual() && $extensionAttributes && $extensionAttributes->getShippingAssignments()) {
152+
$shippingAssignments = $extensionAttributes->getShippingAssignments();
153+
if (!empty($shippingAssignments)) {
154+
$shipping = array_shift($shippingAssignments)->getShipping();
155+
$entity->setShippingAddress($shipping->getAddress());
156+
$entity->setShippingMethod($shipping->getMethod());
157+
}
158+
}
149159
$this->metadata->getMapper()->save($entity);
150160
$this->registry[$entity->getEntityId()] = $entity;
151161
return $this->registry[$entity->getEntityId()];

app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,40 @@ public function testGetList()
110110

111111
$this->assertEquals($collectionMock, $this->model->getList($searchCriteriaMock));
112112
}
113+
114+
public function testSave()
115+
{
116+
$mapperMock = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order::class)
117+
->disableOriginalConstructor()
118+
->getMock();
119+
$orderEntity = $this->getMock(\Magento\Sales\Model\Order::class, [], [], '', false);
120+
$extensionAttributes = $this->getMock(
121+
\Magento\Sales\Api\Data\OrderExtension::class,
122+
['getShippingAssignments'],
123+
[],
124+
'',
125+
false
126+
);
127+
$shippingAssignment = $this->getMockBuilder(\Magento\Sales\Model\Order\ShippingAssignment::class)
128+
->disableOriginalConstructor()
129+
->setMethods(['getShipping'])
130+
->getMock();
131+
$shippingMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Shipping::class)
132+
->disableOriginalConstructor()
133+
->setMethods(['getAddress', 'getMethod'])
134+
->getMock();
135+
$orderEntity->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributes);
136+
$orderEntity->expects($this->once())->method('getIsNotVirtual')->willReturn(true);
137+
$extensionAttributes
138+
->expects($this->any())
139+
->method('getShippingAssignments')
140+
->willReturn([$shippingAssignment]);
141+
$shippingAssignment->expects($this->once())->method('getShipping')->willReturn($shippingMock);
142+
$shippingMock->expects($this->once())->method('getAddress');
143+
$shippingMock->expects($this->once())->method('getMethod');
144+
$this->metadata->expects($this->once())->method('getMapper')->willReturn($mapperMock);
145+
$mapperMock->expects($this->once())->method('save');
146+
$orderEntity->expects($this->any())->method('getEntityId')->willReturn(1);
147+
$this->model->save($orderEntity);
148+
}
113149
}

app/code/Magento/SalesRule/Observer/SalesOrderAfterPlaceObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function execute(EventObserver $observer)
5757
{
5858
$order = $observer->getEvent()->getOrder();
5959

60-
if (!$order || $order->getDiscountAmount() == 0) {
60+
if (!$order || !$order->getAppliedRuleIds()) {
6161
return $this;
6262
}
6363

app/code/Magento/SalesRule/Test/Unit/Observer/SalesOrderAfterPlaceObserverTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ public function testSalesOrderAfterPlaceWithoutRuleId()
121121
{
122122
$observer = $this->getMock(\Magento\Framework\Event\Observer::class, [], [], '', false);
123123
$order = $this->initOrderFromEvent($observer);
124-
$discountAmount = 10;
124+
$ruleIds = null;
125125
$order->expects($this->once())
126-
->method('getDiscountAmount')
127-
->will($this->returnValue($discountAmount));
126+
->method('getAppliedRuleIds')
127+
->will($this->returnValue($ruleIds));
128128

129129
$this->ruleFactory->expects($this->never())
130130
->method('create');
@@ -158,14 +158,10 @@ public function testSalesOrderAfterPlace($ruleCustomerId)
158158
$ruleId = 1;
159159
$couponId = 1;
160160
$customerId = 1;
161-
$discountAmount = 10;
162161

163-
$order->expects($this->once())
162+
$order->expects($this->exactly(2))
164163
->method('getAppliedRuleIds')
165164
->will($this->returnValue($ruleId));
166-
$order->expects($this->once())
167-
->method('getDiscountAmount')
168-
->will($this->returnValue($discountAmount));
169165
$order->expects($this->once())
170166
->method('getCustomerId')
171167
->will($this->returnValue($customerId));

app/code/Magento/Security/Model/Plugin/AccountManagement.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,26 @@ class AccountManagement
2525
*/
2626
protected $securityManager;
2727

28+
/**
29+
* @var int
30+
*/
31+
protected $passwordRequestEvent;
32+
2833
/**
2934
* AccountManagement constructor.
3035
*
3136
* @param \Magento\Framework\App\RequestInterface $request
3237
* @param SecurityManager $securityManager
38+
* @param int $passwordRequestEvent
3339
*/
3440
public function __construct(
3541
\Magento\Framework\App\RequestInterface $request,
36-
\Magento\Security\Model\SecurityManager $securityManager
42+
\Magento\Security\Model\SecurityManager $securityManager,
43+
$passwordRequestEvent = PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST
3744
) {
3845
$this->request = $request;
3946
$this->securityManager = $securityManager;
47+
$this->passwordRequestEvent = $passwordRequestEvent;
4048
}
4149

4250
/**
@@ -56,7 +64,7 @@ public function beforeInitiatePasswordReset(
5664
$websiteId = null
5765
) {
5866
$this->securityManager->performSecurityCheck(
59-
PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST,
67+
$this->passwordRequestEvent,
6068
$email
6169
);
6270
return [$email, $template, $websiteId];

app/code/Magento/Security/etc/adminhtml/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
<type name="Magento\Backend\Controller\Adminhtml\Auth\Login">
1616
<plugin name="security_login_form" type="Magento\Security\Model\Plugin\LoginController" />
1717
</type>
18+
<type name="Magento\Security\Model\Plugin\AccountManagement">
19+
<arguments>
20+
<argument name="passwordRequestEvent" xsi:type="const">Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST</argument>
21+
</arguments>
22+
</type>
1823
<type name="Magento\Security\Model\SecurityManager">
1924
<arguments>
2025
<argument name="securityCheckers" xsi:type="array">

app/code/Magento/Theme/view/frontend/web/js/view/messages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ define([
3232
customerData.set('messages', {});
3333
}
3434

35-
$.cookieStorage.setConf({path: '/', expires: -1}).set('mage-messages', null);
35+
$.cookieStorage.set('mage-messages', '');
3636
}
3737
});
3838
});

app/code/Magento/Ui/view/base/web/js/grid/provider.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ define([
4343
.initStorage()
4444
.clearData();
4545

46+
// Load data when there will
47+
// be no more pending assets.
48+
resolver(this.reload, this);
49+
4650
return this;
4751
},
4852

@@ -122,9 +126,11 @@ define([
122126
* Handles changes of 'params' object.
123127
*/
124128
onParamsChange: function () {
125-
this.firstLoad ?
126-
resolver(this.reload, this) :
129+
// It's necessary to make a reload only
130+
// after the initial loading has been made.
131+
if (!this.firstLoad) {
127132
this.reload();
133+
}
128134
},
129135

130136
/**

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

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ protected function setUp()
3131
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
3232
}
3333

34+
/**
35+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
36+
*/
3437
protected function prepareOrder()
3538
{
3639
/** @var \Magento\Sales\Model\Order $orderBuilder */
@@ -41,6 +44,8 @@ protected function prepareOrder()
4144
$orderPaymentFactory = $this->objectManager->get(\Magento\Sales\Model\Order\PaymentFactory::class);
4245
/** @var \Magento\Sales\Model\Order\AddressRepository $orderAddressRepository */
4346
$orderAddressRepository = $this->objectManager->get(\Magento\Sales\Model\Order\AddressRepository::class);
47+
/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
48+
$storeManager = $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
4449

4550
$order = $orderFactory->create(
4651
['data' => $this->getDataStructure(\Magento\Sales\Api\Data\OrderInterface::class)]
@@ -68,6 +73,32 @@ protected function prepareOrder()
6873
$order->setCustomerEmail($email);
6974
$order->setBaseGrandTotal(100);
7075
$order->setGrandTotal(100);
76+
$order->setShippingDescription('Flat Rate - Fixed');
77+
$order->setIsVirtual(0);
78+
$order->setStoreId($storeManager->getDefaultStoreView()->getId());
79+
$order->setBaseDiscountAmount(0);
80+
$order->setBaseShippingAmount(5);
81+
$order->setBaseShippingTaxAmount(0);
82+
$order->setBaseSubtotal(100);
83+
$order->setBaseTaxAmount(0);
84+
$order->setBaseToGlobalRate(1);
85+
$order->setBaseToOrderRate(1);
86+
$order->setDiscountAmount(0);
87+
$order->setShippingAmount(0);
88+
$order->setShippingTaxAmount(0);
89+
$order->setStoreToOrderRate(0);
90+
$order->setBaseToOrderRate(0);
91+
$order->setSubtotal(100);
92+
$order->setTaxAmount(0);
93+
$order->setTotalQtyOrdered(1);
94+
$order->setCustomerIsGuest(1);
95+
$order->setCustomerNoteNotify(0);
96+
$order->setCustomerGroupId(0);
97+
$order->setBaseSubtotalInclTax(100);
98+
$order->setWeight(1);
99+
$order->setBaseCurrencyCode('USD');
100+
$order->setShippingInclTax(5);
101+
$order->setBaseShippingInclTax(5);
71102

72103
$this->addProductOption($orderItem);
73104

@@ -82,12 +113,39 @@ protected function prepareOrder()
82113
$orderAddressBilling->setFirstname('First Name');
83114
$orderAddressBilling->setTelephone('+00(000)-123-45-57');
84115
$orderAddressBilling->setStreet(['Street']);
85-
$orderAddressBilling->setCountryId(1);
116+
$orderAddressBilling->setCountryId('US');
117+
$orderAddressBilling->setRegion('California');
86118
$orderAddressBilling->setAddressType('billing');
119+
$orderAddressBilling->setRegionId(12);
120+
121+
$orderAddressShipping = $orderAddressRepository->create();
122+
$orderAddressShipping->setCity('City2');
123+
$orderAddressShipping->setPostcode('12345');
124+
$orderAddressShipping->setLastname('Last Name2');
125+
$orderAddressShipping->setFirstname('First Name2');
126+
$orderAddressShipping->setTelephone('+00(000)-123-45-57');
127+
$orderAddressShipping->setStreet(['Street']);
128+
$orderAddressShipping->setCountryId('US');
129+
$orderAddressShipping->setRegion('California');
130+
$orderAddressShipping->setAddressType('shipping');
131+
$orderAddressShipping->setRegionId(12);
87132

88133
$orderData = $order->getData();
89134
$orderData['billing_address'] = $orderAddressBilling->getData();
90135
$orderData['billing_address']['street'] = ['Street'];
136+
$address = $orderAddressShipping->getData();
137+
$address['street'] = ['Street'];
138+
$orderData['extension_attributes']['shipping_assignments'] =
139+
[
140+
[
141+
'shipping' => [
142+
'address' => $address,
143+
'method' => 'Flat Rate - Fixed'
144+
],
145+
'items' => [$orderItem->getData()],
146+
'stock_id' => null,
147+
]
148+
];
91149
return $orderData;
92150
}
93151

@@ -172,5 +230,8 @@ public function testOrderCreate()
172230
$this->assertTrue((bool)$model->getId());
173231
$this->assertEquals($order['base_grand_total'], $model->getBaseGrandTotal());
174232
$this->assertEquals($order['grand_total'], $model->getGrandTotal());
233+
$this->assertNotNull($model->getShippingAddress());
234+
$this->assertTrue((bool)$model->getShippingAddress()->getId());
235+
$this->assertEquals('Flat Rate - Fixed', $model->getShippingMethod());
175236
}
176237
}

0 commit comments

Comments
 (0)