Elamurugan
Elamurugan

Reputation: 3214

magento getting product type from product sku

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

Upvotes: 12

Views: 27790

Answers (4)

Mukesh Chapagain
Mukesh Chapagain

Reputation: 25958

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

Upvotes: 13

Mukesh
Mukesh

Reputation: 7778

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

Upvotes: 8

GregC
GregC

Reputation: 271

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") {

Upvotes: 1

Anton S
Anton S

Reputation: 12750

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

Upvotes: 2

Related Questions