1
votes

I've got a problem with my Magento installation. I'm using the upsell feature to provide some more interesting products. The output works so far but I've got a big problem with the product url.

The url links to my-shop.com/product.html and not to my-shop.com/category-1/category-2/product.html. That's bad because I'm calling a special sidebar navigation for each top category. And so nothing is shown...

I'm using the standard upsell output:

<a href="<?php echo $_link->getProductUrl() ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_link, 'small_image')->resize(115) ?>" width="115" height="115" alt="<?php echo $this->htmlEscape($_link->getName()) ?>" title="<?php echo $this->htmlEscape($_link->getName()) ?>" /></a> <h3 class="product-name"><a href="<?php echo $_link->getProductUrl() ?>"><?php echo $this->htmlEscape($_link->getName()) ?></a></h3> <?php echo $this->getReviewsSummaryHtml($_link) ?> <?php echo $this->getPriceHtml($_link, true, '-upsell') ?>

(I can't post the whole code, the editor will delete most of it)

I've tried it with $_link->getProductPath(), but the output was empty.

I also checked the settings in System->Config->Catalog->Search Engine Optimization. Use Categories Path for Product URLs set to Yes.

Does anybody has an idea how to get the full path url for the products?

Thank you for your help.

2

2 Answers

1
votes

You may use the below logic to get the product url. Update the variables accordingly.

<?php
    $_prodcats = $_product->getCategoryIds();
    $_cat = Mage::getModel('catalog/category')->load($_prodcats[0]);
    $produrl = $this->helper('catalog/output')->productAttribute($_product, $_product->getRequestPath(), 'request_path') ;
    if($this->getRequest()->getModuleName() == 'catalogsearch') {
        $produrl = '/'. basename($_cat->getUrl()) .'/' . basename($_product->getProductUrl()) ;
    }
?>
1
votes

I found a solution on the web which works for 1.9.2.1. The upsell products become a link with category link.

$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 then use this url

<a href="<?php echo $_url; ?>">Link</a>

I still have the problem that the created sitemap.xml just added

www.website.com/product instead of

www.website.com/category/product

even if "Use Categories Path for Product URLs" is set to YES