Skip to content

Commit

Permalink
ENGCOM-2629: Added checks to see if the payment is available #15683
Browse files Browse the repository at this point in the history
  • Loading branch information
nmalevanec authored and gelanivishal committed Oct 11, 2018
1 parent 14b3eaf commit 3eb6c3e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ class SalesOrderBeforeSaveObserver implements ObserverInterface
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException in case order has no payment specified.
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var \Magento\Sales\Model\Order $order */
$order = $observer->getEvent()->getOrder();

if ($order->getPayment() && $order->getPayment()->getMethodInstance()->getCode() != 'free') {
if (!$order->getPayment()) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Please provide payment for the order.')
);
}

if ($order->getPayment()->getMethodInstance()->getCode() != 'free') {
return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public function testSalesOrderBeforeSaveSetForced()

/**
* The method should check that the payment is available, as this is not always the case.
*
* @expectedException \Magento\Framework\Exception\LocalizedException
* @exceptedExceptionMessage Please provide payment for the order.
*/
public function testDoesNothingWhenNoPaymentIsAvailable()
{
Expand Down

0 comments on commit 3eb6c3e

Please sign in to comment.