Skip to content

Commit b73b312

Browse files
Merge branch 2.2-develop into ENGCOM-3833-magento-magento2-20183
2 parents 73f43d7 + d20f927 commit b73b312

File tree

32 files changed

+979
-170
lines changed

32 files changed

+979
-170
lines changed

app/code/Magento/CatalogSearch/Model/ResourceModel/Engine.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,19 @@ public function processAttributeValue($attribute, $value)
107107
&& in_array($attribute->getFrontendInput(), ['text', 'textarea'])
108108
) {
109109
$result = $value;
110-
} elseif ($this->isTermFilterableAttribute($attribute)) {
110+
} elseif ($this->isTermFilterableAttribute($attribute)
111+
|| ($attribute->getIsSearchable()
112+
&& in_array($attribute->getFrontendInput(), ['select', 'multiselect']))
113+
) {
111114
$result = '';
112115
}
113116

114117
return $result;
115118
}
116119

117120
/**
118-
* Prepare index array as a string glued by separator
121+
* Prepare index array as a string glued by separator.
122+
*
119123
* Support 2 level array gluing
120124
*
121125
* @param array $index

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/components/price-configurable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ define([
5353
if (isConfigurable) {
5454
this.disable();
5555
this.clear();
56+
} else {
57+
this.enable();
5658
}
5759
}
5860
});

app/code/Magento/Newsletter/Model/Subscriber.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ public function updateSubscription($customerId)
552552
}
553553

554554
/**
555-
* Saving customer subscription status
555+
* Saving customer subscription status.
556556
*
557557
* @param int $customerId
558558
* @param bool $subscribe indicates whether the customer should be subscribed or unsubscribed
@@ -588,7 +588,12 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
588588
if (AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED
589589
== $this->customerAccountManagement->getConfirmationStatus($customerId)
590590
) {
591-
$status = self::STATUS_UNCONFIRMED;
591+
if ($this->getId() && $this->getStatus() == self::STATUS_SUBSCRIBED) {
592+
// if a customer was already subscribed then keep the subscribed
593+
$status = self::STATUS_SUBSCRIBED;
594+
} else {
595+
$status = self::STATUS_UNCONFIRMED;
596+
}
592597
} elseif ($isConfirmNeed) {
593598
if ($this->getStatus() != self::STATUS_SUBSCRIBED) {
594599
$status = self::STATUS_NOT_ACTIVE;

app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ public function testSubscribeNotLoggedIn()
209209
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->subscribe($email));
210210
}
211211

212+
/**
213+
* Update status with Confirmation Status - required.
214+
*
215+
* @return void
216+
*/
212217
public function testUpdateSubscription()
213218
{
214219
$websiteId = 1;
@@ -225,7 +230,7 @@ public function testUpdateSubscription()
225230
->willReturn(
226231
[
227232
'subscriber_id' => 1,
228-
'subscriber_status' => Subscriber::STATUS_SUBSCRIBED
233+
'subscriber_status' => Subscriber::STATUS_SUBSCRIBED,
229234
]
230235
);
231236
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
@@ -245,8 +250,9 @@ public function testUpdateSubscription()
245250
->getMock();
246251
$this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
247252
$storeModel->expects($this->exactly(2))->method('getWebsiteId')->willReturn($websiteId);
253+
$data = $this->subscriber->updateSubscription($customerId);
248254

249-
$this->assertEquals($this->subscriber, $this->subscriber->updateSubscription($customerId));
255+
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $data->getSubscriberStatus());
250256
}
251257

252258
public function testUnsubscribeCustomerById()

