Tutorialsplane

Magento Get Product Type


Magento Get Product Type: There are various types of products in Magento and each has some different functions. Each has its own meaning and uses so it is very important to understand them. Here in this tutorial first we are going to describe the types of products in magento and then we will cover how to get the products type using product id or sku etc.


Magento Get Product Type – Magento 2 Product Type

Here are following types of products let us have an overview –

Magento 2 get product type from Product id

You check the product type in magento2 same as in below example. Here is syntax to get the product type from product id in Magento 2.

Magento 2 Check Product Type

$productId = 100;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load($productId);
$productType = $product->getTypeID();
if($productType == 'simple')
{   
  echo "Simple Product";
} 
if($productType == 'configurable')
{   
  echo "Configurable Product";
} 

Magento2 Get Product Type : $product->getTypeID() is used for getting the type id from product object in magento. The above example will give the product type in magento.

Magento 1.x get product type from Product id

Here is syntax to get the product type from product id in Magento 1.x.

Magento Get Product Type

$productId = 1222;
$product = Mage::getModel('catalog/product')->load($productId);
$productType = $product->getTypeID();
if($productType == 'simple')
{   
  echo "Simple Product";
} 
if($productType == 'configurable')
{   
  echo "Configurable Product";
} 

More Example

Let us have another example –

Get product type bundle / Grouped / Virtual / Downloadable

Here is syntax to get the bundle / Grouped / Virtual / Downloadable

Magento get product type bundle / Grouped / Virtual / Downloadable:

/****** for magento 1.x*****/
//$product = Mage::getModel('catalog/product')->load($productId);

/****** for magento 2.x*****/
$productId = 100;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load($productId);
$productType = $product->getTypeID();
if($productType == 'bundle')
{   
  echo "Gundle Product";
} 
if($productType == 'grouped')
{   
  echo "Grouped Product";
} 
if($productType == 'Downloadable')
{   
  echo "Downloadable Product";
} 
if($productType == 'virtual')
{   
  echo "Virtual Product";
} 

Thus using the above example you can get product type Details In Magento Version 2.x And 1.x.