user3401141
user3401141

Reputation: 135

Product URL Rewrite troubles in Magento 1.7

My Magento 1.7 installation has a weird problem, All the Products URLs have Category key in them, but the Up-Sell products (on a product's details page) are showing URLs with Category key missing. URLs for related products are ok.

My Magento Settings are as shown below ::

My Products are ::

  1. located 2 category level deep, means cat1/cat2/product
  2. all product URLs are in this format :: site_url/cat2/product_key
  3. One product is appearing under multiple categories

Any help is highly solicited.

Upvotes: 0

Views: 281

Answers (2)

TonkBerlin
TonkBerlin

Reputation: 191

Better use this code where $_categories is an if-function

$d = $_link->getData();
$id = $d['entity_id'];
$_product = Mage::getModel('catalog/product')->load($id);
$_categories = $_product->getCategoryIds();
if($_categories) {
    $_category = Mage::getModel('catalog/category')->load($_categories[0]);
    $cat_url = str_replace(".html","",$_category->getUrlPath());
    $_url = Mage::getUrl($cat_url).basename($_link->getProductUrl());
}

And for output urls:

<?php if ($_categories) { echo $_url; }; ?>

Otherwise system.log counts errors when articles have no categories.

Upvotes: 0

user3401141
user3401141

Reputation: 135

I have found a solution to Include Category Name in Upsell Product's URL ...

I had to modify the file at my_theme/template/catalog/product/list/upsell.phtml

And around line number 51, just after the line :

<?php if($_link=$this->getIterableItem()):

I adde the following lines ::

$d = $_link->getData();
$id = $d['entity_id'];
$_product = Mage::getModel('catalog/product')->load($id);
$_categories = $_product->getCategoryIds();
$_category = Mage::getModel('catalog/category')->load($_categories[0]); 
$cat_url = str_replace(".html","",$_category->getUrlPath());
$_url = Mage::getUrl($cat_url).basename($_link->getProductUrl()); 

And Used the $_url variable as product's URL. This worked perfectly.

Upvotes: 1

Related Questions