cancel
Showing results for 
Search instead for 
Did you mean: 

Orders no longer generate auto invoices.

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Orders no longer generate auto invoices.

Hi,

 

I have been using Magento for my online store for more than 4 years without any problems. My current version is 1.9.2.2 and in the past, my orders would automatically generate an invoice after payment.

 

I have now discovered that that is no longer the case. I can confirm that nothing has been edited and no settings have been changed but I now have to covert each order to an invoice. How do I get that functionality back?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Orders no longer generate auto invoices.

Hello @izette_groenewald1 ,

 

We don't know about your implemented functionality, For generate invoice, Please create a small module for it. I hope that you have experienced to create a module in Magento 1

 

Step1: Insert below event to your config.xml

<events>
        <sales_order_place_after>
            <observers>
                <yourmodule_autoinvoice>
                    <class>yourmodule_autoinvoice/observer</class>
                    <method>autoInvoice</method>
                </yourmodule_autoinvoice>
            </observers>
        </sales_order_place_after>
</events>

then in observer event function use the logic to generate invoice and update order status.

class Yourmodule_Autoinvoice_Model_Observer
    {
        public function autoInvoice($observer) 
        {
                // loading placed order using observer.

                $order = $observer->getEvent()->getOrder();
                $orders = Mage::getModel('sales/order_invoice')->getCollection()->addAttributeToFilter('order_id', array('eq'=>$order->getId()));
                $orders->getSelect()->limit(1);

                if ((int)$orders->count() !== 0) {
                    return $this;
                }

                try {
                        // checking the order can invoice or not.

                        if(!$order->canInvoice()) {
                            $order->addStatusHistoryComment('AutoInvoice: Order cannot be invoiced.', false);
                            $order->save();
                        } else {

                            $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();

                            // below capture method depends on your payment method.
                            // here I used CAPTURE_OFFLINE method.

                            $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
                            $invoice->register();

                            $transactionSave = Mage::getModel('core/resource_transaction')
                                               ->addObject($invoice)
                                               ->addObject($invoice->getOrder());
                            $transactionSave->save();

                            // Now its setting the status to processing. 
                            // for virtual products this might not required. 
                            // please test only with invoice generate code.

                            $invoice->getOrder()->setIsInProcess(true);
                            $order->addStatusHistoryComment(Mage::helper('yourmodule')->__('Auto Invoice generated.'), 
                                                                Mage_Sales_Model_Order::STATE_PROCESSING)->setIsCustomerNotified(true);
                            $invoice->sendEmail(true, '');
                            $order->save(); 
                        }

                    } catch (Exception $e) {
                        $order->addStatusHistoryComment('AutoInvoice: Exception occurred during autoInvoice action. Exception message: '.$e->getMessage(), false);
                        $order->save();
                    }
            return $this;
        }
    }


--
If my answer is useful, please Accept as Solution & give Kudos

View solution in original post

1 REPLY 1

Re: Orders no longer generate auto invoices.

Hello @izette_groenewald1 ,

 

We don't know about your implemented functionality, For generate invoice, Please create a small module for it. I hope that you have experienced to create a module in Magento 1

 

Step1: Insert below event to your config.xml

<events>
        <sales_order_place_after>
            <observers>
                <yourmodule_autoinvoice>
                    <class>yourmodule_autoinvoice/observer</class>
                    <method>autoInvoice</method>
                </yourmodule_autoinvoice>
            </observers>
        </sales_order_place_after>
</events>

then in observer event function use the logic to generate invoice and update order status.

class Yourmodule_Autoinvoice_Model_Observer
    {
        public function autoInvoice($observer) 
        {
                // loading placed order using observer.

                $order = $observer->getEvent()->getOrder();
                $orders = Mage::getModel('sales/order_invoice')->getCollection()->addAttributeToFilter('order_id', array('eq'=>$order->getId()));
                $orders->getSelect()->limit(1);

                if ((int)$orders->count() !== 0) {
                    return $this;
                }

                try {
                        // checking the order can invoice or not.

                        if(!$order->canInvoice()) {
                            $order->addStatusHistoryComment('AutoInvoice: Order cannot be invoiced.', false);
                            $order->save();
                        } else {

                            $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();

                            // below capture method depends on your payment method.
                            // here I used CAPTURE_OFFLINE method.

                            $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
                            $invoice->register();

                            $transactionSave = Mage::getModel('core/resource_transaction')
                                               ->addObject($invoice)
                                               ->addObject($invoice->getOrder());
                            $transactionSave->save();

                            // Now its setting the status to processing. 
                            // for virtual products this might not required. 
                            // please test only with invoice generate code.

                            $invoice->getOrder()->setIsInProcess(true);
                            $order->addStatusHistoryComment(Mage::helper('yourmodule')->__('Auto Invoice generated.'), 
                                                                Mage_Sales_Model_Order::STATE_PROCESSING)->setIsCustomerNotified(true);
                            $invoice->sendEmail(true, '');
                            $order->save(); 
                        }

                    } catch (Exception $e) {
                        $order->addStatusHistoryComment('AutoInvoice: Exception occurred during autoInvoice action. Exception message: '.$e->getMessage(), false);
                        $order->save();
                    }
            return $this;
        }
    }


--
If my answer is useful, please Accept as Solution & give Kudos