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
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.
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.
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.
I think $_product->getTypeId()
should work. If it doesn't then try $_product->getResource()->getTypeId()
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";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With