Home > Article > Backend Development > Magento fixes product page navigation from home page_PHP tutorial
This article is to introduce Magento to friends. Modify the implementation method of breadcrumb navigation for product pages from the homepage. If the product enters the Product details page from the Category product list, the breadcrumb navigation contains Category Path; otherwise, when entering the Product details page from the homepage; otherwise, when entering the product page from the homepage , or in the search results, or entered elsewhere, it is missing. I think it may be because Magento supports putting a product into multiple categories. In any case, the Category Path is missing from the product page, and the user experience is not very good.
Correction method, find the file app/code/core/Mage/Catalog/Helper/Data.php
Copy a copy to the local code pool
app/code/local/Mage/Catalog/Helper/Data.php
At the beginning of the function getBreadcrumbPath, add the following code logic:
代码如下 | 复制代码 |
getBreadcrumbPath() { if (!$this->_categoryPath) { $path = array(); //add by date 2013-04-07 产品页面包屑导航修正 if ($this->getProduct() && !$this->getCategory()) { $_categoryIds = $this->getProduct()->getCategoryIds(); rsort($_categoryIds); if ($_categoryId = $_categoryIds[0]) { $_category = Mage::getModel('catalog/category')->load($_categoryId); Mage::register('current_category', $_category); } } //end date 2013-04-07 if ($category = $this->getCategory()) { $pathInStore = $category->getPathInStore(); $pathIds = array_reverse(explode(',', $pathInStore)); $categories = $category->getParentCategories(); // add category path breadcrumb foreach ($pathIds as $categoryId) { if (isset($categories[$categoryId]) && $categories[$categoryId]->getName()) { $path['category'.$categoryId] = array( 'label' => $categories[$categoryId]->getName(), 'link' => $this->_isCategoryLink($categoryId) ? $categories[$categoryId]->getUrl() : '' ); } } } if ($this->getProduct()) { $path['product'] = array('label'=>$this->getProduct()->getName()); } $this->_categoryPath = $path; } return $this->_categoryPath; } |
First determine whether the current page is a product page. If it is and there is no Category information, get the Category IDs to which the product belongs. In Magento, a product can be added to multiple Categories. Now I don’t care about so many, just pick out one of them. Category as current_category