Thursday, November 8, 2018

Invoice Auto Generation in Magento

Sometimes the Magento order process causes more work than a client desires. Imagine you have a client who utilizes their Magento eCommerce store so their customers can make purchases online. Now they also want to process orders on their own with customers from their physical store.

If they were to place an order, they would need to also invoice and process shipping. This becomes cumbersome. Here we bypass this so that placing a successful order with payment will auto invoice the order so it is complete and nothing more is required.

Create NAMESPACE folder under app/code/community/MCorner

• Create module folder "MCornerOrdersObserver" as we will use this one as the name of our module

• app/code/community/MCorner/MCornerOrdersObserver

• Create Folders

• app/code/community/MCorner/MCornerOrdersObserver/etc

• app/code/community/MCorner/ MCornerOrdersObserver/Model

• app/code/community/MCorner/ MCornerOrdersObserver/Helper

• Create the config.xml file

• app/code/community/MCorner/MCornerOrdersObserver/etc/config.xml

• Inside the config.xml file copy and paste the code below

******************************************************************************

0.1.0MCorner_MCornerOrdersObserver_Model_ObserverMCorner_MCornerOrdersObserver_Model_ObserverafterSalesOrderSaveCommitAfterMCorner_MCornerOrdersObserver_Helper

******************************************************************************

Create the main observer file:

• app/code/community/MCorner/ MCornerOrdersObserver/Model/Observer.php

• Copy and paste the code below into app/code/community/MCorner/ MCornerOrdersObserver/Model/Observer.php

******************************************************************************

class MCorner_MCornerOrdersObserver_Model_Observer {

public $order;//the order...

function afterSalesOrderSaveCommitAfter(&$event) {

return $this->__process($event);

}

protected function __process($event) {

$this->order = $event->getEvent()->getOrder();

if (!$this->order->getId()) {

//order is not saved in the database

return $this;

}

else {

$this->createInvoice();

}

}

protected function createInvoice() {

$orderState = $this->order->getState();

if ($orderState === Mage_Sales_Model_Order::STATE_NEW) { // Check for state new.

if ($this->order->canInvoice()) {

$this->order->getPayment()->setSkipTransactionCreation(false);

$invoice = $this->order->prepareInvoice();

$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);

$invoice->register();

Mage::getModel('core/resource_transaction')

->addObject($invoice)

->addObject($this->order)

->save();

}

else {

//we can not invoice it so the process is normal.

}

}

}

}

?>

******************************************************************************

To activate the observer module create the module file:

• app/etc/modules/MCorner_ MCornerOrdersObserver.xml

• Copy and paste the code below

******************************************************************************

truecommunity

******************************************************************************

Make sure all files are saved in their locations as in the tutorial and now go into Magento admin and CLEAR ALL CACHE.

Now, if an order is placed through your Magento store it will automatically be invoiced and the invoice amount will be charged. An invoice will be created and an email will be sent. This functionality is similar to clicking the Invoice Button in Magento order administration.













Share on Facebook
Share on Twitter
Share on Google+
Tags :

Related : Invoice Auto Generation in Magento

0 comments:

Post a Comment

  • How To Make Money Online With Games Are you fed up with having to wake up early to catch the morning cable or beat traffic on the roads? Is your boss becoming too much knowing that your survival depends on him? If so, this is the time to start thinking of how you can make money…
  • The Basics and Tips of Direct Marketing Direct marketing is an approach to product marketing communications that does not employ contemporary marketing channels. This absolutely means that deals are done directly between the manufacturers and customers without involving channel…
  • Credit Repair Tips There are many methods to credit repair and if you have poor credit scores then you should consider restoring your credit. You will enjoy an increase in your financial freedom when you take steps towards bad credit repair. Bad credit can be…
  • Hire Web Developer - 10 Important Points to Ponder Upon Nowadays it is almost an outdated thought to run a business without online presence! Besides that people know that online presence increases or just double the Return on Investment for all the businesses! Also institutions or organization do…
  • Important Reasons To Consider Windows Mobile App DevelopmentYou must have noticed people holding their Android phones or iPhones for communication or shopping, but now new operating systems are also entering the market with great features and the trends are also changing. It is really interesting to note…
Invoice Auto Generation in Magento
Important: This article is about the Invoice Auto Generation in Magento, The best of Invoice Auto Generation in Magento inspiration updated regularly with new designs and info, and featuring the best Invoice Auto Generation in Magento
Originally Answered: What are the best sites?
Invoice Auto Generation in Magento April 2025, We Always give correct and complete information about Invoice Auto Generation in Magento, This document provides Invoice Auto Generation in Magento We want to improve the quality of content for all. By using information about the content you have received, those involved in providing info in April 2025.

Advertisement