I've had several credit card orders come in and they always create an invoice automagically like they are supposed to. However 1 credit card order did not create an invoice. I'm unable to figure out how to force the system to create an invoice for this product. It doesn't give you the "Invoice" button because it's a credit card order.
Does anyone know how to do this? Programmatically possibly? I'm using Magento 2.3.1.
Thank you.
Hello @legacy_polo
Let me help you to create invoice from admin first :
Note : The Invoice option does not appear if the payment method is set to Authorize and Capture.
Now create invoice from code level :
<?xml version="1.0"?> <event name="sales_order_invoice_pay"> <observer name="webpos_sales_order_invoice_pay" instance="Vendor\Module\Observer\SalesOrderInvoicePay" /> </event> </config>
<?php namespace Vendor\Module\Observer\Sales; use Magento\Framework\Event\Observer as EventObserver; use Magento\Framework\Event\ObserverInterface; class SalesOrderInvoicePay implements ObserverInterface { /** * @param EventObserver $observer * @return $this */ public function execute(EventObserver $observer) { $invoice = $observer->getEvent()->getInvoice(); $order = $invoice->getOrder(); /* reset total_paid & base_total_paid of order */ $order->setTotalPaid($order->getTotalPaid() - $invoice->getGrandTotal()); $order->setBaseTotalPaid($order->getBaseTotalPaid() - $invoice->getBaseGrandTotal()); } }
// Code... $this->eventManager->dispatch('sales_order_invoice_pay'); // More code that sets $data... $this->eventManager->dispatch('sales_order_invoice_pay', ['Data' => $data]);
That is my problem:
The Invoice option does not appear if the payment method is set to Authorize and Capture.
The Invoice is from an "Authorize and Capture", so from the admin gui I can't create it. How do I tell the code you gave me that I want to generate an invoice for order_id 86 for example?
In the above code it is fetching order from event, you can get order by fetching with id from repository.
check the answer here for help :
but event observer works when you add it with some functionality,
you can do this with console command as well where you can pass ID in console command which will not be dependent on other functionality