Load category, but only with limited data to build a Breadcrumb

by zerokelvin   Last Updated November 09, 2018 01:09 AM

Based on the helper catalog there is a function that returns a path for the breadcrumb to be displayed in Magento when viewing a Product.

I want to enhance this method to return the full path of the categories back to me.

Current implementation:

 if ($this->getProduct()) {
                $path['product'] = array('label'=>$this->getProduct()->getName());
        $this->_categoryPath = $path;

Here I want to append a process that load the categories of the product via getCategoryIds(), which is available trough the getProduct() method.

I'd like to load a conditional collection, that only loads the respective ID of the categories but only the following data:

  • url
  • name
  • title
  • my_custom_eav_param

I assume something like:

        if ($product = $this->getProduct()) {
            $cats = $product->getCategoryIds();
            foreach ($cats as $category_id) {
                $attributesToSelect = [''];
                $_cat = Mage::getModel('catalog/category')
                    ->addAttributeToFilter(['name', 'id', 'url', 'description'])
                var_dump($_cat); die;
            $path['product'] = array('label'=>$this->getProduct()->getName());

        $this->_categoryPath = $path;

but this does not work. How can I specify what entities are loaded in order to keep load to DB as low as possible for this requests? To load the whole category all the time is a lot of traffic, or can it be ignored completely?

Related Questions

New Category Page Showing 404

Updated April 27, 2017 15:09 PM

Adding Category Attribute to Select

Updated October 24, 2017 11:09 AM

I can not manage the categories of Magento

Updated February 16, 2017 15:09 PM