Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

magento getting product type from product sku

How can i get the product type(simplee,configurable/grouped ...) using product sku or id, i have loaded product collection and from that trying to prict type by

$_product->getTypeId()

But its not printing the product type. Please help me

Thanks

like image 775
Elamurugan Avatar asked Mar 03 '11 07:03

Elamurugan


People also ask

How do you find the product type?

To get the product type you will use get_type() method. To check the product type inside an IF statement you will use is_type() method.

How do I get product SKU using product ID in Magento 2?

Step 1: Declare the command to get product ID or SKU You will use a block class of the module Mageplaza_HelloWorld , then possibly inject the object of \Magento\Catalog\Model\ProductRepository class in the constructor of the module's block class.

What is product type in Magento 2?

By default, Magento 2 supports 6 product types. These are: Simple, Groped, Configurable, Virtual, Bundle and Downloadable products. To add a new product in a Magento 2 store, go to Products - Catalog - Add Product.


2 Answers

I think $_product->getTypeId() should work. If it doesn't then try $_product->getResource()->getTypeId()

like image 88
Mukesh Chapagain Avatar answered Sep 21 '22 03:09

Mukesh Chapagain


I got product type following way in phtml file

$product=Mage::getModel('catalog/product')->load($product_id);
$productType=$product->getTypeID();
//Simple Product    
if($productType == 'simple')
{   
  echo "Simple Product";
}                           
//Configurable Product
if($productType == 'configurable')
{   
  echo "Configurable Product";
}
like image 22
Mukesh Avatar answered Sep 18 '22 03:09

Mukesh