How do I get categories for a product in Magento

后端 未结 6 2123
情书的邮戳
情书的邮戳 2021-01-31 16:12

I\'m trying to add product_type to my Magento Google Base output based on the product\'s categories, but I seem to be unable to. I have the following code:

// Ge         


        
6条回答
  •  孤独总比滥情好
    2021-01-31 16:22

    This code work in phtml file in Magento 2

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product
    $categories = $product->getCategoryIds(); /*will return category ids array*/  
    

提交回复
热议问题