8

I am creating new module in magento2.I try to get product information in phtml file. I have get successfully entity_id and product name information. but when i get product type information is getting wrong. Following code used.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); //get current product

echo $product->getId() . '<br/>';
echo $product->getName() . '<br/>';
echo $product->getProductType() . '<br/>'; //getting wrong product type
29

You should try

$product->getTypeId()

It will return configurable, simple, grouped, virtual or downloadable

  • Does it work for collection and product object both? – Tejas Vyas Apr 16 '18 at 6:40
  • it also returns other types like grouped , virtual , ... – CompactCode May 20 '18 at 6:07
0

Try this :

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); //get current product

$product->getTypeId() // it will return the product type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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