I am working on my custom module where I added a button on Configurable products. The Content I was showing through button was by getting the Parent Category ID.

The main issue I am facing is that when I open a product by going through the path(mean Men>Tops>Jackets) it works. But When I directly open the product from HOME PAGE it gives me the error.

enter image description here

In my Block file, I am using these functions

public function getCurrentCategory()

            return $this->_registry->registry('current_category');

     public function getCurrentProduct()

        return $this->_registry->registry('current_product');

    public function getCollection($id){
        return $this->_Collection->create()

    public function getDisplay($id){
        return $this->_Collection->create()

For my phtml file, I am using

$cat = $block->getCurrentProduct()->getCategory(); 


         foreach ($cat->getParentCategories() as $parent) {
            $parentId[]= $parent->getId();

        $sizeColl = $block->getDisplay($parentId[0]);
            $display = $sizeColl[0]['display'];

            if($display == 'page'): 
                        foreach ($Charts as $chart) {
                            echo $chart['content'];

            else: ?>

Can Anyone help me out with this or suggest me with a better option. Because I need to target Main Parent Category to do my work. Thanks in advance

  • please include post error code not its image – fmsthird May 9 '19 at 0:21
  • I have added the image – Zeeshan May 9 '19 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.