Home / Magento / Create a event observer after order submit Magento 1x

Create a event observer after order submit Magento 1x

Create a event observer after order submit. Bellow code is need to add in your module path/etc/config.xml if you have already adminhtml tag then just ignore adminhtml tag. in bellow code Trenza_Prescription is the module name. and class is the class name of which trigger it do when observer event run. Method is which class function run for this observer event.

<adminhtml>
		<events>
			<sales_order_place_after>
				<observers>
					<Trenza_Prescription>
						<type>singleton</type>
						<class>Trenza_Prescription_Model_Observer</class>
						<method>updatePrescription</method>
					</Trenza_Prescription>
				</observers>
			</sales_order_place_after>
		</events>
	</adminhtml>

Now add this class on your magento module model create a file name Observer.php

<?php
Class Trenza_Prescription_Model_Observer
{
    public function updatePrescription($observer) {
        #echo 'hi';
        #print_r(Mage::app()->getRequest()->getParams()) ;
        #$order_id = $observer->getReservedOrderId();
        $order = $observer->getEvent()->getOrder();
        $order_id = $order->getId();
        
        $session = Mage::getSingleton('core/session', array ('name' => 'backend'));
        #echo Mage::getSingleton('core/session')->setOrdersession2('hello');
        $prescription_id = Mage::getSingleton('core/session')->getOrdersession();
        
        
        $data = array('orderid'=>$order_id);
        $model = Mage::getModel('prescription/prescription')->load($prescription_id)->addData($data);
        try {
                $model->setId($prescription_id)->save();
                Mage::getSingleton('core/session')->unsOrdersession();
                #echo "Data updated successfully.";
               
            } catch (Exception $e){
                echo $e->getMessage(); 
        }
    }
}

Hits: 149

%d bloggers like this: