1

I have this code, after trying for hours I still cant figure this out.. Custom API works fine but the observer never fires..

I want to fire this observer after an admin edits/saves a customer through admin panel.

local/ghs/ghsapi/etc/api.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <ghs_ghsApi>
            <version>0.1.0</version>
        </ghs_ghsApi>
    </modules>


    <global>
        <models>
            <ghs_ghsapi>
            <class>ghs_ghsApi_Model</class>
            </ghs_ghsapi>
        </models>

        <events>
            <adminhtml_customer_save_after>
                <observers>
                    <fire_delete>
                        <class>ghs_ghsapi/observer</class>
                        <method>observeOrders</method>
                    </fire_delete>
                </observers>
            </adminhtml_customer_save_after>
        </events>
</global>


    <api>
        <resources>
            <ghs translate="title" module="customer">
                <model>ghs_ghsApi_Model_Api</model>
                <title>Customer Resource</title>
                <acl>ghs</acl>
                <methods>
                    <orderlist translate="title" module="customer">
                        <title>Retrieve customer data</title>
                        <acl>ghs/orderlist</acl>
                        <method>orderlist</method>
                    </orderlist>

                    <ordertotal translate="title" module="customer">
                        <title>Retrieve customer data</title>
                        <acl>ghs/ordertotal</acl>
                        <method>ordertotal</method>
                    </ordertotal>


                </methods>
                <faults module="xyz">                   
                </faults>
            </ghs>
        </resources>
    </api>

</config>

local/ghs/ghsApi/Model/Observer.php:

<?php
class ghs_ghsApi_Model_Observer
{

    public function observeOrders($observer)
    {
       Mage::log('Observer works!');

    }
}
1

aris;

Issue1: you have not create config.xml code and you have put config code at api.xml that is wrong; code is

<?xml version="1.0"?>
<config>
  <modules>
    <Ghs_Ghsapi>
      <version>0.1.0</version>
    </Ghs_Ghsapi>
  </modules>
  <global>
    <helpers>
      <ghs_ghsapi>
        <class>Ghs_Ghsapi_Helper</class>
      </ghs_ghsapi>
    </helpers>
    <models>
      <ghs_ghsapi>
        <class>Ghs_Ghsapi_Model</class>
      </ghs_ghsapi>
    </models>
    <events>
      <adminhtml_customer_save_after> <!-- identifier of the event we want to catch -->
        <observers>
          <adminhtml_customer_save_after_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>ghs_ghsapi/observer</class> <!-- observers class alias -->
            <method>observeOrders</method>  <!-- observer's method to be called -->
          </adminhtml_customer_save_after_handler>
        </observers>
      </adminhtml_customer_save_after>
    </events>
  </global>

Issue2: folder Name is wrong should be

Extension name Space: Ghs

and Module is : Ghsapi

That means folder stucure should be

Ghs/Ghsapi/etc/api.xml

Ghs/Ghsapi/etc/config.xml

Ghs/Ghsapi/Model/Observer.php

Issue3:api.xml code:

 <?xml version="1.0"?>
<config>
  <api>
        <resources>
            <ghs translate="title" module="customer">
                <model>ghs_ghsapi>/api</model>
                <title>Customer Resource</title>
                <acl>ghs</acl>
                <methods>
                    <orderlist translate="title" module="customer">
                        <title>Retrieve customer data</title>
                        <acl>ghs/orderlist</acl>
                        <method>orderlist</method>
                    </orderlist>

                    <ordertotal translate="title" module="customer">
                        <title>Retrieve customer data</title>
                        <acl>ghs/ordertotal</acl>
                        <method>ordertotal</method>
                    </ordertotal>

                </methods>
                <faults module="xyz">                   
                </faults>
            </ghs>
        </resources>
    </api>
  • Hello Amit, thank you this actually worked. I have few questions: 1. Does config.xml and api.xml need to be separate files? Don't they get merged? 2. Ghs_Ghsapi_Helper, why is this needed? – Aris Μπ. Nov 1 '14 at 12:38

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.