0
votes

I'm getting confused about the configuration of my config.xml file. I tried following this example at the bottom of the page https://wiki.magento.com/display/m1wiki/Using+the+Event-Observer+Method+in+Magento+1.x
with this result:

<events>
  <catalog_product_save_before>
    <observers>
      <Pfay_Vert_observer>
        <type>singleton</type>
        <class>Pfay_Vert_Model_Observer</class>
        <method>databaseOverlayUpdater</method>
      </Pfay_Vert_observer>
    </observers>
  </catalog_product_save_before>
</events> 

My module is called Vert and my namespace Pfay.
My Observer.php looks like this:

class Pfay_Vert_Model_Observer 
  { 
   public function databaseOverlayUpdater($event)
  {
     $data= $event->getData();
     //scripts 
  }
}
1
Can you be more specific about the problem ? - Rabea
the script is not running and I don't know where is the problem(if inside observer.php or config.xml), I'm fairly new to magento so everything is kinda of a haze - Javis Ulrick
is this observer setup under the <global> tag ? and where are you testing this ? adminpanel ? some other place? - Rabea
yes this code is inside the <global> tag, I'm testing this by adding and removing products in the database(I have a front end page to do that). The script itself has a fwrite on txt file to confirm if it is running or not. Maybe I'm messing up the activation method? - Javis Ulrick
you are doing it through the database directly ? a sql query ? - Rabea

1 Answers

0
votes

specify observer in global tag in config.xml

<global>
  ..
  ..
  <events>
    <my_custom_event>
      <observers>
        <namespace_modulename_my_custom_event_observer>
          <type>singleton</type>
          <class>modulename/observer</class>
          <method>my_custom_method</method>
        </namespace_modulename_my_custom_event_observer>
      </observers>
    </my_custom_event>
  </events>
  ..
  ..
</global>

your observer should looks like this.

<?php
class Namespace_Modulename_Model_Observer
{
  public function my_custom_method($observer) {
    $event = $observer->getEvent();

    // getter method to fetch cid value passed from the dispatcher
    $cid = $event->getCid();
    echo $cid;
    exit;
  }
}

I hope this will help you calling observer and define in config.xml.