The only time that this method won't work is when someone arrives at the product listing from a direct link (a bookmark, or a search engine page, etc.) When this happens, there is no internal path to follow... and no breadcrumb that matches any info from the HTTP_REFERER so the breadcrumb generator will loop through ALL available breadcrumbs and display the LAST ONE it finds.
This code works for ISC 4.07... it may work in other versions, but I have not tested it in other versions.
I am claiming a copyright on the added code. Individuals are free to add this code to your registered copy of the ISC software, but ISC is NOT free to include it in the software they distribute, sell, or use on their BigCommerce.
DO NOT RE-POST THIS CODE ON THE ISC WEB SITE! (Instead, just link to it here.)
REPEAT... DO NOT RE-POST THIS CODE ON THE ISC WEB SITE! Send them here... this is a great site that deserves more traffic.
KEEP THE COPYRIGHT NOTICES INTACT
Buy me a beer if you like this code well enough to use it.
ISC VERSION: 4.07
FILE TO EDIT: ../includes/classes/class.product.php
SEARCH FOR:
Code: Select all
public function _BuildBreadCrumbs()
Code: Select all
public function ORIGINAL_BuildBreadCrumbs()
SEARCH FOR:
Code: Select all
public function HandlePage()
INSERT ABOVE THAT:
Code: Select all
public function _BuildBreadCrumbs()
{
/*
Build a list of one or more breadcrumb trails for this
product based on which categories it appears in
*/
// Build the arrays that will contain the category names to build the trails
$count = 0;
$GLOBALS['BreadCrumbs'] = "";
$GLOBALS['FindByCategory'] = "";
// First we need to fetch the parent lists of all of the categories
$trailCategories = array();
$crumbList = array();
$query = sprintf("
SELECT c.categoryid, c.catparentlist
FROM [|PREFIX|]categoryassociations ca
INNER JOIN [|PREFIX|]categories c ON (c.categoryid=ca.categoryid)
WHERE ca.productid='%d'",
$GLOBALS['ISC_CLASS_DB']->Quote($this->GetProductId())
);
$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
if ($row['catparentlist'] == '') {
$row['catparentlist'] = $row['categoryid'];
}
$cats = explode(",", $row['catparentlist']);
$trailCategories = array_merge($trailCategories, $cats);
$crumbList[$row['categoryid']] = $row['catparentlist'];
}
$trailCategories = implode(",", array_unique($trailCategories));
$categories = array();
if ($trailCategories != '') {
// Now load the names for the parent categories from the database
$query = sprintf("SELECT categoryid, catname FROM [|PREFIX|]categories WHERE categoryid IN (%s)", $trailCategories);
$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
$categories[$row['categoryid']] = $row['catname'];
}
}
// Now we have all of the information we need to build the trails, lets actually build them
// ===================================================================
// BEGIN COPYRIGHT © 2009 ~ CHARLIE FOXTROT (FOXTROTPRINTING.COM)
// IS THE BREADCRUMB RELEVENT? ARE THERE ANY SIMILARITIES WITH THE REFERER??
$wasCatBrowsing = false; // assume false until we determine it's true
$catDirectory = "/categories/"; // Change this value if you've modified "categories" for a different language.
$referrer = getenv("HTTP_REFERER"); // get the referrer for comparison... but first we need to clean it up a bit
$wasCatBrowsing = strpos($referrer, $catDirectory); // Search for the word "categories". If true, we were browsing a category
if ($wasCatBrowsing !== false) { // Not-false is true. We were browsing a category, so let's clean-up and trim-down the referrer
$serverName = getenv("SERVER_NAME"); // we won't need this... we'll store its value in the array to be removed later
$httpStuff = array($serverName, "http://", "https://"); // Items in this array will be stripped-out of the referrer comparison string
$referrer = str_replace($httpStuff, "", $referrer); // ...so we need to delete these array elements from the referrer string
$argPosition = strpos($referrer, "?"); // if the "?" exists then the next line will trim it and all unneeded arguments that follow it
if ($argPosition !== false) { $referrer = substr($referrer, 0, $argPosition); }}
// END COPYRIGHT © 2009 ~ CHARLIE FOXTROT (FOXTROTPRINTING.COM)
// ===================================================================
foreach ($crumbList as $productcatid => $trail) {
$GLOBALS['CatTrailLink'] = $GLOBALS['ShopPath'];
$GLOBALS['CatTrailName'] = GetLang('Home');
$GLOBALS['BreadcrumbItems'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("BreadcrumbItem");
$GLOBALS['FindByCategoryItems'] = "";
$cats = explode(",", $trail);
$breadcrumbitems = "";
$findbycategoryitems = "";
$hasAccess = true;
foreach ($cats as $categoryid) {
if(!CustomerGroupHasAccessToCategory($categoryid)) {
/*
if customer doesn't have access to this category and this category is the category of the product,
dont print the trail, otherwise just exclude the category from the trail
*/
if ($categoryid == $productcatid) {
$hasAccess = false;
break;
}
continue;
}
if (isset($categories[$categoryid])) {
$catname = $categories[$categoryid];
$GLOBALS['CatTrailLink'] = CatLink($categoryid, $catname);
$GLOBALS['CatTrailName'] = isc_html_escape($catname);
// Fixed error with this by copying the 4.01 lines of code
$GLOBALS['BreadcrumbItems'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("BreadcrumbItem");
// Fixed error with this by copying the 4.01 lines of code
$GLOBALS['FindByCategoryItems'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("ProductFindByCategoryItem");
}
}
if ($hasAccess) {
$GLOBALS['CatTrailName'] = isc_html_escape($this->GetProductName());
$GLOBALS['BreadcrumbItems'] .= $breadcrumbitems . $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("BreadcrumbItemCurrent");
// BELOW are the original ISC lines... they have been commented out and replaced
//$GLOBALS['BreadCrumbs'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("ProductBreadCrumb");
//$GLOBALS['FindByCategory'] .= $findbycategoryitems . $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("ProductFindByCategory");
// The modification below means that the LAST one found when looping will be the ONLY one displayed
// The ".=" is now just "=" ... This means that every breadcrumb found during this loop REPLACES the previous
// one (instead of stacking them one on top of the other). Not very efficient, but it's necessary to do while we
// continue to search for a matching breadcrumb path (below). Ultimately, if no match is found, we still display
// only ONE breadcrumb path: the last one found.
$GLOBALS['BreadCrumbs'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("ProductBreadCrumb");
$GLOBALS['FindByCategory'] = $findbycategoryitems . $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("ProductFindByCategory");
// ===================================================================
// BEGIN COPYRIGHT © 2009 ~ CHARLIE FOXTROT (FOXTROTPRINTING.COM)
// However, if the breadcrumb matches our previous referrer, then stop looping and use THAT one.
if ($wasCatBrowsing !== false) { // we were browsing a category, so check the current breadcrumb-string for a referrer-match
$refMatch = strpos($GLOBALS['BreadCrumbs'], $referrer); // check to see if the referer-URL segment exists in this breadcrumb
if ($refMatch !== false) { break; }} // if found, then we can stop looping and disply THIS breadcrumb
//
// END COPYRIGHT © 2009 ~ CHARLIE FOXTROT (FOXTROTPRINTING.COM)
// ===================================================================
}
}
}
Save your work. Upload the file. Test it.
BUY ME A BEER: PayPal to... charlie.foxtrot[at]foxtrotprinting[dot]com