/** * @param \Magento\Sales\Model\Order $order * @return $this|bool */ protected function _initInvoice($order) { $invoiceId = $this->getInvoiceId(); if ($invoiceId) { $invoice = $this->invoiceRepository->get($invoiceId); $invoice->setOrder($order); if ($invoice->getId()) { return $invoice; } } return false; }
/** * Process invoice or credit memo * * @param Queue $queue * @return \Magento\Sales\Api\Data\InvoiceInterface|\Magento\Sales\Api\Data\CreditmemoInterface * @throws \Exception */ protected function getProcessingEntity(Queue $queue) { // Check to see which type of entity we are processing if ($queue->getEntityTypeCode() === Queue::ENTITY_TYPE_CODE_INVOICE) { try { /* @var $invoice \Magento\Sales\Api\Data\InvoiceInterface */ $invoice = $this->invoiceRepository->get($queue->getEntityId()); if ($invoice->getEntityId()) { return $invoice; } else { $message = __('Invoice not found: (EntityId: %1, IncrementId: %2)', $queue->getEntityId(), $queue->getIncrementId()); // Update the queue record $this->failQueueProcessing($queue, $message); throw new \Exception($message); } } catch (NoSuchEntityException $e) { /* @var $message \Magento\Framework\Phrase */ $message = __('Queue ID: %1 - Invoice not found: (EntityId: %2, IncrementId: %3)', $queue->getId(), $queue->getEntityId(), $queue->getIncrementId()); // Update the queue record $this->failQueueProcessing($queue, $message); throw new NoSuchEntityException($message, $e); } catch (\Exception $e) { $message = __('Unexpected Exception getProcessingEntity() invoiceRepository->get(): ') . "\n" . $e->getMessage() . "\n" . $queue->getMessage(); // Update the queue record $this->failQueueProcessing($queue, $message); throw new \Exception($message); } } elseif ($queue->getEntityTypeCode() === Queue::ENTITY_TYPE_CODE_CREDITMEMO) { try { /* @var $creditmemo \Magento\Sales\Api\Data\CreditmemoInterface */ $creditmemo = $this->creditmemoRepository->get($queue->getEntityId()); if ($creditmemo->getEntityId()) { return $creditmemo; } else { $message = __('Credit Memo not found: (EntityId: %1, IncrementId: %2)', $queue->getEntityId(), $queue->getIncrementId()); // Update the queue record $this->failQueueProcessing($queue, $message); throw new \Exception($message); } } catch (\Exception $e) { $message = __('ERROR getProcessingEntity() creditmemoRepository->get(): ') . "\n" . $e->getMessage() . "\n" . $queue->getMessage(); // Update the queue record $this->failQueueProcessing($queue, $message); throw $e; } } else { $message = __('Unknown Entity Type Code for processing (%1)', $queue->getEntityTypeCode()); // Update the queue record $this->failQueueProcessing($queue, $message); throw new \Exception(); } }
/** * @inheritdoc */ public function setVoid($id) { return (bool) $this->repository->get($id)->void(); }
/** * Load invoice by id * * @param int|null $invoiceId * @return \Magento\Sales\Api\Data\InvoiceInterface|null */ protected function getInvoice($invoiceId) { if ($invoiceId === null) { return null; } try { return $this->invoiceRepository->get($invoiceId); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { return null; } }