resultPageFactory = $resultPageFactory; $this->logger = $logger; $this->orderRepository = $orderRepository; $this->cart = $cart; $this->registry = $registry; $this->orderManager = $orderManager; $this->orderStatusHistory; parent:: __construct($context); } /** * Execute view action * * @return ResultInterface */ public function execute() { $order_id = $this->getRequest()->getParam('order_id'); try { $order = $this->orderRepository->get((int)$order_id); $items = $order->getItemsCollection(); foreach ($items as $item) { try { $options = $item->getProductOptions(); $product = $item->getProduct(); if (isset($options['info_buyRequest'])) { $options['info_buyRequest']['qty'] = $item['qty_ordered']; $this->cart->addProduct($product, $options['info_buyRequest']); } else { $this->cart->addOrderItem($product); } } catch (Exception $e) { $this->logger->critical($e); } } $this->cart->save(); $this->registry->register('isSecureArea', 'true'); //Cancel the abandoned order and add comment $order->cancel(); $order->addCommentToStatusHistory(__('The customer has left the payment page and has returned to the shop. The invoice is expired.')); $order->save(); $this->registry->unregister('isSecureArea'); } catch (\Exception $e) { $this->logger->error($e); } $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setUrl('/checkout/cart/'); return $resultRedirect; } }