16 private $eventManager;
24 $this->eventManager = $context->getEventDispatcher();
39 $this->calculateOrderItemsTotals(
51 }
elseif (!
$order->getPayment()->getMethodInstance()->isGateway() || !$capture) {
52 if (!
$order->getPayment()->getIsTransactionPending()) {
65 $this->eventManager->dispatch(
66 'sales_order_invoice_register',
80 private function calculateOrderItemsTotals(
$items)
83 if (
$item->isDeleted()) {
87 if (
$item->getQty() > 0) {
90 $item->isDeleted(
true);
103 private function canCapture(
107 return $invoice->getState() != \Magento\Sales\Model\Order\Invoice::STATE_CANCELED &&
108 $invoice->getState() != \Magento\Sales\Model\Order\Invoice::STATE_PAID &&
109 $order->getPayment()->canCapture();
120 private function calculateOrderTotals(
127 $order->setBaseTotalInvoiced(
131 $order->setSubtotalInvoiced(
134 $order->setBaseSubtotalInvoiced(
141 $order->setBaseTaxInvoiced(
145 $order->setDiscountTaxCompensationInvoiced(
146 $order->getDiscountTaxCompensationInvoiced() +
$invoice->getDiscountTaxCompensationAmount()
148 $order->setBaseDiscountTaxCompensationInvoiced(
149 $order->getBaseDiscountTaxCompensationInvoiced() +
$invoice->getBaseDiscountTaxCompensationAmount()
152 $order->setShippingTaxInvoiced(
153 $order->getShippingTaxInvoiced() +
$invoice->getShippingTaxAmount()
155 $order->setBaseShippingTaxInvoiced(
156 $order->getBaseShippingTaxInvoiced() +
$invoice->getBaseShippingTaxAmount()
159 $order->setShippingInvoiced(
162 $order->setBaseShippingInvoiced(
163 $order->getBaseShippingInvoiced() +
$invoice->getBaseShippingAmount()
166 $order->setDiscountInvoiced(
169 $order->setBaseDiscountInvoiced(
170 $order->getBaseDiscountInvoiced() +
$invoice->getBaseDiscountAmount()
173 $order->setBaseTotalInvoicedCost(
elseif(isset( $params[ 'redirect_parent']))
execute(\Magento\Sales\Api\Data\OrderInterface $order, \Magento\Sales\Api\Data\InvoiceInterface $invoice, $capture)
__construct(\Magento\Framework\Model\Context $context)