Skip to content

Commit c03e717

Browse files
author
Olexandr Lysenko
committed
Merge remote-tracking branch 'origin/MAGETWO-58237' into bugfixes
2 parents 2c22ac4 + df6acb5 commit c03e717

File tree

12 files changed

+196
-13
lines changed

12 files changed

+196
-13
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function execute()
102102
$creditmemoManagement = $this->_objectManager->create(
103103
\Magento\Sales\Api\CreditmemoManagementInterface::class
104104
);
105+
$creditmemo->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
105106
$creditmemoManagement->refund($creditmemo, (bool)$data['do_offline']);
106107

107108
if (!empty($data['send_email'])) {

app/code/Magento/Sales/Model/Order/Payment.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\Sales\Model\Order;
1010

11+
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\Pricing\PriceCurrencyInterface;
1213
use Magento\Sales\Api\OrderRepositoryInterface;
1314
use Magento\Sales\Model\Order\Payment\Info;
@@ -105,6 +106,11 @@ class Payment extends Info implements OrderPaymentInterface
105106
*/
106107
protected $orderRepository;
107108

109+
/**
110+
* @var OrderStateResolverInterface
111+
*/
112+
private $orderStateResolver;
113+
108114
/**
109115
* @param \Magento\Framework\Model\Context $context
110116
* @param \Magento\Framework\Registry $registry
@@ -692,7 +698,12 @@ public function refund($creditmemo)
692698
}
693699
$message = $message = $this->prependMessage($message);
694700
$message = $this->_appendTransactionToMessage($transaction, $message);
695-
$this->setOrderStateProcessing($message);
701+
$orderState = $this->getOrderStateResolver()->getStateForOrder($this->getOrder());
702+
$this->getOrder()
703+
->addStatusHistoryComment(
704+
$message,
705+
$this->getOrder()->getConfig()->getStateDefaultStatus($orderState)
706+
)->setIsCustomerNotified($creditmemo->getOrder()->getCustomerNoteNotify());
696707
$this->_eventManager->dispatch(
697708
'sales_order_payment_refund',
698709
['payment' => $this, 'creditmemo' => $creditmemo]
@@ -1388,6 +1399,19 @@ protected function _getInvoiceForTransactionId($transactionId)
13881399
return false;
13891400
}
13901401

1402+
/**
1403+
* @deprecated
1404+
* @return OrderStateResolverInterface
1405+
*/
1406+
private function getOrderStateResolver()
1407+
{
1408+
if ($this->orderStateResolver === null) {
1409+
$this->orderStateResolver = ObjectManager::getInstance()->get(OrderStateResolverInterface::class);
1410+
}
1411+
1412+
return$this->orderStateResolver;
1413+
}
1414+
13911415
//@codeCoverageIgnoreStart
13921416
/**
13931417
* Returns account_status

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ public function execute(
218218
$connection->beginTransaction();
219219
try {
220220
$creditmemo->setState(\Magento\Sales\Model\Order\Creditmemo::STATE_REFUNDED);
221+
$order->setCustomerNoteNotify($notify);
221222
$order = $this->paymentAdapter->refund($creditmemo, $order, $isOnline);
222223
$order->setState(
223224
$this->orderStateResolver->getStateForOrder($order, [])

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ public function execute(
186186
$connection->beginTransaction();
187187
try {
188188
$creditmemo->setState(\Magento\Sales\Model\Order\Creditmemo::STATE_REFUNDED);
189+
$order->setCustomerNoteNotify($notify);
189190
$order = $this->paymentAdapter->refund($creditmemo, $order);
190191
$order->setState(
191192
$this->orderStateResolver->getStateForOrder($order, [])

app/code/Magento/Sales/Model/Service/CreditmemoService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function refund(
182182
$connection->commit();
183183
} catch (\Exception $e) {
184184
$connection->rollBack();
185-
throw new \Magento\Framework\Exception\LocalizedException($e->getMessage());
185+
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()));
186186
}
187187

188188
return $creditmemo;

app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@ class PaymentTest extends \PHPUnit_Framework_TestCase
1919
{
2020
const TRANSACTION_ID = 'ewr34fM49V0';
2121

22+
/**
23+
* @var \PHPUnit_Framework_MockObject_MockObject
24+
*/
2225
private $mockContext;
2326

27+
/**
28+
* @var \PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $orderStateResolverMock;
31+
2432
/**
2533
* @var Payment
2634
*/
@@ -59,6 +67,9 @@ class PaymentTest extends \PHPUnit_Framework_TestCase
5967
/** @var \Magento\Sales\Model\Order\Invoice | \PHPUnit_Framework_MockObject_MockObject $orderMock */
6068
private $invoiceMock;
6169

70+
/**
71+
* @var string
72+
*/
6273
private $transactionId;
6374

6475
/**
@@ -271,14 +282,19 @@ function ($value) {
271282
'getGrandTotal',
272283
'getBaseGrandTotal',
273284
'getDoTransaction',
274-
'getInvoice'
285+
'getInvoice',
286+
'getOrder'
275287
],
276288
[],
277289
'',
278290
false
279291
);
280-
292+
$this->orderStateResolverMock = $this->getMockBuilder(Order\OrderStateResolverInterface::class)
293+
->disableOriginalConstructor()
294+
->getMockForAbstractClass();
281295
$this->payment = $this->initPayment();
296+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
297+
$helper->setBackwardCompatibleProperty($this->payment, 'orderStateResolver', $this->orderStateResolverMock);
282298
$this->payment->setMethod('any');
283299
$this->payment->setOrder($this->orderMock);
284300
$this->transactionId = self::TRANSACTION_ID;
@@ -1465,6 +1481,9 @@ public function testRefund()
14651481
$this->creditMemoMock->expects(static::once())
14661482
->method('getInvoice')
14671483
->willReturn($this->invoiceMock);
1484+
$this->creditMemoMock->expects(static::once())
1485+
->method('getOrder')
1486+
->willReturn($this->orderMock);
14681487

14691488
$captureTranId = self::TRANSACTION_ID . '-' . Transaction::TYPE_CAPTURE;
14701489
$captureTransaction = $this->getMockBuilder(Transaction::class)
@@ -1499,7 +1518,10 @@ public function testRefund()
14991518

15001519
$status = 'status';
15011520
$message = 'We refunded ' . $amount . ' online. Transaction ID: "' . $refundTranId . '"';
1502-
$this->mockGetDefaultStatus(Order::STATE_PROCESSING, $status);
1521+
$this->orderStateResolverMock->expects($this->once())->method('getStateForOrder')
1522+
->with($this->orderMock)
1523+
->willReturn(Order::STATE_CLOSED);
1524+
$this->mockGetDefaultStatus(Order::STATE_CLOSED, $status);
15031525
$this->assertOrderUpdated(Order::STATE_PROCESSING, $status, $message);
15041526

15051527
static::assertSame($this->payment, $this->payment->refund($this->creditMemoMock));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ public function testOrderCreditmemo($invoiceId, $items, $notify, $appendComment)
287287
->method('validate')
288288
->with($this->creditmemoItemCreationMock)
289289
->willReturn([]);
290+
$this->orderMock->expects($this->once())->method('setCustomerNoteNotify')->with($notify);
290291
$this->paymentAdapterMock->expects($this->once())
291292
->method('refund')
292293
->with($this->creditmemoMock, $this->orderMock)

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public function testOrderCreditmemo($orderId, $notify, $appendComment)
238238
[CreationQuantityValidator::class],
239239
$this->orderMock
240240
)->willReturn([]);
241+
$this->orderMock->expects($this->once())->method('setCustomerNoteNotify')->with($notify);
241242
$this->paymentAdapterMock->expects($this->once())
242243
->method('refund')
243244
->with($this->creditmemoMock, $this->orderMock)
@@ -246,41 +247,33 @@ public function testOrderCreditmemo($orderId, $notify, $appendComment)
246247
->method('getStateForOrder')
247248
->with($this->orderMock, [])
248249
->willReturn(Order::STATE_CLOSED);
249-
250250
$this->orderMock->expects($this->once())
251251
->method('setState')
252252
->with(Order::STATE_CLOSED)
253253
->willReturnSelf();
254-
255254
$this->orderMock->expects($this->once())
256255
->method('getState')
257256
->willReturn(Order::STATE_CLOSED);
258-
259257
$this->configMock->expects($this->once())
260258
->method('getStateDefaultStatus')
261259
->with(Order::STATE_CLOSED)
262260
->willReturn('Closed');
263-
264261
$this->orderMock->expects($this->once())
265262
->method('setStatus')
266263
->with('Closed')
267264
->willReturnSelf();
268-
269265
$this->creditmemoMock->expects($this->once())
270266
->method('setState')
271267
->with(\Magento\Sales\Model\Order\Creditmemo::STATE_REFUNDED)
272268
->willReturnSelf();
273-
274269
$this->creditmemoRepositoryMock->expects($this->once())
275270
->method('save')
276271
->with($this->creditmemoMock)
277272
->willReturn($this->creditmemoMock);
278-
279273
$this->orderRepositoryMock->expects($this->once())
280274
->method('save')
281275
->with($this->orderMock)
282276
->willReturn($this->orderMock);
283-
284277
if ($notify) {
285278
$this->notifierMock->expects($this->once())
286279
->method('notify')

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/History.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ class History extends Block
2121
*/
2222
protected $commentHistory = '.note-list-comment';
2323

24+
/**
25+
* Comment history status.
26+
*
27+
* @var string
28+
*/
29+
protected $commentHistoryStatus = '.note-list-status';
30+
31+
/**
32+
* Comment history notified status.
33+
*
34+
* @var string
35+
*/
36+
protected $commentHistoryNotifiedStatus = '.note-list-customer';
37+
2438
/**
2539
* Authorized Amount.
2640
*
@@ -103,6 +117,28 @@ public function getRefundedAmount()
103117
return $result;
104118
}
105119

120+
/**
121+
* Gets the status which presented in comment
122+
*
123+
* @return string
124+
*/
125+
public function getStatus()
126+
{
127+
$this->waitCommentsHistory();
128+
return $this->_rootElement->find($this->commentHistoryStatus, Locator::SELECTOR_CSS)->getText();
129+
}
130+
131+
/**
132+
* Gets the is customer notified status which presented in comment
133+
*
134+
* @return string
135+
*/
136+
public function getNotifiedStatus()
137+
{
138+
$this->waitCommentsHistory();
139+
return $this->_rootElement->find($this->commentHistoryNotifiedStatus, Locator::SELECTOR_CSS)->getText();
140+
}
141+
106142
/**
107143
* Wait for comments history is visible.
108144
*
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Test\Constraint;
7+
8+
use Magento\Sales\Test\Page\Adminhtml\SalesOrderView;
9+
use Magento\Sales\Test\Page\Adminhtml\OrderIndex;
10+
use Magento\Mtf\Constraint\AbstractConstraint;
11+
use Magento\Sales\Test\Fixture\OrderInjectable;
12+
13+
/**
14+
* Class AssertOrderCommentsHistoryNotifyStatus
15+
*/
16+
class AssertOrderCommentsHistoryNotifyStatus extends AbstractConstraint
17+
{
18+
/**
19+
* Assert that comment about refunded amount exist in Comments History section on order page in Admin.
20+
*
21+
* @param SalesOrderView $salesOrderView
22+
* @param OrderIndex $salesOrder
23+
* @param OrderInjectable $order
24+
* @param array $data
25+
*/
26+
public function processAssert(
27+
SalesOrderView $salesOrderView,
28+
OrderIndex $salesOrder,
29+
OrderInjectable $order,
30+
array $data
31+
) {
32+
$salesOrder->open();
33+
$salesOrder->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]);
34+
$sendMail = isset($data['form_data']['send_email']) ? filter_var(
35+
$data['form_data']['send_email'],
36+
FILTER_VALIDATE_BOOLEAN
37+
) : false;
38+
\PHPUnit_Framework_Assert::assertContains(
39+
$salesOrderView->getOrderHistoryBlock()->getNotifiedStatus(),
40+
(bool)$sendMail ? 'Customer Notified' : 'Customer Not Notified'
41+
);
42+
}
43+
44+
/**
45+
* Returns string representation of successful assertion.
46+
*
47+
* @return string
48+
*/
49+
public function toString()
50+
{
51+
return "Message with appropriate notification status is available in Comments History section.";
52+
}
53+
}

0 commit comments

Comments
 (0)