/** * Cancel order, return quote to customer * * @param string $errorMsg * @return false|string */ protected function _cancelPayment($errorMsg = '') { $gotoSection = false; $this->_checkoutHelper->cancelCurrentOrder($errorMsg); if ($this->_checkoutSession->restoreQuote()) { //Redirect to payment step $gotoSection = 'paymentMethod'; } return $gotoSection; }
public function testCancelCurrentOrderWhichIsCancelled() { $id = 1; $state = Order::STATE_CANCELED; $comment = 'Bla Bla'; $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); $this->session->expects(static::once())->method('getLastRealOrder')->willReturn($order); $order->expects(static::once())->method('getId')->willReturn($id); $order->expects(static::once())->method('getState')->willReturn($state); $order->expects(static::never())->method('registerCancellation')->with($comment)->willReturnSelf(); $order->expects(static::never())->method('save'); static::assertFalse($this->checkout->cancelCurrentOrder($comment)); }
/** * @param bool $hasOrderId * @param bool $isOrderCancelled * @param bool $expectedResult * @dataProvider cancelCurrentOrderDataProvider */ public function testCancelCurrentOrder($hasOrderId, $isOrderCancelled, $expectedResult) { $comment = 'Some test comment'; $order = $this->_getOrderMock($hasOrderId, ['registerCancellation', 'save']); $order->setData('state', $isOrderCancelled ? \Magento\Sales\Model\Order::STATE_CANCELED : 'some another state'); if ($expectedResult) { $order->expects($this->once())->method('registerCancellation')->with($this->equalTo($comment))->will($this->returnSelf()); $order->expects($this->once())->method('save'); } else { $order->expects($this->never())->method('registerCancellation'); $order->expects($this->never())->method('save'); } $this->_session->expects($this->any())->method('getLastRealOrder')->will($this->returnValue($order)); $this->assertEquals($expectedResult, $this->_checkout->cancelCurrentOrder($comment)); }
/** * Customer canceled payment on gateway side. * * @return void */ public function execute() { $this->checkoutHelper->cancelCurrentOrder(''); $this->checkoutHelper->restoreQuote(); $this->_redirect('checkout', ['_fragment' => 'payment']); }