Magento Forum

Question on file structure
 
SwiftCol
Sr. Member
 
Total Posts:  85
Joined:  2008-05-22
 

I am looking at app/design/frontend/default/default/layout/page.xml, and I have deduced that a blocks “type” attribute coresponds with that blocks class, located with in app/code/core/Mage/

So if I put in page/html_breadcrumbs
it will grab app/code/core/Mage/page/Block/html/breadcrumbs.php

Can you please explain this relationship? What if I wanted to edit the breadcrumbs class? I don’t want to change a core file, because that may prevent me from upgrading Magento later on, but i don’t know how to get anything to point to php classes in the local folder (as appossed to ‘core’)

As you can see i’m rather new at all of this, and any explanation or Wiki link that you can provide to help me understand how you go from a line in an XML file, to a PHP class being loaded, would really be appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

You are on the right track. Instead of modifying a core class, you make a new class that extends that class. Then you tell Magento to use your class instead of the one from the core. You can do that by “rewriting” the class in local.xml as shown here:

http://www.magentocommerce.com/wiki/groups/174/changing_and_customizing_magento_code

You can also make your own xml file and put it in app/etc/modules.

 
Magento Community Magento Community
Magento Community
Magento Community
 
SwiftCol
Sr. Member
 
Total Posts:  85
Joined:  2008-05-22
 

It this a standard Smarty template thing, or Magento specific?
Thanks for the link and info.

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

It’s not Smarty, it’s Magento’s own way of doing it. XML files for setting up the layout (blocks) and then html templates for each block.

 
Magento Community Magento Community
Magento Community
Magento Community
 
SwiftCol
Sr. Member
 
Total Posts:  85
Joined:  2008-05-22
 

Anders,

I have copied the original app/code/core/Mage/Catalog/Block/Category/Breadcrumbs.php into a new folder located at app/code/local/MyCompany/Catalog/Block/Breadcrumbs.php

I changed ’Home‘ to ’Home!!!‘ on line 35 so that i could see if my change had worked. (Home / Electronics / Laptops should become Home!!! / Electronics / Laptops )

The part about the blocks tag inside local.xml confused me, but this is what I tried adding at the bottom of local.xml just before </global>:

<modules>
            <
MyCompany_Catalog>
                <
active>true</active>
                <
codePool>local</codePool>
                <
blocks>
                    <
catalog>
                        <
rewrite>
                            <
breadcrumbs>MyCompany_Catalog_Block_Breadcrumbs</breadcrumbs>
                        </
rewrite>
                    </
catalog>
                </
blocks>
            </
MyCompany_Catalog>
        </
modules>

Long story short, I am not seeing a change in the breadcrumbs on my site. (I am using breadcrumbs as an example to learn how to make these changes.) By the way, I have all caching turned off while I do these tests. Can you help me figure out what i’ve done wrong, or skipped?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

I just tried doing the same as you and ran into the same problem. I looked a little closer at Breadcrumbs.php and discovered that you cannot just copy it directly. You have to replace return parent::_prepareLayout(); with return $this;

The problem is, it calls the old function which will overwrite your changes.

Also, remember to replace class Mage_Catalog_Block_Breadcrumbs extends Mage_Core_Block_Template with class MyCompany_Catalog_Block_Breadcrumbs extends Mage_Catalog_Block_Breadcrumbs.

 
Magento Community Magento Community
Magento Community
Magento Community
 
SwiftCol
Sr. Member
 
Total Posts:  85
Joined:  2008-05-22
 

I did make the change to the name of the classes, (and forgot to post it above.)
It’s good to know that the issue is now PHP code, not in how I have setup Magento files. Thanks for your help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
SwiftCol
Sr. Member
 
Total Posts:  85
Joined:  2008-05-22
 

Anders,
I am still unable to get this to work. I can’t event get my Breadcrumbs.php to print something and exit PHP, so I don’t think that Magento is even getting to that page. I’m thinking that maybe my theme might be the issue. Do my theme have anything to do with me customizing the breadcrumb module?
Thank you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

If Magento’s core breadcrumbs is displayed in your theme, it should also be possible to make it use your own Breadcrumbs.php. Instead of your xml above, try to just put the following in global in local.xml:

<blocks>
    <
catalog>
        <
rewrite>
            <
breadcrumbs>MyCompany_Catalog_Block_Breadcrumbs</product_featured>
        </
rewrite>
    </
catalog>
</
blocks>
 
Magento Community Magento Community
Magento Community
Magento Community
 
SwiftCol
Sr. Member
 
Total Posts:  85
Joined:  2008-05-22
 

Thank you kindly.
Can you explain why return $this; works? Shouldn’t it just return an object representation of the class? I don’t see how that translates to a rendered breadcrumb built earlier in the function.
Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

Well, let’s look at what return parent::_prepareLayout(); in Breadcrumbs.php actually means. The parent is Mage_Core_Block_Template, but that one doesn’t have a _prepareLayout() function, so let’s go to the “grand parent”, which is Mage_Core_Block_Abstract. Look at _prepareLayout() in that class. It just says return $this.

Now the problem was that your subclass of Breadcrumbs would call the function in the old Breadcrumbs class, which we don’t want, because it will overwrite your changes. So, we just replace return parent::_prepareLayout(); with the grand parent’s definition of _prepareLayout() which is return $this;

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