diff --git a/Controller/Gateway/Paymentwall.php b/Controller/Gateway/Paymentwall.php index 7ab36b4..a1aa8bf 100644 --- a/Controller/Gateway/Paymentwall.php +++ b/Controller/Gateway/Paymentwall.php @@ -1,22 +1,26 @@ getOnepage()->getCheckout(); - if (!$this->_objectManager->get('Magento\Checkout\Model\Session\SuccessValidator')->isValid()) { + if (!$this->_objectManager->get(SuccessValidator::class)->isValid()) { return $this->resultRedirectFactory->create()->setPath('checkout/cart'); } - $session->clearQuote(); - $resultPage = $this->resultPageFactory->create(); - $this->_eventManager->dispatch( - 'checkout_onepage_controller_success_action', - ['order_ids' => [$session->getLastOrderId()]] - ); - return $resultPage; + if ($this->getRequest()->isAjax()) { + $order = $session->getLastRealOrder(); + $customer = $this->_customerSession->getCustomer(); + $widget = $this->model->generateWidget($order, $customer); + + return $this->resultJsonFactory->create()->setData(['url' => $widget->getUrl()]); + } + + return $this->resultPageFactory->create(); } } diff --git a/Controller/Onepage/Success.php b/Controller/Onepage/Success.php index cca326a..7c8c372 100644 --- a/Controller/Onepage/Success.php +++ b/Controller/Onepage/Success.php @@ -5,7 +5,18 @@ class Success extends \Magento\Checkout\Controller\Onepage { public function execute() { - $resultPage = $this->resultPageFactory->create(); - return $resultPage; + $session = $this->getOnepage()->getCheckout(); + $session->clearQuote(); + + $result = $this->resultRawFactory->create(); + $url = $this->urlBuilder->getUrl('checkout/onepage/success'); + $result->setContents(''); + + $this->_eventManager->dispatch( + 'checkout_onepage_controller_success_action', + ['order_ids' => [$session->getLastOrderId()]] + ); + + return $result; } } diff --git a/view/frontend/web/js/action/redirect-to-widget.js b/view/frontend/web/js/action/redirect-to-widget.js index 09e87b7..d1a279a 100644 --- a/view/frontend/web/js/action/redirect-to-widget.js +++ b/view/frontend/web/js/action/redirect-to-widget.js @@ -12,7 +12,19 @@ define( * Provide redirect to page */ execute: function () { - window.location.replace(url.build(this.redirectUrl)); + fullScreenLoader.startLoader(); + + storage.get(this.redirectUrl) + .success(function (response) { + var url = response.url; + + $('.page-wrapper').append('
'); + $('body').addClass('_has-modal'); + }) + .fail(function () { + window.location.replace(url.build(this.redirectUrl)); + }); + } }; }