Thursday, September 17, 2015

Magento - Product ID from Product Name.

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

No comments :

Post a Comment