This repository was archived by the owner on Apr 29, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -15,13 +15,20 @@ class SalesOrderBeforeSaveObserver implements ObserverInterface
15
15
*
16
16
* @param \Magento\Framework\Event\Observer $observer
17
17
* @return $this
18
+ * @throws \Magento\Framework\Exception\LocalizedException in case order has no payment specified.
18
19
*/
19
20
public function execute (\Magento \Framework \Event \Observer $ observer )
20
21
{
21
22
/** @var \Magento\Sales\Model\Order $order */
22
23
$ order = $ observer ->getEvent ()->getOrder ();
23
24
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 ' ) {
25
32
return $ this ;
26
33
}
27
34
Original file line number Diff line number Diff line change @@ -158,6 +158,9 @@ public function testSalesOrderBeforeSaveSetForced()
158
158
159
159
/**
160
160
* 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.
161
164
*/
162
165
public function testDoesNothingWhenNoPaymentIsAvailable ()
163
166
{
You can’t perform that action at this time.
0 commit comments