1

I need to ensure a link is added to all categories (except the current one) in my breadcrumbs. In my $crumbs variable provided by page > html > breadcrumbs is the following var_dump:

array (size=3)
  'home' => 
    array (size=6)
      'label' => string 'Home' (length=4)
      'title' => string 'Go to Home Page' (length=15)
      'link' => string 'http://dev.example.co.uk/' (length=32)
      'first' => boolean true
      'last' => null
      'readonly' => null
  'category270' => 
    array (size=6)
      'label' => string 'Batteries By Use' (length=16)
      'link' => null
      'title' => null
      'first' => null
      'last' => null
      'readonly' => null
  'category321' => 
    array (size=6)
      'label' => string 'Digital Camera Batteries' (length=24)
      'link' => string '' (length=0)
      'title' => null
      'first' => null
      'last' => boolean true
      'readonly' => null

As you can see, there should be a link variable on category270 but I have no idea how to get this to work. The core doesn't provide much guidance on adding these links to the breadcrumbs.

Obviously, I'll need to track down the area where this breadcrumb is added, but with regard to categories, I have no idea where to look.

1

I've solved this issue; and it appears to be a bug with the breadcrumbs generation process.

Hopefully this is rectified on 1.9, but as I'm working on 1.8, I had to fix is manually.

Within Mage > Catalog > Helper > Data.php, on line 109, you will see the following code:

$path['category'.$categoryId] = array(
    'label' => $categories[$categoryId]->getName(),
    'link' => $this->_isCategoryLink($categoryId) ? $categories[$categoryId]->getUrl() : ''
);

This needs to change to:

$path['category'.$categoryId] = array(
    'label' => $categories[$categoryId]->getName(),
    'link' => $this->_isCategoryLink($categoryId) ? '/' . $categories[$categoryId]->getUrlPath() : ''
);

For some reason, at this stage, the $categories[$categoryId]->getUrl() returns a null value, so the category URLs weren't being linked correctly.

I changed this to $categories[$categoryId]->getUrlPath() to generate a path instead of a fully qualified URL, and prepended a / to it, forcing it to work from root.

This now works successfully.

NB.
If someone could confirm whether or not this bug exists in 1.9, that would be awesome.

  • Still there for 1.9.x :-( – lrkwz Jul 30 '15 at 14:54

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.