Magento 2 check if product type is bundle


Magento 2 check if product type is bundle– We sometimes need to check the product type is “bundle” or not. We can check get product type bunlde using product type id property. Here in this tutorial, we are going to explain how you can check whether a product is bundle or not in Magento 2.


Magento 2 check if product type is bundle Example

Magento 2 check if product type is bundle

You can check if product type is bundle or not simply as below-

Example:

$productId = 199;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load($productId);
$productType = $product->getTypeID();

if($productType == \Magento\ConfigurableProduct\Model\Product\Type\Bundle::TYPE_CODE)
{   
  echo "Product is Bundle";
} 

$productType will give you “bundle” which means product type is bundle.

You can directly compare the type simply below

if($productType == "bundle")
{   
  echo "Product is bundle";
} 

You can check the product type using any of the above method in magento 2.


Advertisements

Add Comment

📖 Read More