/** * Adds url_path property for non-root category - to ensure that url path is not empty. * * Sometimes attribute 'url_path' can be empty, because url_path hasn't been generated yet, * in this case category is loaded with empty url_path and we should generate it manually. * * @param Varien_Object $category * @return void */ protected function _addCategoryUrlPath($category) { if (!$category instanceof Varien_Object || $category->getUrlPath()) { return; } // This routine is not intended to be used with root categories, // but handle 'em gracefully - ensure them to have empty path. if ($category->getLevel() <= 1) { $category->setUrlPath(''); return; } if (self::$_categoryForUrlPath === null) { self::$_categoryForUrlPath = Mage::getModel('catalog/category'); } // Generate url_path $urlPath = self::$_categoryForUrlPath->setData($category->getData())->getUrlPath(); $category->setUrlPath($urlPath); }
public function render(Varien_Object $row) { $url = sprintf('%s%s', Mage::getBaseUrl(), trim($row->getUrlPath(), '/')); return "<a href='{$url}' target='_blank'>{$url}</a>"; }
/** * Generate either id path, request path or target path for product and/or category * * For generating id or system path, either product or category is required * For generating request path - category is required * $parentPath used only for generating category path * * @param string $type * @param Varien_Object $product * @param Varien_Object $category * @param string $parentPath * @return string * @throws Mage_Core_Exception */ public function generatePath($type = 'target', $product = null, $category = null, $parentPath = null) { if (!$product && !$category) { Mage::throwException(Mage::helper('core')->__('Specify either category or product, or both.')); } // generate id_path if ('id' === $type) { if (!$product) { return 'category/' . $category->getId(); } if ($category && $category->getUrlPath()) { return 'product/' . $product->getId() . '/' . $category->getId(); } return 'product/' . $product->getId(); } // generate request_path if ('request' === $type) { // for category if (!$product) { if ($category->getUrlKey() == '') { $urlKey = $this->getCategoryModel()->formatUrlKey($category->getName()); } else { $urlKey = $this->getCategoryModel()->formatUrlKey($category->getUrlKey()); } $categoryUrlSuffix = $this->getCategoryUrlSuffix($category->getStoreId()); if (null === $parentPath) { $parentPath = $this->getResource()->getCategoryParentPath($category); } elseif ($parentPath == '/') { $parentPath = ''; } $parentPath = Mage::helper('catalog/category')->getCategoryUrlPath($parentPath, true, $category->getStoreId()); return $this->getUnusedPath($category->getStoreId(), $parentPath . $urlKey . $categoryUrlSuffix, $this->generatePath('id', null, $category)); } // for product & category if (!$category) { Mage::throwException(Mage::helper('core')->__('Category object is required for determining product request path')); // why? } if ($product->getUrlKey() == '') { $urlKey = $this->getProductModel()->formatUrlKey($product->getName()); } else { $urlKey = $this->getProductModel()->formatUrlKey($product->getUrlKey()); } $productUrlSuffix = $this->getProductUrlSuffix($category->getStoreId()); if ($category->getUrlPath()) { $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(), false, $category->getStoreId()); return $this->getUnusedPath($category->getStoreId(), $categoryUrl . '/' . $urlKey . $productUrlSuffix, $this->generatePath('id', $product, $category)); } // for product only return $this->getUnusedPath($category->getStoreId(), $urlKey . $productUrlSuffix, $this->generatePath('id', $product)); } // generate target_path if (!$product) { return 'catalog/category/view/id/' . $category->getId(); } if ($category && $category->getUrlPath()) { return 'catalog/product/view/id/' . $product->getId() . '/category/' . $category->getId(); } return 'catalog/product/view/id/' . $product->getId(); }
public function render(Varien_Object $row) { return sprintf('%s%s', Mage::getBaseUrl(), trim($row->getUrlPath(), '/')); }