Tuesday, August 7, 2012

Magento: Tag Url Rewrite and Generate

Rewrite the tag/tag model and override the getTaggedProductsUrl() with the following code
public function getTaggedProductsUrl()
{
    $fullTargetPath = Mage::getUrl('tag/product/list', array(
        'tagId' => $this->getTagId(),
        '_nosid' => true
    ));
    $targetPath = substr($fullTargetPath, strlen(Mage::getBaseUrl()));
    $rewriteUrl = Mage::getModel('core/url_rewrite')->loadByIdPath($targetPath);
    if ($rewriteUrl->getId()) {
        return $rewriteUrl->getRequestPath();
    }
    return $fullTargetPath;
}

No comments:

Post a Comment