Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 3eb6c3e

Browse files
nmalevanecgelanivishal
authored andcommitted
ENGCOM-2629: Added checks to see if the payment is available #15683
1 parent 14b3eaf commit 3eb6c3e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

app/code/Magento/Payment/Observer/SalesOrderBeforeSaveObserver.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ class SalesOrderBeforeSaveObserver implements ObserverInterface
1515
*
1616
* @param \Magento\Framework\Event\Observer $observer
1717
* @return $this
18+
* @throws \Magento\Framework\Exception\LocalizedException in case order has no payment specified.
1819
*/
1920
public function execute(\Magento\Framework\Event\Observer $observer)
2021
{
2122
/** @var \Magento\Sales\Model\Order $order */
2223
$order = $observer->getEvent()->getOrder();
2324

24-
if ($order->getPayment() && $order->getPayment()->getMethodInstance()->getCode() != 'free') {
25+
if (!$order->getPayment()) {
26+
throw new \Magento\Framework\Exception\LocalizedException(
27+
__('Please provide payment for the order.')
28+
);
29+
}
30+
31+
if ($order->getPayment()->getMethodInstance()->getCode() != 'free') {
2532
return $this;
2633
}
2734

app/code/Magento/Payment/Test/Unit/Observer/SalesOrderBeforeSaveObserverTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ public function testSalesOrderBeforeSaveSetForced()
158158

159159
/**
160160
* The method should check that the payment is available, as this is not always the case.
161+
*
162+
* @expectedException \Magento\Framework\Exception\LocalizedException
163+
* @exceptedExceptionMessage Please provide payment for the order.
161164
*/
162165
public function testDoesNothingWhenNoPaymentIsAvailable()
163166
{

0 commit comments

Comments
 (0)