2

I need to display only first level category inside product url. If visitors browse and click product inside categorylevel1/categorylevel2.html, I need to show domain.com/categorylevel1/product.html and NOT domain.com/categorylevel1/categorylevel2/product.html

Is there any easy way to do that?

  • Did you find a solution? Does the answer provided work? I'm looking for the same funcionality. – Artur Rain Oct 27 '15 at 12:09
  • I didn't find any solution, but I didn't made any further research, I just simple didn't use second level categories but I went with only one level structure. – JohnyFree Oct 27 '15 at 20:41
0

You can get product url path form Url Rewrite collection

$path = Mage::getResourceModel('core/url_rewrite')->getRequestPathByIdPath('product/{product_id}/{category_id}', Mage::app()->getStore());

Parameter

{product_id} => your product Id 
{category_id} => your first level category id.

Now you can get the product Url like

Mage::getBaseUrl().$path

or

$this->getUrl('', array('_direct' => $path));

Note: product must be assign with both category (i.e., first level and second level category)

I have refer this link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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