/** * Retrieve Url for specified category * * @param Mage_Catalog_Model_Category $category * @return string */ public function getCategoryUrl(Mage_Catalog_Model_Category $category) { $url = $category->getData('url'); if (null !== $url) { return $url; } Varien_Profiler::start('REWRITE: ' . __METHOD__); if ($category->hasData('request_path') && $category->getRequestPath() != '') { $category->setData('url', $this->getUrlInstance()->getDirectUrl($category->getRequestPath())); Varien_Profiler::stop('REWRITE: ' . __METHOD__); return $category->getData('url'); } $requestPath = $this->_getRequestPath($category); if ($requestPath) { $category->setRequestPath($requestPath); $category->setData('url', $this->getUrlInstance()->getDirectUrl($requestPath)); Varien_Profiler::stop('REWRITE: ' . __METHOD__); return $category->getData('url'); } Varien_Profiler::stop('REWRITE: ' . __METHOD__); $category->setData('url', $category->getCategoryIdUrl()); return $category->getData('url'); }
/** * Enter description here... * * @param Mage_Catalog_Model_Category $category * @param int $level * @param boolean $last * @return string */ public function drawItemSingle($category, $level = 0, $last = false) { $html = ''; if (!$category->getIsActive()) { return $html; } if (Mage::helper('catalog/category_flat')->isEnabled()) { $children = $category->getChildrenNodes(); $childrenCount = count($children); } else { $children = $category->getChildren(); $childrenCount = $children->count(); } $hasChildren = $children && $childrenCount; $html .= '<li'; if ($hasChildren) { $html .= ' onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)"'; } $html .= ' class="level' . $level; $html .= ' nav-' . str_replace('/', '-', Mage::helper('catalog/category')->getCategoryUrlPath($category->getRequestPath())); if ($this->isCategoryActive($category)) { $html .= ' active'; } if ($last) { $html .= ' last'; } if ($hasChildren) { $cnt = 0; foreach ($children as $child) { if ($child->getIsActive()) { $cnt++; } } if ($cnt > 0) { $html .= ' parent'; } } $html .= '">' . "\n"; $html .= '<a href="' . $this->getCategoryUrl($category) . '"><span>' . $this->htmlEscape($category->getName()) . '</span></a>' . "\n"; $html .= '</li>' . "\n"; return $html; }
/** * Get category request path * * @param Mage_Catalog_Model_Category $category * @return string * @deprecated since 1.13.0.2 */ protected function _getCategoryRequestPath(Mage_Catalog_Model_Category $category) { /** * Initialize request_path value */ $category->getUrl(); /** @var $helper Enterprise_Catalog_Helper_Data */ $helper = $this->_factory->getHelper('enterprise_catalog'); return $helper->getCategoryRequestPath($category->getRequestPath(), $category->getStoreId()); }
/** * Get full URL by request path if it exist or by ID-URL * * @param Mage_Catalog_Model_Category $category * @return string * @deprecated since 1.13.0.2 */ protected function _getFullUrl(Mage_Catalog_Model_Category $category) { return $category->getRequestPath() ? $this->_getDirectUrl($category) : $category->getCategoryIdUrl(); }
/** * Returns category URL by which it can be accessed * @param Mage_Catalog_Model_Category $category * @return string */ protected function _getDirectUrl(Mage_Catalog_Model_Category $category) { return $this->getUrlInstance()->getDirectUrl($category->getRequestPath()); }
public function testGetRequestPath() { $this->assertNull($this->_model->getRequestPath()); $this->_model->setData('request_path', 'test'); $this->assertEquals('test', $this->_model->getRequestPath()); }
public function getObject(Mage_Catalog_Model_Category $category) { /** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */ $productCollection = $category->getProductCollection(); $productCollection = $productCollection->addMinimalPrice(); $category->setProductCount($productCollection->getSize()); $transport = new Varien_Object(); Mage::dispatchEvent('algolia_category_index_before', array('category' => $category, 'custom_data' => $transport)); $customData = $transport->getData(); $storeId = $category->getStoreId(); $category->getUrlInstance()->setStore($storeId); $path = ''; foreach ($category->getPathIds() as $categoryId) { if ($path != '') { $path .= ' / '; } $path .= $this->getCategoryName($categoryId, $storeId); } $image_url = NULL; try { $image_url = $category->getImageUrl(); } catch (Exception $e) { /* no image, no default: not fatal */ } $data = array('objectID' => $category->getId(), 'name' => $category->getName(), 'path' => $path, 'level' => $category->getLevel(), 'url' => Mage::getBaseUrl() . $category->getRequestPath(), '_tags' => array('category'), 'popularity' => 1, 'product_count' => $category->getProductCount()); if (!empty($image_url)) { $data['image_url'] = $image_url; } foreach ($this->config->getCategoryAdditionalAttributes($storeId) as $attribute) { $value = $category->getData($attribute['attribute']); $attribute_ressource = $category->getResource()->getAttribute($attribute['attribute']); if ($attribute_ressource) { $value = $attribute_ressource->getFrontend()->getValue($category); } if (isset($data[$attribute['attribute']])) { $value = $data[$attribute['attribute']]; } if ($value) { $data[$attribute['attribute']] = $value; } } $data = array_merge($data, $customData); foreach ($data as &$data0) { $data0 = $this->try_cast($data0); } return $data; }
/** * Enter description here... * * @param Mage_Catalog_Model_Category $category * @param int $level * @param boolean $last * @return string */ public function drawItem($category, $level = 0, $last = false) { $html = ''; if (!$category->getIsActive()) { return $html; } if (Mage::helper('catalog/category_flat')->isEnabled()) { $children = $category->getChildrenNodes(); $childrenCount = count($children); } else { $children = $category->getChildren(); $childrenCount = $children->count(); } $hasChildren = $children && $childrenCount; $html .= '<li'; if ($hasChildren) { //$html.= ' onmouseover="Element.addClassName(this, \'over\') " onmouseout="Element.removeClassName(this, \'over\') "'; } $html .= ' class="level' . $level; $html .= ' nav-' . str_replace('/', '-', Mage::helper('catalog/category')->getCategoryUrlPath($category->getRequestPath())); if ($this->isCategoryActive($category)) { $html .= ' active'; } if ($last) { $html .= ' last'; } if ($hasChildren) { $cnt = 0; foreach ($children as $child) { if ($child->getIsActive()) { $cnt++; } } if ($cnt > 0) { $html .= ' parent'; } } $html .= '">' . "\n"; if ($level == 0) { $html .= '<a href="' . $this->getCategoryUrl($category) . '"><span>' . $this->htmlEscape($category->getName()) . '</span></a><span class="head"><a href="#" style="float:right;"></a></span>' . "\n"; } else { $html .= '<a href="' . $this->getCategoryUrl($category) . '"><span>' . $this->htmlEscape($category->getName()) . '</span></a>' . "\n"; } if ($hasChildren) { $j = 0; $htmlChildren = ''; foreach ($children as $child) { if ($child->getIsActive()) { $htmlChildren .= $this->drawItem($child, $level + 1, ++$j >= $cnt); } } if (!empty($htmlChildren)) { $html .= '<ul class="level' . $level . '">' . "\n" . $htmlChildren . '</ul>'; } } $html .= '</li>' . "\n"; return $html; }
/** * Enter description here... * * @param Mage_Catalog_Model_Category $category * @param int $level * @param boolean $last * @return string */ public function drawItem($category, $level = 0, $last = false) { $html = ''; if (!$category->getIsActive()) { return $html; } $children = $category->getChildren(); $hasChildren = $children && $children->count(); $html .= '<li'; if ($hasChildren) { $html .= ' onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)"'; } $html .= ' class="level' . $level; $html .= ' nav-' . str_replace('/', '-', Mage::helper('catalog/category')->getCategoryUrlPath($category->getRequestPath())); if ($this->isCategoryActive($category)) { $html .= ' active'; } if ($last) { $html .= ' last'; } if ($hasChildren) { $cnt = 0; foreach ($children as $child) { if ($child->getIsActive()) { $cnt++; } } $html .= ' parent'; } $html .= '">' . "\n"; $html .= '<a href="' . $this->getCategoryUrl($category) . '"><span>' . $this->htmlEscape($category->getName()) . '</span></a>' . "\n"; //$html.= '<span>'.$level.'</span>'; if ($hasChildren) { $j = 0; $htmlChildren = ''; foreach ($children as $child) { if ($child->getIsActive()) { $htmlChildren .= $this->drawItem($child, $level + 1, ++$j >= $cnt); } } if (!empty($htmlChildren)) { $html .= '<ul class="level' . $level . '">' . "\n" . $htmlChildren . '</ul>'; } } $html .= '</li>' . "\n"; return $html; }
/** * Enter description here... * * @param Mage_Catalog_Model_Category $category * @param int $level * @param boolean $last * @return string */ public function drawItem($category, $level = 0, $last = false) { $html = ''; if (!$category->getIsActive()) { return $html; } if (Mage::helper('catalog/category_flat')->isEnabled()) { $children = $category->getChildrenNodes(); $childrenCount = count($children); } else { $children = $category->getChildren(); $childrenCount = $children->count(); } $hasChildren = $children && $childrenCount; $html .= '<li'; $html .= ' class="item'; $html .= ' nav-' . str_replace('/', '-', Mage::helper('catalog/category')->getCategoryUrlPath($category->getRequestPath())); if ($this->isCategoryActive($category)) { $html .= ' active'; } if ($last) { $html .= ' last'; } if ($hasChildren) { $cnt = 0; foreach ($children as $child) { if ($child->getIsActive()) { $cnt++; } } if ($cnt > 0) { $html .= ' hasChild'; } } $html .= '">' . "\n"; if ($level == 0) { if ($hasChildren) { $html .= '<a class="item" href="' . $this->getCategoryUrl($category) . '">' . $this->htmlEscape($category->getName()) . '</a>' . "\n"; //$html.= '<span class="collapse">collapse</span>'; } else { $html .= '<a class="item" href="' . $this->getCategoryUrl($category) . '">' . $this->htmlEscape($category->getName()) . '</a>' . "\n"; } } else { if ($hasChildren) { $html .= '<a class="item" href="' . $this->getCategoryUrl($category) . '">' . $this->htmlEscape($category->getName()) . '</a>' . "\n"; //$html.= '<span class="collapse">collapse</span>'; } else { $html .= '<a class="item" href="' . $this->getCategoryUrl($category) . '">' . $this->htmlEscape($category->getName()) . '</a>' . "\n"; } } if ($hasChildren) { $j = 0; $htmlChildren = ''; foreach ($children as $child) { if ($child->getIsActive()) { $htmlChildren .= $this->drawItem($child, $level + 1, ++$j >= $cnt); } } if (!empty($htmlChildren)) { $html .= '<ul class="detail-parent">' . "\n" . $htmlChildren . '</ul>'; } } $html .= '</li>' . "\n"; return $html; }