0

I have a product bag in home->products->men->handbag category path .I want hangbag category url in product detail page

1
  • product view page url get in mini-cart ??? Commented May 5, 2020 at 4:31

1 Answer 1

0

Please check below code.

<?php
namespace VENDOR\EXTENSION\Block;
class Caturl extends \Magento\Framework\View\Element\Template
{
        protected $_registry;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,        
        \Magento\Framework\Registry $registry,
        array $data = []
    )
    {        
        $this->_registry = $registry;
        parent::__construct($context, $data);
    }

    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }

    public function getCurrentCategory()
    {        
        return $this->_registry->registry('current_category');
    }        
}
?>

And use it with below code in .phtml.

// print for current category
$currentCategory = $block->getCurrentCategory();
echo $currentCategory->getName() . '<br />';
echo $currentCategory->getUrl() . '<br />';

Happy Coding.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.