Magento corrected the crumb navigation on the product page from the homepage _ PHP Tutorial

Source: Internet
Author: User
Magento corrected the crumb navigation on the product page from the home page. This article will introduce Magento to you how to implement the breadcrumb navigation on the Product page from the homepage. if the Product is from the Category Product list, go to the Product details page, this article introduces Magento to's solution to the browser. if the Product is from the Category Product list, go to the Product details page, the breadcrumb navigation contains the Category Path; otherwise, it is missing when you enter from the homepage, search results, or somewhere else. I think it may be because Magento supports multiple Category for one product. In any case, the product page lacks the Category Path, and the user experience is poor.

Find the app/code/core/Mage/Catalog/Helper/Data. php file.

Copy a copy to the local code pool

App/code/local/Mage/Catalog/Helper/Data. php
Add the following code logic to the start part of the getBreadcrumbPath function:

The code is as follows:
GetBreadcrumbPath ()
{
If (! $ This-> _ categoryPath ){
$ Path = array ();
// Add by date 2013-04-07 product page bread navigation correction
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 product page is used. if there is no Category information, obtain the Category IDs to which the product belongs. one product in Magento can be added to multiple Category, select only one of the lucky Category as current_category.

Corrected the implementation method of the breadcrumb navigation on the Product page from the homepage. if the Product is from the Category Product list to enter the Product details page, then the breadcrumb navigation...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.