Get product id and product type in magento?
Asked Answered
A

8

23

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

Alphonsa answered 2/5, 2013 at 6:40 Comment(0)
S
60

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();
Schwitzer answered 2/5, 2013 at 6:49 Comment(11)
Hi @liyakat. I got it my product id. i need also get product type. please help mei am trying $_product->getResource()->getTypeId() this way but i got Fatal error: Call to a member function getCategoryIds() on a non-objectAlphonsa
This is my demo url demo.osiztechnologies.com/printing/index.php/folders/…Alphonsa
Thanks for your answers. my last question i am creating custom option input type using config.xml file. admin panel custom option tab working good. it show web2print option. but i am save that option type. any possible to get input type in magento please guide me..Alphonsa
I got product id and product type. last question only please help meAlphonsa
i am not getting you clear about custom option ? is it from admin side or front end to get from end user ? will you please explain moreSchwitzer
custom option in admin side. please see this url demo.osiztechnologies.com/printing/index.php/folders/…. My task is add web2print tool in magento. but the tool in core php so i am add one menu in admin panel called web2print also i can go to admin page catalog-> managecatelog->customoption. i am also creating new input type like(File/text). my type name called web2printAlphonsa
This is my ref URl for create custom options magento.ikantam.com/qa/custom-input-types-custom-optionsAlphonsa
Hey @Schwitzer , how can i get child id from product id ?Lubet
Thanks! You save my day! I had a lot of problems with attributes in files different from view.phtml... with your Mage::registry now i have solved all problems!Melisma
@Schwitzer the function name is getTypeId() not getTypeID(). You also have and quotes in your second code block.Emulsifier
@Schwitzer How can i get add to cart button in my CMS page for relevant products?Selfgratification
D
6
<?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

Deafmute answered 4/8, 2013 at 5:31 Comment(0)
P
3

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>";
Phosphoprotein answered 2/5, 2013 at 6:55 Comment(2)
I want how can i get input type name or id. guide meAlphonsa
This answered the question I have when I came here so upvoted!Mohl
K
2

Item collection.

$_item->product_type;
$_item->getId()

Product :

$product->getTypeId();
$product->getId()
Kenleigh answered 22/11, 2014 at 5:56 Comment(0)
C
1

You can also try this..

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

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

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

Contexture answered 27/12, 2013 at 13:37 Comment(0)
K
0

IN MAGENTO query in the database and fetch the result like. product id, product name and manufracturer with out using the product flat table use the eav catalog_product_entity and its attribute table product_id product_name manufacturer 1 | PRODUCTA | NOKIA 2 | PRODUCTB | SAMSUNG

Klepht answered 3/10, 2013 at 13:56 Comment(0)
F
0

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

above code not working for me. its throw exception;

This is working for me for get product details.

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

So use for for product type.

$productType = $_product->getTypeId();

Food answered 31/5, 2016 at 13:12 Comment(0)
M
0

This worked for me-

if(Mage::registry('current_product')->getTypeId() == 'simple' ) {

Use getTypeId()

Mcclish answered 12/7, 2017 at 16:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.