如何获得产品类型?


12

我正在Magento 2中创建一个新模块。我尝试在phtml文件中获取产品信息。我已经成功获取了entity_id产品名称信息。但是当我得到产品类型信息时,就出错了。使用以下代码。

$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

Answers:



0

尝试这个 :

$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
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.