I'm using this in my controller file to get the current product URL and insert it into database.

Tried this solution, but it works partially: instead of http://formodulecheck.dev/media/catalog/product/p/r/product.jpg it's returning http://formodulecheck.dev/index.php/catalog/product/view/

$product = Mage::getModel('catalog/product')->load($id);
$productUrl = $product->getProductUrl();

Version 2 - Also tried this:

$_product = Mage::getModel('catalog/product')->load($product_id); 
$product_url=Mage::helper('catalog/image')->init($product, 'thumbnail');
echo $product_url." HERE IS THE PRODUCT URL";

And getting this error:

Fatal error: Call to a member function getData() on null in app\code\core\Mage\Catalog\Helper\Image.php on line 166

How can I fix this? (Thanks for the help)

  • Can you please add your full form code? what is the value for $_product in your code?
    – John
    Commented Jun 8, 2017 at 3:38

1 Answer 1


After spending hours and trying dozens of possible solutions, I found one that worked for me in this tiny article.

$product = Mage::getModel('catalog/product')->load($product_id);
$productMediaConfig = Mage::getModel('catalog/product_media_config');
$productUrl = $productMediaConfig->getMediaUrl($product->getThumbnail());

$connectionresource = Mage::getSingleton('core/resource');
$connectionWrite = $connectionresource->getConnection('core_write');
$table = 'cpstest_productcomment_cps';
$data = array(
    'id' => NULL,
    'productcomment_increment_id' => $product_id,
    'customer_email' => $user_email,
    'name'    =>  $user_name,
    'comment_status' => 'Not Approved',
    'comment_date' => $comment_date,
    'comment_txt' => $user_comment_notags,
    'product_name' => $product_name,

Hopefully someone will save time on this.

  • how to get product complete url in custom module observer
    – inrsaurabh
    Commented Oct 16, 2017 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.