简体   繁体   中英

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 ::

  • "Use Categories Path for Product URLs" => YES
  • "Create Permanent Redirect for URLs if URL Key Changed" => No
  • "Use Parent Category Path for Category URLs" => No

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM