Reputation: 135
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 ::
Any help is highly solicited.
Upvotes: 0
Views: 281
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
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