0

I am using magento 1.8. I have requirement that need to save the order details in separate custom table. for this I need to execute saveorder method using observer event sales_order_place_after But when I am clicking place order, My observer function is not executing,

My config.xml file content

 <?xml version="1.0"?> <config> <modules> <Npm_Commission> <version>0.1.0</version> </Npm_Commission> </modules> <global> <events> <sales_order_place_after> <observers> <npm_commission> <type>singleton</type> <class>Npm_Commission_Model_Observer</class> <method>calculate_commission</method> </npm_commission> </observers> </sales_order_place_after> </events> <resources> <commission_setup> <setup> <module>Npm_Commission</module> </setup> <connection> <use>core_setup</use> </connection> </commission_setup> <commission_write> <connection> <use>core_write</use> </connection> </commission_write> <commission_read> <connection> <use>core_read</use> </connection> </commission_read> </resources> <models> <commission> <class>Npm_Commission_Model</class> <resourceModel>commission_mysql4</resourceModel> </commission> <commission_mysql4> <class>Npm_Commission_Model_Mysql4</class> <entities> <commission> <table>commission</table> </commission> </entities> </commission_mysql4> </models> </global> </config> 

my observer method

<?php class Npm_Commission_Model_Observer extends Varien_Event_Observer { public function saveorder($observer) { die('sales_order_place_after'); $params = Mage::app()->getFrontController()->getRequest()->getParams(); echo "<pre>";print_r($params);die(); } 

If this information is not enough, add in comment for other part of code. And suggest any other idea for this issue, Or my faults in this code.

Thank you friends:)

4
  • it seems code you pasted is fine.please paste the whole code from your config.xml Commented Jun 18, 2014 at 14:04
  • What payment method do you use? Afaik there are a few events which don't fire with paypal Commented Jun 18, 2014 at 15:19
  • Yes, I used paypal only Commented Jun 18, 2014 at 15:43
  • 1
    @Charlie method name should be saveorder and not calculate_commission in config.xml. I bet you would have already solved it :) Commented Sep 18, 2014 at 0:04

2 Answers 2

1

There are small issue ,in closing backet of class Npm_Commission_Model_Observer and method name is wrong, should calculate_commission from saveorder as xml define

<?php class Npm_Commission_Model_Observer extends Varien_Event_Observer { public function saveorder($observer) { die('sales_order_place_after'); $params = Mage::app()->getFrontController()->getRequest()->getParams(); echo "<pre>";print_r($params);die(); } } /* it was missing */ 

Also

total code config.xml code is (path app/code/local/Npm/Commission/etc)

<?xml version="1.0"?> <config> <modules> <Npm_Commission> <version>0.1.0</version> </Npm_Commission> </modules> <global> <models> <commission> <class>Npm_Commission_Model</class> <resourceModel>commission_mysql4</resourceModel> </commission> <commission_mysql4> <class>Npm_Commission_Model_Mysql4</class> <entities> <commission> <table>commission</table> </commission> </entities> </commission_mysql4> </models> <events> <sales_order_place_after> <observers> <npm_commission> <type>singleton</type> <class>commission/observer</class> <method>calculate_commission</method> </npm_commission> </observers> </sales_order_place_after> </events> <resources> <commission_setup> <setup> <module>Npm_Commission</module> </setup> <connection> <use>core_setup</use> </connection> </commission_setup> <commission_write> <connection> <use>core_write</use> </connection> </commission_write> <commission_read> <connection> <use>core_read</use> </connection> </commission_read> </resources> </global> </config> 

Observer.php path app/code/local/Npm/Commission/Model

<?php class Npm_Commission_Model_Observer extends Varien_Event_Observer { public function calculate_commission($observer) { $order = $observer->getEvent()->getOrder(); if (!$order) { return $this; } //die('sales_order_place_after'); Mage::log('sales_order_place_after'); //$params = $observer->getEvent()->getOrder; Mage::log(print_r($order->getData('increament_id'),true)); //echo "<pre>";print_r($params);die(); } } 

etc/modules files Npm_Commission.xml

<?xml version="1.0" ?> <config> <modules> <Npm_Commission> <codePool>local</codePool> <active>true</active> </Npm_Commission> </modules> </config> 
0

rather then you die you Mage::log('testing');

Follow the below code

<?php class Npm_Commission_Model_Observer extends Varien_Event_Observer { public function saveorder($observer) { Mage::log('sales_order_place_after'); $params = Mage::app()->getFrontController()->getRequest()->getParams(); Mage::log(print_r($params,true)); } 

Make you have enable log in Magento. system >> Configuration >> Developer >> Log.

To check your data var/log.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.