14 use Magento\Framework\Controller\Result\RawFactory;
44 private $invoiceService;
79 $orderId = $this->
getRequest()->getParam(
'order_id');
80 $invoiceData = $this->
getRequest()->getParam(
'invoice', []);
81 $invoiceItems = isset($invoiceData[
'items']) ? $invoiceData[
'items'] : [];
83 $order = $this->_objectManager->create(\
Magento\Sales\Model\Order::class)->load($orderId);
85 throw new \Magento\Framework\Exception\LocalizedException(
__(
'The order no longer exists.'));
88 if (!
$order->canInvoice()) {
89 throw new \Magento\Framework\Exception\LocalizedException(
90 __(
'The order does not allow an invoice to be created.')
94 $invoice = $this->invoiceService->prepareInvoice(
$order, $invoiceItems);
97 throw new \Magento\Framework\Exception\LocalizedException(
98 __(
"The invoice can't be created without products. Add products and try again.")
101 $this->registry->register(
'current_invoice',
$invoice);
103 $invoiceRawCommentText = $invoiceData[
'comment_text'];
104 $invoice->setCommentText($invoiceRawCommentText);
107 $resultPage = $this->resultPageFactory->create();
108 $resultPage->getConfig()->getTitle()->prepend(
__(
'Invoices'));
109 $response = $resultPage->getLayout()->getBlock(
'order_items')->toHtml();
110 }
catch (LocalizedException $e) {
111 $response = [
'error' =>
true,
'message' => $e->getMessage()];
112 }
catch (\Exception $e) {
113 $response = [
'error' =>
true,
'message' =>
__(
'Cannot update item quantity.')];
117 $resultJson = $this->resultJsonFactory->create();
122 $resultRaw = $this->resultRawFactory->create();
__construct(Context $context, Registry $registry, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, PageFactory $resultPageFactory, JsonFactory $resultJsonFactory, RawFactory $resultRawFactory, InvoiceService $invoiceService)