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...
This question is related to
php
magento
magento-1.7
$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();
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();
<?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
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
This worked for me-
if(Mage::registry('current_product')->getTypeId() == 'simple' ) {
Use getTypeId()
Item collection.
$_item->product_type;
$_item->getId()
Product :
$product->getTypeId();
$product->getId()
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>";
Source: Stackoverflow.com