app/code/Magento/Sales/Block/Order/Item/Renderer/DefaultRenderer.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,21 @@ public function getItemRowTotalAfterDiscountHtml($item = null)
278278
$block->setItem($item);
279279
return $block->toHtml();
280280
}
281+
282+
/**
283+
* Return the base total amount minus discount.
284+
*
285+
* @param OrderItem|InvoiceItem|CreditmemoItem $item
286+
* @return float|null
287+
*/
288+
public function getBaseTotalAmount($item)
289+
{
290+
$baseTotalAmount = $item->getBaseRowTotal()
291+
+ $item->getBaseTaxAmount()
292+
+ $item->getBaseDiscountTaxCompensationAmount()
293+
+ $item->getBaseWeeeTaxAppliedAmount()
294+
- $item->getBaseDiscountAmount();
295+
296+
return $baseTotalAmount;
297+
}
281298
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Model\Order;
9+
10+
use Magento\Sales\Api\Data\OrderInterface;
11+
use Magento\Sales\Api\OrderRepositoryInterface;
12+
use Magento\Customer\Api\Data\CustomerInterface;
13+
use Magento\Framework\Event\ManagerInterface;
14+
15+
class CustomerAssignment
16+
{
17+
/**
18+
* @var ManagerInterface
19+
*/
20+
private $eventManager;
21+
22+
/**
23+
* @var OrderRepositoryInterface
24+
*/
25+
private $orderRepository;
26+
27+
/**
28+
* CustomerAssignment constructor.
29+
*
30+
* @param ManagerInterface $eventManager
31+
* @param OrderRepositoryInterface $orderRepository
32+
*/
33+
public function __construct(
34+
ManagerInterface $eventManager,
35+
OrderRepositoryInterface $orderRepository
36+
) {
37+
$this->eventManager = $eventManager;
38+
$this->orderRepository = $orderRepository;
39+
}
40+
41+
/**
42+
* @param OrderInterface $order
43+
* @param CustomerInterface $customer
44+
*/
45+
public function execute(OrderInterface $order, CustomerInterface $customer)/*: void*/
46+
{
47+
$order->setCustomerId($customer->getId());
48+
$order->setCustomerIsGuest(false);
49+
$this->orderRepository->save($order);
50+
51+
$this->eventManager->dispatch(
52+
'sales_order_customer_assign_after',
53+
[
54+
'order' => $order,
55+
'customer' => $customer
56+
]
57+
);
58+
}
59+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Model\Order\Webapi;
9+
10+
use Magento\Sales\Api\Data\OrderItemInterface;
11+
use Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn;
12+
use Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer;
13+
14+
/**
15+
* Class for changing row total in response.
16+
*/
17+
class ChangeOutputArray
18+
{
19+
/**
20+
* @var DefaultColumn
21+
*/
22+
private $priceRenderer;
23+
24+
/**
25+
* @var DefaultRenderer
26+
*/
27+
private $defaultRenderer;
28+
29+
/**
30+
* @param DefaultColumn $priceRenderer
31+
* @param DefaultRenderer $defaultRenderer
32+
*/
33+
public function __construct(
34+
DefaultColumn $priceRenderer,
35+
DefaultRenderer $defaultRenderer
36+
) {
37+
$this->priceRenderer = $priceRenderer;
38+
$this->defaultRenderer = $defaultRenderer;
39+
}
40+
41+
/**
42+
* Changing row total for webapi order item response.
43+
*
44+
* @param OrderItemInterface $dataObject
45+
* @param array $result
46+
* @return array
47+
*/
48+
public function execute(
49+
OrderItemInterface $dataObject,
50+
array $result
51+
): array {
52+
$result[OrderItemInterface::ROW_TOTAL] = $this->priceRenderer->getTotalAmount($dataObject);
53+
$result[OrderItemInterface::BASE_ROW_TOTAL] = $this->priceRenderer->getBaseTotalAmount($dataObject);
54+
$result[OrderItemInterface::ROW_TOTAL_INCL_TAX] = $this->defaultRenderer->getTotalAmount($dataObject);
55+
$result[OrderItemInterface::BASE_ROW_TOTAL_INCL_TAX] = $this->defaultRenderer->getBaseTotalAmount($dataObject);
56+
57+
return $result;
58+
}
59+
}

app/code/Magento/Sales/Observer/AssignOrderToCustomerObserver.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Event\Observer;
1313
use Magento\Framework\Event\ObserverInterface;
1414
use Magento\Sales\Api\OrderRepositoryInterface;
15+
use Magento\Sales\Model\Order\CustomerAssignment;
1516

1617
/**
1718
* Assign order to customer created after issuing guest order.
@@ -24,11 +25,22 @@ class AssignOrderToCustomerObserver implements ObserverInterface
2425
private $orderRepository;
2526

2627
/**
28+
* @var CustomerAssignment
29+
*/
30+
private $assignmentService;
31+
32+
/**
33+
* AssignOrderToCustomerObserver constructor.
34+
*
2735
* @param OrderRepositoryInterface $orderRepository
36+
* @param CustomerAssignment $assignmentService
2837
*/
29-
public function __construct(OrderRepositoryInterface $orderRepository)
30-
{
38+
public function __construct(
39+
OrderRepositoryInterface $orderRepository,
40+
CustomerAssignment $assignmentService
41+
) {
3142
$this->orderRepository = $orderRepository;
43+
$this->assignmentService = $assignmentService;
3244
}
3345

3446
/**
@@ -44,11 +56,8 @@ public function execute(Observer $observer)
4456
if (array_key_exists('__sales_assign_order_id', $delegateData)) {
4557
$orderId = $delegateData['__sales_assign_order_id'];
4658
$order = $this->orderRepository->get($orderId);
47-
if (!$order->getCustomerId()) {
48-
//if customer ID wasn't already assigned then assigning.
49-
$order->setCustomerId($customer->getId());
50-
$order->setCustomerIsGuest(0);
51-
$this->orderRepository->save($order);
59+
if (!$order->getCustomerId() && $customer->getId()) {
60+
$this->assignmentService->execute($order, $customer);
5261
}
5362
}
5463
}

app/code/Magento/Sales/Test/Unit/Block/Order/Item/Renderer/DefaultRendererTest.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,7 @@ protected function setUp()
6060
->setMethods(['setItem', 'toHtml'])
6161
->getMock();
6262

63-
$itemMockMethods = [
64-
'__wakeup',
65-
'getRowTotal',
66-
'getTaxAmount',
67-
'getDiscountAmount',
68-
'getDiscountTaxCompensationAmount',
69-
'getWeeeTaxAppliedRowAmount',
70-
];
71-
$this->itemMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class)
72-
->disableOriginalConstructor()
73-
->setMethods($itemMockMethods)
74-
->getMock();
63+
$this->itemMock = $this->createMock(\Magento\Sales\Model\Order\Item::class);
7564
}
7665

7766
public function testGetItemPriceHtml()
@@ -161,4 +150,20 @@ public function testGetTotalAmount()
161150

162151
$this->assertEquals($expectedResult, $this->block->getTotalAmount($this->itemMock));
163152
}
153+
154+
/**
155+
* @return void
156+
*/
157+
public function testGetBaseTotalAmount()
158+
{
159+
$expectedBaseTotalAmount = 10;
160+
161+
$this->itemMock->expects($this->once())->method('getBaseRowTotal')->willReturn(8);
162+
$this->itemMock->expects($this->once())->method('getBaseTaxAmount')->willReturn(1);
163+
$this->itemMock->expects($this->once())->method('getBaseDiscountTaxCompensationAmount')->willReturn(1);
164+
$this->itemMock->expects($this->once())->method('getBaseWeeeTaxAppliedAmount')->willReturn(1);
165+
$this->itemMock->expects($this->once())->method('getBaseDiscountAmount')->willReturn(1);
166+
167+
$this->assertEquals($expectedBaseTotalAmount, $this->block->getBaseTotalAmount($this->itemMock));
168+
}
164169
}

0 commit comments

Comments
 (0)