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

Page 1 of 2
Overriding catalog/breadcrumbs and catalog/products/view
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

Hi all -

Im using Magento v 1.1.2

I’ve read a few threads that say how to override / rewrite Magento Core classes - but I can’t get it work, and I have no clue why…

Files:
app/code/local/Fido/Catalog/Block/Breadcrumbs.php
app/code/local/Fido/Catalog/etc/config.xml
app/etc/modules/Fido_Catalog.xml

app/etc/modules/Fido_Catalog.xml

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

app/code/local/Fido/Catalog/etc/config.xml

<?xml version="1.0"?>
<config>
    <global>
        <
blocks>
            <
catalog>
                <
rewrite>
                    <
breadcrumbs>Fido_Catalog_Block_Breadcrumbs</breadcrumbs>
                </
rewrite>
            </
catalog>
        </
blocks>
    </global>
</
config>

app/code/local/Fido/Catalog/Block/Breadcrumbs.php

class Fido_Catalog_Block_Breadcrumbs extends Mage_Catalog_Block_Breadcrumbs  #note: extending file I'm overwriting, not the abstract class the original class extends (is this correct?)
{
    
protected function _prepareLayout()
    
{
        
if ($breadcrumbsBlock $this->getLayout()->getBlock('breadcrumbs')) {
            $breadcrumbsBlock
->addCrumb('home',
                array(
'label'=>Mage::helper('catalog')->__('Home'), 'title'=>Mage::helper('catalog')->__('Go to Home Page'), 'link'=>Mage::getBaseUrl())
            );

            
$title = (string)Mage::getStoreConfig('system/store/name');
            
$path Mage::helper('catalog')->getBreadcrumbPath($this->getCategory());
            foreach (
$path as $name=>$breadcrumb{
                $breadcrumbsBlock
->addCrumb($name$breadcrumb);
                
$title $breadcrumb['label'].' '.Mage::getStoreConfig('catalog/seo/title_separator').' '.$title;
            
}

            
if ($headBlock $this->getLayout()->getBlock('head')) {
                $headBlock
->setTitle($title);
            
}
        }
        
echo 'yay'#The new code just to test if it works! (string appears at the top of the screen if it is)
        
return parent::_prepareLayout();
    
}

}

What small thing am I missing? rasberry

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

it seems to be ok

did u disable cache management ?
does ur module appear in the advanced tab in admin system ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 
olixelle - 11 August 2008 10:20 AM

it seems to be ok

did u disable cache management ?
does ur module appear in the advanced tab in admin system ?

I just had to disable cacheing. I think I was messing with cacheing yesterday and forgot to turn if back off :(

False alarm, nothing to see here except the correct way to override Breadcrumbs.php rasberry

 
Magento Community Magento Community
Magento Community
Magento Community
 
Periculi
Sr. Member
 
Total Posts:  249
Joined:  2009-02-03
 

Would anyone know why this method doesn’t work for overriding catalog navigation, you know- the file right next to breadcrumbs.php?
This doesn’t work:

<?xml version="1.0"?>
<config>
    <global>
        <
blocks>
            <
catalog>
                <
rewrite>
                    <
navigation>HCP_Catalog_Block_Navigation</navigation>
                </
rewrite>
            </
catalog>
        </
blocks>
    </global>
</
config>

I wanted to rewrite Mage_Catalog_Block_Navigation and thought that since it was right next to Breadcrumbs in the Catalog Block folder that the same rewrite method would apply.

But it didn’t work.  I used the same set up for altering Mage_Checkout_Block_Links and that worked great, but seem to hit a snag with navigation.

Actually, I tried to override the breadcrumbs going step by step according to this “correct way to do it” thread, and nothing was overridden.  Is there some changes to how this is being handled in version 1.3.0???

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

I am trying the same thing

<global>
  <
blocks>
    <
catalog>
      <
rewrite>
        <
Navigation>
          
WDC_midwest_Block_navigation
        
</Navigation>
      </
rewrite>
    </
catalog>    
  </
blocks>
</global>

My module shows up but I get an error when I try to execute my code?

I create a navigation.php page in my local/WDC/midwest/Block folder

I added this funtion

public function WDC_drawItemreDux($category$level=0$last=false)
    
{
        
...

Then in the Top.phtml I change to this

<ul id="nav">   
 
<?php foreach ($this->getStoreCategories() as $_category): ?>
        <?php 
echo $this->WDC_Navigation->WDC_drawItemreDux($_category?>
    <?php 
endforeach ?>
    
</ul>

My new function works if I leave it in Navigation.php in the Core, but it does not work in my ext. Can anyone tell me what I maybe doing wrong?

“I think there is a world market for maybe five computers.” Thomas Watson, chairman of IBM, 1943

Thanks,

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

I added this code with no success

require_once("Mage/Catalog/Block/Navigation.php");

class 
WDC_navigation extends Mage_Catalog_Block_Navigation  
{

I even made a test function and I still get a blank page.

public function WDC_SayHello()
    
{
        try{
        
return 'hello world';
        
}
        
catch(exception $e)
        
{
            
return $e;
        
}
    }
 
Magento Community Magento Community
Magento Community
Magento Community
 
jamesrowe
Jr. Member
 
Total Posts:  10
Joined:  2009-04-21
 

I have exactly the same problem. I am trying to override Mage_Catalog_Block_Navigation with my own class, so that I can change the functionality in drawItem.

Have followed the example above for the breadcrumbs and it all seems to make logical sense.

Caching is off, and I can see my module at the bottom of the module list in the advanced admin section.

Has anyone solved this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

My works, but for the life of me I can’t remember what I did!

I have a module that over rides the navigation

http://new.midwestsupplies.com/

I am now working on the how the drawitem orders the categories so they all fit nicely on my big menus

I also added a switch that looks up my images for my main categories.

Do you want to see any of my local code?

 
Magento Community Magento Community
Magento Community
Magento Community
 
toete
Jr. Member
 
Total Posts:  21
Joined:  2009-08-23
 

yes plz.
I can’t get it to work.

Anybody found a solution?

thx

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

1) I created a module for my catalog
2) I created a class called Wdc_Catalog_Block_Navagation which extends Mage_Catalog_Block_Navigation
3) I rewrote the way the Menus right on the header, namly, I created each column in a DIV then stacked them and pushed them left

You can see them here

http://new.midwestsupplies.com/

The class was fairly complicated as I counted how many rows in each column, then moved them to the next, of course we could have one end half way so I had to account for that.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

Here is the class that overrides the menus

File Attachments
Navigation.php  (File Size: 15KB - Downloads: 424)
 
Magento Community Magento Community
Magento Community
Magento Community
 
toete
Jr. Member
 
Total Posts:  21
Joined:  2009-08-23
 

I did everything the same way, but it doesn’t work.
Can you show me the app/code/local/Wdc/Catalog/etc/config.xml and app/etc/modulesWdc_Catalog.xml files?
Where did you put your navigation.php??

thx

 
Magento Community Magento Community
Magento Community
Magento Community
 
toete
Jr. Member
 
Total Posts:  21
Joined:  2009-08-23
 

I think it has to do with the fact that I’m rewriting the drawitem method.
You didn’t rewrite a method.

Anybody succeeded in this?

Edit: Even if I don’t rewrite the method but take another methodname, I get the error.
It just says it can’t find the class:
Fatal error: Class ‘Bram_Catalog_Block_Navigation’ not found in /www/app/code/core/Mage/Core/Model/Layout.php on line 462

:s

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

Here is the config

<?xml version="1.0"?>
<config>
  <
modules>
    <
Wdc_Catalog>
      <
version>0.1.0</version>
    </
Wdc_Catalog>
  </
modules>  
  <global>
    <
blocks>
      <
catalog>
        <
rewrite>
          <class>
Wdc_Catalog_Block</class>
        </
rewrite>
      </
catalog>
    </
blocks>
    <
models>
      <
catalog>
        <
rewrite>
          <class>
Wdc_Catalog_Model</class>
        </
rewrite>
      </
catalog>
    </
models>
    <
helpers>
      <
catalog>
        <
rewrite>
          <class>
Wdc_Catalog_Helper</class>
        </
rewrite>
      </
catalog>
    </
helpers>
  </global>
</
config>

here is the module

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

I guess I don’t know what you are trying to accomplish? I completely rewrote the method. Did you look at it?

 
Magento Community Magento Community
Magento Community
Magento Community
 
toete
Jr. Member
 
Total Posts:  21
Joined:  2009-08-23
 

Yes I looked at it.
I saw that you wrote new methods, and u use them in your top.phml file.

I’m trying to accomplisch the same thing as periculi and jamesrowe explain.
To create my own class in the local folder, which extends the navigation class.
I don’t care if I should override the drawitem method or create a new (for ex) mydrawitem method, this doesn’t really matter as long as it doesn’t accept my class.

Here are my files:

app/etc/modules/Bram_All.xml

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

app/code/local/Bram/Catalog/etc/config.xml

<?xml version="1.0"?>
<config>
    <global>
        <
blocks>
            <
catalog>
                <
rewrite>
                    <
navigation>Bram_Catalog_Block_Navigation</navigation>
                </
rewrite>
            </
catalog>
        </
blocks>
    </global>
</
config>

I tried to replace <navigation> with <class> like you did, but that didn’t work either.

app/code/local/Bram/Catalog/Block/Navigation.php

class Bram_Catalog_Block_Navigation extends Mage_Catalog_Block_Navigation
{

    
public function drawItem($category$level=0$last=false)
    
{
        
//Same here as in original method but I'm not gonna put this here or this post will be too long
    
}
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

Here is a different config out of a different module that I made, perhaps that will help

<?xml version="1.0"?>
<config>
  <
modules>
    <
Wdc_QuickOrder>
      <
version>0.1.0</version>
    </
Wdc_QuickOrder>
  </
modules>
  <global>
    <
blocks>
      <
QuickOrder>       
          <class>
Wdc_QuickOrder_Block</class>      
      </
QuickOrder>
    </
blocks>
    <
models>
      <
QuickOrder>       
          <class>
Wdc_QuickOrder_Model</class>       
      </
QuickOrder>
    </
models>
    <
helpers>
      <
QuickOrder>
        <class>
Wdc_QuickOrder_Helper</class>
      </
QuickOrder>
    </
helpers>
  </global>
</
config>

start of block class looks like this

class Wdc_QuickOrder_Block_Loader extends Mage_Core_Block_Abstract
{

I can access anything back in the Core_Block_Abstract

(Turning on Mod looks the same)

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2