0

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
  • Can you please add your full form code? what is the value for $_product in your code?
    – John
    Jun 8, 2017 at 3:38

1 Answer 1

0

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.

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

Your Answer

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

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