1

I have one query regarding category id.I need to include category id, in category list page. Currently it should be like this :

http://magento2.shelltag.com/women/bags/backpacks

I want to show like this :

http://magento2.shelltag.com/women/bags/backpacks-6

How can it be achieved?

enter image description here

is this is the possible solution?

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->get('Magento\Framework\Registry')->registry(‌​'current_product'); $categories = $product->getCategoryIds(); /*will return category ids array*/ foreach($categories as $category){ $cat = $objectManager->create('Magento\Catalog\Model\Category')->lo‌​ad($category); echo $cat->getId(); } ?> 

or in which file i need to make changes?

  • Is this is the possible solution? <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); $categories = $product->getCategoryIds(); /*will return category ids array*/ foreach($categories as $category){ $cat = $objectManager->create('Magento\Catalog\Model\Category')->load($category); echo $cat->getId(); } ?> or in which file i need to make changes? – Yogesh Raghav Mar 3 '17 at 6:30
  • do i need to call observer class or how to do it? – Yogesh Raghav Mar 6 '17 at 6:16
  • any suggestions please? – Yogesh Raghav Mar 6 '17 at 7:25
  • any idea regarding the same? – Yogesh Raghav May 19 '17 at 5:34

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.