Get product id and product type in magento?

I am creating magento store. I am beginner in magento. I want to get product id and product input type in my phtml file is this possible? please guide me..

I am trying to this way to get product type. but its not working for me

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

Please guide me...

Solutions

<?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

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();

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>";
Tags: PHP / Magento / Magento 1.7

Similar questions

How to set Sku Type & Price Type of Bundle Product programmatically in Magento?
I have added a Bundled Product in Magento programmatically, using all the options / properties of the Simple Product & the use of the 3 methods specifically for Bundle Options:- The result is that the newly added Bundle Product shows just fine in the Admin section, with some default values taken of the following properties:- However, this Bundl...
Error: Unsupported product type "type"
Using Magento EE 1.13.0.1 when saving or duplicating some products (but not all) we get the error: Unsupported product type "type". Stack trace: And the product's entry in catalog_product_entity with type_id set to "Simple" Has anyone seen this before? We're not sure what makes this product special, or why it's doing this.
New product type based on bundle - price type not saving
I've created new product type extended from bundle product. Every thing works fine, except "price_type" "sku_type" attributes. I want to save the price_type as fixed "it's value is 1", also for the sku_type. But it's not saving this value, In other words those attributes not saving at all, not fixed nor dynamic. Where should I look for the solution...
magento 2 Incompatible argument type: Required type: \Magento\Framework\Registry
i am getting this error while compiling,when i add dependency injection then getting other error like,filefactory if this solved then getting customerfactory. Actually i want to do custom code in my controller when user click - Actually i need customer id in my custom controller.
Magento setup:upgrade fails with "Element 'type': Character content other than whitespace is not allowed because the content type is 'element-only'."
We recently purchased software that runs as an extension for Magento 2. We purchased a brand new VPS setup, and turned it over to them for installation. They completed the installation and got their product working, and turned the site/server back over to us, and everything seemed to be working fine. I've been attempting to install some additional ...
Compilation error : Incompatible argument type: Required type: \\Magento\\Config\\Model\\Config\\Reader\\Source\\Deployed\\DocumentRoot
Compilation error: Code of the /app/app/code/MyCompany/Sitemap/Model/Sitemap.php file: I do not understand the error, I check the parameters of the construct method, everything seems ok. Any idea?

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.