Get Product details Using Product Name in Magento

Get Product details Using Product Name in Magento

This post is how to get product id using product name. This code will show you list of all product id related name of your product name.


NOTE : This code is not ideal way to get product id. Do you have any better way than please share heat with us, we will appreciate it.

// add name of product
	$products_name = 'over Products name'; 

	// get model product's 
	$product_obj = Mage::getModel('catalog/product');

	// get collection of products
	$product_collection = $product_obj->getCollection(); 

	/ get all product using foreach loop 
	foreach ($product_collection as $products) 
	{                  
	    $product_obj->load( $products->getId() );
	    $get_product_anme = $product_obj->getName();
	    if( strcmp( $get_product_anme , $products_name ) == 0 )
	    {
	        // Get id of product's
	    	$products_id[] = $products->getId();
	    }
	}

	// show all product id related to name
	echo "<pre>";
	print_r($products_id);
	echo "</pre>";

Use this code for Get Product details Using Product Id

$product_id = "17"; // add youtr poduct id

$product_obj = Mage::getModel('catalog/product');

// Enter your Product Id in $product_id
$_products = $product_obj->load($product_id); 

// show all detail of Product's
echo "<pre>";
print_r($_products); // all Product's detail
echo "</pre>";

// get Product's name
echo $_products->getName();

//get product's short description
echo $_products->getShortDescription();

//get Product's Long Description
echo $_products->getDescription();

//get Product's Regular Price
echo $_products->getPrice();

//get Product's special Price
echo $_product->getSpecialPrice();

//get Product's Url
echo $_products->getProductUrl();

//get Product's image Url
echo $_products->getImageUrl(); 

//get Product's small image url
echo $_products->getSmallImageUrl(); 

//get Product's thumbnail image url   
echo $_products->getThumbnailUrl(); 

Leave a Comment

Your email address will not be published. Required fields are marked *

5  +  3  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US