magento getting product type from product sku

2019-06-15 06:43发布

问题:

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

回答1:

I think $_product->getTypeId() should work. If it doesn't then try $_product->getResource()->getTypeId()



回答2:

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";
}


回答3:

did you know that you can see whats inside an object by just performing print_r($_product->getData())



回答4:

Here's another tip.

If you are iterating though Cart Items, then use the getProductType() for the product type information. For example -

foreach( $cartItems as $item ){
    if($item->getProductType() == "configurable") {