Magento 2: Get all Categories of any/current Product

This article shows how we can get list of all categories from current product or any particular product as well. Both ways (Dependency Injection & Object Manager way) are shown below: Using Dependency Injection (DI) Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory, \Magento\Catalog\Model\ProductRepository and \Magento\Framework\Registry classes … Read more

Magento 2: Get Related, UpSell & CrossSell Products

This article shows how we can get related products, upsell products, and cross-sell products in Magento 2. Check the product relation tables in MySQL database mysql> SELECT * FROM `catalog_product_link_type`; +————–+————+ | link_type_id | code | +————–+————+ | 1 | relation | | 3 | super | | 4 | up_sell | | 5 | … Read more

Magento: How to set and get registry?

Registry means registering or creating a new variable which is to be used later on in the project/code. The registry variable acts as a global variable which can be used anywhere. Here are the functions to register, unregister and fetch a registry variable. register(): register a variable unregister(): unregister a variable registry(‘VARIABLE_NAME’): fetch registry variable … Read more