Creating Hello world event dispatcher(observer) in Magento?

前端 未结 3 1111
挽巷
挽巷 2021-01-01 09:23

I am trying to create an event dispatcher in Magento (which should be called after a product gets added to cart).

What I\'ve done so far:

I Googled this and

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 10:12

    Looking at your code downloaded from http://goo.gl/O7dBy you define:

    
        
            
                
                    dispatcher/observer
                    hookToAddToCartAfter
                
            
        
    
    

    and define the model alias of dispatcher as:

    
        
            MyPackage_Crossdata_Dispatcher_Model
        
    
    

    The resulting class name would be MyPackage_Crossdata_Model_Dispatcher_Model_Observer, but your observer class is named MyPackage_Crossdata_Dispatcher_Model_Observer, missing the Model in between Crossdata and Dispatcher.

    I'd recommend to drop the whole dispatcher models definition above and only use the other model alias crossdata which you've already defined in config.xml:

    
        MyPackage_Crossdata_Model
        crossdata_mysql4
       
    

    Then change the event definition to:

    
        crossdata/observer
        hookToAddToCartAfter
    
    

    Create a file /app/code/local/MyPackage/Crossdata/Model/Observer.php and define your observer class in it:

    class MyPackage_Crossdata_Model_Observer
    {
        public function hookToAddToCartAfter($observer)
        {
            // your observer code
        }
    }
    

提交回复
热议问题