Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Help with my first “Hello World” module
 
rcourtna
Jr. Member
 
Total Posts:  8
Joined:  2008-04-17
 

Hello,

I’m trying to write a simple module that will change the title of all items in a shopping cart to “hello world”, and do so without hacking “core” files. 

I think I have a good understanding about what to do, and how it should work.  I’m able to get my module to appear as Enabled in the admin, but my “hello world” never shows up.  I’ve disabled the Magento cache as well. 

Here’s what I’ve done:

1. created etc/modules/MyCompany_HelloWorld.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
MyCompany_HelloWorld>
            <
active>true</active>
            <
codePool>local</codePool>
        </
MyCompany_HelloWorld>
    </
modules>
</
config>

2. created app/local/MyCompany_HelloWorld/etc/config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
MyCompany_HelloWorld>
            <
version>0.1.0</version>
        </
MyCompany_HelloWorld>
    </
modules>
    <global>
    <
blocks>
      <
checkout>
        <
rewrite>
          <
cart>MyCompany_HelloWorld_Checkout_Block_Cart</cart>
        </
rewrite>
      </
checkout>
    </
blocks>
    </global>
</
config>

3. Created app/local/MyCompany_HelloWorld/Block/Checkout/Cart.php

<?php
class MyCompany_HelloWorld_Checkout_Block_Cart extends Mage_Checkout_Block_Cart
{

    
public function getItemName($item)
    
{
        
return 'Hello World';
    
}

}

4. Verified in Admin that my new module is enabled

At this point, I’d expect items in my shopping car to all have a title of “Hello World”.  However, it doesn’t work.  I suspect it’s something in my .xml config files.  Am I missing anything obvious?  What troubleshooting steps should I be taking from here?

Thank you!
Ryan

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Change your file locations from

app/local/MyCompany_HelloWorld
to
app/code/local/MyCompany/HelloWorld
 
Magento Community Magento Community
Magento Community
Magento Community
 
rcourtna
Jr. Member
 
Total Posts:  8
Joined:  2008-04-17
 

Thanks to ‘hardcorelamer’ on the IRC for helping me out on this.  Turns out I was close (but not close enough!).  I had some path problems, and some class naming problems.

I was going to add a wiki page, but that appears to be broken.  I’ll regurgitate it below with the corrections in place.

HOW TO WRITE A MODULE THAT CHANGES THE TITLE OF ALL ITEMS IN A SHOPPING CART TO “HELLO WORLD”

1. create etc/modules/MyCompany_HelloWorld.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
MyCompany_HelloWorld>
            <
active>true</active>
            <
codePool>local</codePool>
        </
MyCompany_HelloWorld>
    </
modules>
</
config>

2. create app/local/MyCompany/HelloWorld/etc/config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
MyCompany_HelloWorld>
            <
version>0.1.0</version>
        </
MyCompany_HelloWorld>
    </
modules>
    <global>
    <
blocks>
      <
checkout>
        <
rewrite>
          <
cart>MyCompany_HelloWorld_Block_Checkout_Cart</cart>
        </
rewrite>
      </
checkout>
    </
blocks>
    </global>
</
config>

3. Create app/local/MyCompany/HelloWorld/Block/Checkout/Cart.php

<?php
class MyCompany_HelloWorld_Block_Checkout_Cart extends Mage_Checkout_Block_Cart
{

    
public function getItemName($item)
    
{
        
return 'Hello World';
    
}

}

4. Make sure the module is enabled in admin->System->Configuration->Advanced

Now when viewing items in your shopping cart, they’ll have a title of “Hello World”.  How useful is that!?

Ryan

 
Magento Community Magento Community
Magento Community
Magento Community
 
rcourtna
Jr. Member
 
Total Posts:  8
Joined:  2008-04-17
 

thanks to Moshe too!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
harish
Jr. Member
 
Total Posts:  23
Joined:  2008-04-01
 

i followed the step described by you. nothing changed.

anyway its really good tutorial.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rcourtna
Jr. Member
 
Total Posts:  8
Joined:  2008-04-17
 
harish - 22 April 2008 02:23 AM

i followed the step described by you. nothing changed.

anyway its really good tutorial.

Please follow my second post, as some of the class names where ass-backwards in the first.

 
Magento Community Magento Community
Magento Community
Magento Community
 
harish
Jr. Member
 
Total Posts:  23
Joined:  2008-04-01
 

its working fine. i forgot to refresh cache.

thanx

 
Magento Community Magento Community
Magento Community
Magento Community
 
Adam_Shuy
Member
 
Avatar
Total Posts:  51
Joined:  2008-02-20
San Jose, CA
 

Magento did not read the config.xml under the app/local/MyCompany/HelloWorld/etc/ directory.  Because I took out one tag of this config.xml and run it but nothing happen (I am expecting some error message).  So the rewrite never happen.  Can anybody tell me why? I did refresh the cache all the time.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nafnaf1000
Sr. Member
 
Total Posts:  209
Joined:  2008-02-21
 

I got this to work......

except that the who card dos not work at ALL the is it “Disabled” ......

 
Magento Community Magento Community
Magento Community
Magento Community
 
BoostMyShop
Sr. Member
 
Avatar
Total Posts:  155
Joined:  2008-06-11
France
 

nice sample !
however, the main difficulties is to know magento class organization: i read that magento team will soon provide such a documentation but i wander if zend studio could help me to parse class structure

thanks for ur answer smile

olixelle

 
Magento Community Magento Community
Magento Community
Magento Community
 
nabler
Sr. Member
 
Total Posts:  80
Joined:  2010-07-27
 

it not show in front end and admin...i have followed all you step..

 
Magento Community Magento Community
Magento Community
Magento Community
 
mnbnour
Jr. Member
 
Total Posts:  3
Joined:  2010-03-13
 

Hello

could you please attach the files

thanks in advance

Noor

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top