Magento 2 check if product type is simple
Magento 2 check if product type is simple– We sometimes need to check the product type is “simple” or not. We can check get product type simple using product type id property. Here in this tutorial, we are going to explain how you can check whether a product is simple or not in Magento 2.
Magento 2 check if product type is simple Example
You can check if product type is simple 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\Simple::TYPE_CODE) { echo "Product is simple"; } |
$productType will give you “simple” which means product type is simple.
You can directly compare the type simply below
if($productType == "simple") { echo "Product is simple"; }
You can check the product type using any of the above method in magento 2.
Advertisements