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 –
-
Simple products in Magento :
This is most common used product in magento. Simple products are basically used for single item without any selectable variations. Example – Chair, Table
-
Grouped products In Magento :
Magnto grouped products are combination of simple products. If in the above example Chair & Tables are combined and sell together it will come in grouped products type.
-
Configurable Products in Magento :
Configurable Products are products which can be configured on the basis of various parameters. For example – Tee Shirt in Different Colors and Sizes.
-
Virtual Products In Magento :
Virtual Products in magento are products which does not exist in real ie. they are not touchable. Shipping method is not used for these products because there is nothing to ship in real. The simple example can be – Reservation for movie ticket.
-
Bundle Products in Magento :
Bundle products are basically bundle of simple products which are sold together not separately. Example – Mobile which is sold with accessories such as charger & headphone.
-
Downloadable products :
Products which can be downloaded online. These products also does not need shipping method as they are downloaded directly.
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.
Advertisements