Home » Magento, Magento 212 February 2016

Magento 2: Get Current Category & Current Product

This article shows how we can get current category and current product data in Magento 2.

Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Framework\Registry class in the constructor of my module’s block class.

app/code/Chapagain/HelloWorld/Block/HelloWorld.php

Printing current category and current product in any template (.phtml) file

Using Object Manager

For more, see:

MAGENTO_ROOT/vendor/magento/module-catalog/Model/Product.php
MAGENTO_ROOT/vendor/magento/module-catalog/Model/Category.php

Hope this helps. Thanks.

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • minh hiep nguyen

    thank you

  • Liam Fielding

    You shouldn’t be using the object manager directly.

  • Attique Rehman

    Nice and simple