orderLoader = $orderLoader; $this->_coreRegistry = $registry; parent::__construct($context); $this->reorder = $reorder ?: ObjectManager::getInstance()->get(\Magento\Sales\Model\Reorder\Reorder::class); $this->checkoutSession = $checkoutSession ?: ObjectManager::getInstance()->get(CheckoutSession::class); } /** * Action for reorder * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $result = $this->orderLoader->load($this->_request); if ($result instanceof \Magento\Framework\Controller\ResultInterface) { return $result; } $order = $this->_coreRegistry->registry('current_order'); /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); try { $reorderOutput = $this->reorder->execute($order->getIncrementId(), $order->getStoreId()); } catch (LocalizedException $localizedException) { $this->messageManager->addErrorMessage($localizedException->getMessage()); return $resultRedirect->setPath('checkout/cart'); } // Set quote id for guest session: \Magento\Quote\Api\CartRepositoryInterface::save doesn't set quote id // to session for guest customer, as it does \Magento\Checkout\Model\Cart::save which is deprecated. $this->checkoutSession->setQuoteId($reorderOutput->getCart()->getId()); return $resultRedirect->setPath('checkout/cart'); } }