maximus 69
maximus 69

Reputation: 1458

Magento getProductUrl() gives different product’s URL

I'm working on an ajax auto suggest script and have encountered an issue where the product URL's being outputted are false (meaning that they point to the product but the category path is not mentioned).

This particular code snippet would get the job done (found on the magento forum) but am encountering an error in the following location

$_categories = $_product->getCategoryIds();
$_category = Mage::getModel('catalog/category')->load($_categories[0]);  
$url = $this->getUrl($_category->getUrlPath()).basename($_product->getProductUrl()); 

I am actually inside a class which is extending from Mage_Core_Controller_Front_Action. Could anyone tell me what should come in place of $this in order for me to get the proper URL?

Upvotes: 1

Views: 3193

Answers (1)

Mukesh Chapagain
Mukesh Chapagain

Reputation: 25968

Try putting Mage instead of $this

Mage::getUrl(...)

Upvotes: 2

Related Questions