How to get Order No. at event sales_order_place_after using event-observer model?
I want to get Order No. as soon as order is placed by customer.
I want to pass that order no. to another external php file & include that php file in the Observer.php? How Can I do that?
I am trying to include external php file in Magento but I am unable to do that.
Observer.php:
<?php
include("connection/Final/Function1.php");
class Sample_Event_Model_Observer {
public function Mytestmethod($observer) {
$event = $observer->getEvent(); //Fetches the current event
$eventmsg = "Current Event Triggered : <I>" . $event->getName() . "</I>";
echo Mage::getSingleton('checkout/session')->addSuccess($eventmsg);
$Id = $observer->getEvent()->getOrder()->getId();
$incrementid = $observer->getEvent()->getOrder()->getIncrementId();
$ordermsg1 = "Current order Id : <I>" . $Id . "</I>";
echo Mage::getSingleton('checkout/session')->addSuccess($ordermsg1);
$ordermsg2 = "Current increment Id : <I>" . $incrementid . "</I>";
echo Mage::getSingleton('checkout/session')->addSuccess($ordermsg2);
$p = new testDatabase();
$p -> setId($incrementid);
$p -> dbConnect();
}
}
?>
Function1.php:
<?php
class testDatabase
{
public function setId($getId)
{
$incrementid=$getId;
echo $incrementid;
}
public function dbConnect()
{
$db_name = "magento";
$con = mysql_connect("localhost", "magento", "password");
If (!$con)
{
die('Could not connect: ' . mysql_error());
}
$seldb = mysql_select_db($db_name, $con);
If ($seldb)
{
echo "Database Found ";
$query = "INSERT INTO sample(id) VALUES($incrementid)" ;
$result = mysql_query($query);
print "id is added to the database";
mysql_close($seldb);
}
else
{
echo "Database NOT Found ";
}
}
}
How can I access variable $incrementid
in Function1.php
? My problem is I am unable to access $incrementid
as it is unable to insert in my sample table.
I have caught sales_order_place_after
event. So that once customer press PLACE ORDER, I can include Function1.php & it will take increment/order id & I can able to access Functions in it that will do needful job.