0

I'm having a problem in a Magento Module. I'm trying to modify a module to add an observer that will do stuf only after the invoice is created and the order is paid (sales_order_invoice_save_after), and this is what the config file looks like:

<?xml version="1.0"?>
<config>
  <modules>
    <Datasource_Moloni>
      <version>0.1.0</version>
    </Datasource_Moloni>
  </modules>
  <global>
    <helpers>
      <moloni>
        <class>Datasource_Moloni_Helper</class>
      </moloni>
    </helpers>
    <blocks>
      <moloni>
        <class>Datasource_Moloni_Block</class>
      </moloni>
    </blocks>
    <models>
        <moloni>
            <class>Datasource_Moloni_Model</class>
        </moloni>
    </models>
    <events>
        <sales_order_invoice_save_after>
            <observers>
                <moloni>
                    <class>moloni/auto</class>
                    <method>genInvoice</method>
                    <type>model</type>
                </moloni>
            </observers>
        </sales_order_invoice_save_after>
    </events>
  </global>
  <admin>
    <routers>
      <moloni>
        <use>admin</use>
        <args>
          <module>Datasource_Moloni</module>
          <frontName>moloni</frontName>
        </args>
      </moloni>
    </routers>
  </admin>
  <adminhtml>
    <menu>
      <moloni module="moloni">
        <title>Moloni</title>
        <sort_order>100</sort_order>
        <children>
          <molonibackend module="moloni">
            <title>Moloni</title>
            <sort_order>0</sort_order>
            <action>moloni/adminhtml_molonibackend</action>
          </molonibackend>
        </children>
      </moloni>
    </menu>
    <acl>
      <resources>
        <all>
          <title>Allow Everything</title>
        </all>
        <admin>
          <children>
            <moloni translate="title" module="moloni">
              <title>Moloni</title>
              <sort_order>1000</sort_order>
              <children>
                  <molonibackend translate="title">
                    <title>Moloni</title>
                  </molonibackend>
              </children>
            </moloni>
          </children>
        </admin>
        <moloni_write>
            <connection>
                <use>core_write</use>
            </connection>
        </moloni_write>
      </resources>
    </acl>
    <layout>
      <updates>
        <moloni>
          <file>moloni.xml</file>
        </moloni>
      </updates>
    </layout>
  </adminhtml>
</config> 

It tries to run the script in the folder includes/src folder, where I have the file Datasource_Moloni_Model_Observer.php .

Inside that file, I have something like this:

<?php

class Datasource_Moloni_Model_Auto
{
public function genInvoice(Varien_Event_Observer $observer)
    { 
         echo "inside the function";
    }
}

echo "outside";

The result no matter what is always "outside". I've tried changing the class so many times in the XML and the PHP files, that I don't know how many things I tried...

Anyone knows why this is happening or has any sugestion? Would love to ear some feedback!

0

Echoing in files to test them is not ideal. Even more in observers as the way they are called is different than anything else.

I would recommend:

  • Enable the logs in the backend
  • Replace your echo with Mage::log("inside the function"); . Also don't add echo outside of a class declaration, it won't help you debug it.
  • Or even better, use xdebug and add a breakpoint inside your function to see if it's called.
  • Also as you said "It tries to run the script in the folder includes/src folder" I would suggest you disable the compiler under System > Tools > Compilation when developping your module. Recompile and reenable once you're finished your development

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.