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)
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,
'product_image_url'=>$productUrl,
);
Hopefully someone will save time on this.
-
how to get product complete url in custom module observerinrsaurabh– inrsaurabh2017年10月16日 13:44:05 +00:00Commented Oct 16, 2017 at 13:44
Explore related questions
See similar questions with these tags.
$_productin your code?