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')
                    ->getCollection()
                    ->addAttributeToSelect('*')
                    ->addAttributeToFilter(['name', 'id', 'url', 'description'])
                    ->load()
                    ->getSelect()->__toString();
                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


Updated July 27, 2018 11:09 AM

Updated April 27, 2017 15:09 PM

Updated July 24, 2017 07:09 AM

Updated October 24, 2017 11:09 AM

Updated February 16, 2017 15:09 PM