I have been overriding the function saveOrderAction in the OnepageController.php (/app/code/core/Mage/Checkout/controllers) with my custom code.
I have implemented the logic for this successfully. I believe at this point at the start of the function as the order hasn't been completed there is no order ID. Instead I have access to the 'quote ID'.
What I need to do now is find out where the Order ID is generated for the order. My first question is which file/function is best to override for when the Order ID is created?
My second question is, is there a way to link the quote ID to the Order ID which is generated?
Essentially my aim is to get the order ID of the currently ordered items so I can do further custom processing.
My observer code is through this path: /local/James/Aftercheckout
config.xml – /local/James/Aftercheckout/etc
Observer.php – /local/James/Aftercheckout/Model
Contents of config.xml:
<?xml version="1.0"?>
<config>
<modules>
<James_Aftercheckout>
<version>0.1.0</version>
</James_Aftercheckout>
</modules>
<global>
<events>
<sales_model_service_quote_submit_before>
<observers>
<james_aftercheckout_observer>
<type>singleton</type>
<class>James_Aftercheckout_Model_Observer</class>
<method>test</method>
</james_aftercheckout_observer>
</observers>
</sales_model_service_quote_submit_before>
</events>
</global>
Code for Observer.php :
class James_Aftercheckout_Model_Observer
{
public function test($observer)
{
$quote = $observer->getEvent()->getQuote();
$incrementId = $quote->getReservedOrderId();
$to = "myemail@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message! .".$incrementId;
$from = "randomemail@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
}
}
Best Answer
The increment id of the order is created when the order is submitted, in this method
Mage_Sales_Model_Service_Quote::submitOrder()
. The line responsible for the creation is$quote->reserveOrderId();
.If you want to access it you can hook onto the event
sales_model_service_quote_submit_before
.You will be able to get the increment id in you observer like this: