Shafeeque S
Shafeeque S

Reputation: 2613

In Magento how can I get the product type from product id in list.phtml?

How can I get the product type from product id in product list page? I'm using the code

$product_id = $this->getProduct()->getId();
$product = Mage::getModel('catalog/product')->load($product_id); 
$productType = $product->getTypeId();

but I'm getting the error "Fatal error: Call to a member function getId() on a non-object in XXXX". How can I resolve this?

Upvotes: 1

Views: 1935

Answers (1)

Pankaj Pareek
Pankaj Pareek

Reputation: 3836

On Product page, we already have $_product object loaded. so instead of loading product again.

You can use the below code:

echo $_product->getTypeId()

Upvotes: 2

Related Questions