Armand Ndizigiye
Armand Ndizigiye

Reputation: 199

magento event observer (magento1.7)

i am trying to implement an simple observer in my module (app/code/local/Foo/Bar). My objective is to set the product names to '[product name] is cool' when a product is loaded in the frontend.

These are my files: app/code/local/Foo/Bar/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>

<config>
    <global>
        <models>
            <foo_bar>       
                    <class>Foo_Bar_Model</class>
            </foo_bar>  
        </models>
    </global>
    <frontend>
        <events>
            <catalog_product_load_after>
                <observers>
                    <foo_bar>
                        <type>model</type>
                        <class>foo_bar/observer</class>
                        <method>catalogProductLoadAfter</method>
                    </foo_bar>
                </observers>
            </catalog_product_load_after>
        </events>
    </frontend>
</config>

app/code/local/Foo/Bar/Model/Observer.php

<?php 
class Foo_Bar_Model_Observer{

public function catalogProductLoadAfter(Varien_Event_Observer $observer)

{
    $product = $observer ->getProduct();

    $product ->setName($product.getName().' '.'is cool');
} 
}
?>

And i have also configured the module in app/etc/modules/Foo_Bar.xml

<?xml version="1.0" encoding="UTF-8"?>
 <config>
   <modules>
     <Foo_Bar>
        <active>true</active>
        <codePool>local</codePool>
     </Foo_Bar>
  </modules>
</config>

But it doenst work, does anyone have any suggestion?

Upvotes: 3

Views: 1611

Answers (1)

Andrew
Andrew

Reputation: 12809

You only need to module name for the model:

<foo_bar>
     <type>model</type>
     <class>bar/observer</class>
     <method>catalogProductLoadAfter</method>
</foo_bar>

you don't need to specify Foo_Bar

also have you an error in your PHP

$product ->setName($product.getName().' '.'is cool');

should be

$product->setName($product->getName().' '.'is cool');

Upvotes: 2

Related Questions