In Magento eCommerce while working with catalog model, There arise the need to fetch product details from product id.
We can get all product details if we have product id.
But sometimes we only have product name, so we need to get product id for getting product details.
I am listing here both the method.
1) Product details from Product ID.
<?php $model = Mage::getModel('catalog/product') //getting product model $_product = $model->load($productid); //getting product object for particular product id echo $_product->getShortDescription(); //product's short description echo $_product->getDescription(); // product's long description echo $_product->getName(); //product name echo $_product->getPrice(); //product's regular Price echo $_product->getSpecialPrice(); //product's special Price echo $_product->getProductUrl(); //product url echo $_product->getImageUrl(); //product's image url echo $_product->getSmallImageUrl(); //product's small image url echo $_product->getThumbnailUrl(); //product's thumbnail image url ?>
2) Product ID from Product Name
This is little bit complex. (If anybody has better way please post here)
<?php $product_name = 'Test Product'; //product name $model = Mage::getModel('catalog/product') //getting product model $collection = $model->getCollection(); //products collection foreach ($collection as $product) //loop for getting products { $model->load($product->getId()); $pname = $model->getName(); if(strcmp($pname,$product_name)==0) { $id = $product->getId(); } } echo 'Required ID->'.$id; //id of product ?>
May i know where the function getProductName() exists ? and How to get the category of each product? Please help
Thank you
I have not mentioned getProductName anywhere in the post, let me know your question exactly.
Please check this post for fetching product categories :
Product Category
I also have same question above 🙁
May I know the question ?
$model = Mage::getModel(‘catalog/product’) //getting product model
//add this product id to load particular product
$productid = 1; // your product id
$_product = $model->load($productid);
Thanks for this script
Thanks a lot for the wonderful tuts.
Cheers
hey, i have create popup window in show view perticuler product description but every time, i have set prouct id in href but when i access this id so they can get every time first id so what proble in my code
I am not able to understand your query, could you please paste the url/code here ?
Thank you for this post, i was working with addon and i was looking the way to get products id and this just gets solved.
I’m glad it was helpful
getId();
$_product = $model->load($productid);
echo $_product->getName() // get Product Name
echo $_product->getAttributeText(‘manufacturer’) // get Brand name
?>