Get product id and product type in magento? Get product id and product type in magento? php php

Get product id and product type in magento?


Try below code to get currently loaded product id:

$product_id = $this->getProduct()->getId();

When you don’t have access to $this, you can use Magento registry:

$product_id = Mage::registry('current_product')->getId();

Also for product type i think

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


<?php if( $_product->getTypeId() == 'simple' ): ?>//your code for simple products only<?php endif; ?><?php if( $_product->getTypeId() == 'grouped' ): ?>//your code for grouped products only<?php endif; ?>

So on.It works! Magento 1.6.1, place in the view.phtml


you can get all product information from following code

$product_id=6//Suppose$_product=Mage::getModel('catalog/product')->load($product_id);    $product_data["id"]=$_product->getId();    $product_data["name"]=$_product->getName();    $product_data["short_description"]=$_product->getShortDescription();    $product_data["description"]=$_product->getDescription();    $product_data["price"]=$_product->getPrice();    $product_data["special price"]=$_product->getFinalPrice();    $product_data["image"]=$_product->getThumbnailUrl();    $product_data["model"]=$_product->getSku();    $product_data["color"]=$_product->getAttributeText('color'); //get cusom attribute value    $storeId = Mage::app()->getStore()->getId();    $summaryData = Mage::getModel('review/review_summary')->setStoreId($storeId)  ->load($_product->getId());    $product_data["rating"]=($summaryData['rating_summary']*5)/100;    $product_data["shipping"]=Mage::getStoreConfig('carriers/flatrate/price');    if($_product->isSalable() ==1)        $product_data["in_stock"]=1;    else        $product_data["in_stock"]=0;    echo "<pre>";    print_r($product_data);    //echo "</pre>";