Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 837
Padmanathan J Avatar asked May 02 '13 06:05

Padmanathan J


People also ask

How do you find the product type?

To get the product type you will use get_type() method. To check the product type inside an IF statement you will use is_type() method.

What are Magento product types?

By default, Magento 2 supports 6 product types. These are: Simple, Groped, Configurable, Virtual, Bundle and Downloadable products.


2 Answers

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();
like image 140
liyakat Avatar answered Oct 05 '22 12:10

liyakat


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

like image 6
Bakk László Avatar answered Oct 05 '22 11:10

Bakk László