Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recommended Posts

Posted

By default the cPath variable is not passed to the product_info.php page. When products are linked in multiple categories the default behavior of searching for a path to the top category backwards from the product is insufficient as it will stop at the first available path and thus quite probably not display the path the user actually took to get the to product being displayed.

There are two possible solutions.

First is to make certain the cPath variable is always passed to the product_info.php page. This can turn out to be a major pain and very time consuming.

I took the much easier way. Well it was easier after I studied what actually occurs when no cPath variable is passed to the product_info.php page. Simply insert an if statement to see if the http referer data contains the cPath from the previous page and if so, use that cPath instead of creating a new cPath variable.

The function in question here is tep_get_product_path() in the catalog/includes/functions/general.php file.

My stores are very heavily modified, so I won't bother telling you a line number, but here is the code to add at the very beginning of the function.

$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'Referer Not Available';
if(substr_count($referer,HTTP_SERVER . DIR_WS_HTTP_CATALOG . 'index.php/cPath/')>0){
	$cPath=str_replace(HTTP_SERVER . DIR_WS_HTTP_CATALOG . 'index.php/cPath/','',$referer);
}
else{

Don't forget to close that else statement at the very end of the function. My complete tep_get_product_path() function looks like this.

function tep_get_product_path($products_id) {
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'Referer Not Available';
if(substr_count($referer,HTTP_SERVER . DIR_WS_HTTP_CATALOG . 'index.php/cPath/')>0){
	$cPath=str_replace(HTTP_SERVER . DIR_WS_HTTP_CATALOG . 'index.php/cPath/','',$referer);
}
else{
$cPath = '';

$category_query = tep_db_query("select p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = '" . (int)$products_id . "' and p.products_status = '1' and p.products_id = p2c.products_id limit 1");
if (tep_db_num_rows($category_query)) {
  $category = tep_db_fetch_array($category_query);

  $categories = array();
 tep_get_parent_categories($categories, $category['categories_id']);

  $categories = array_reverse($categories);

  $cPath = implode('_', $categories);

  if (tep_not_null($cPath)) $cPath .= '_';
  $cPath .= $category['categories_id'];
  }
}
return $cPath;
 }

So what if the referer data is not available (ie. the visitor has anti-spyware software that prevents this data from being sent to the webserver). Well osCommerce will simply default to the default behavior of recreating the cPath variable using the first path back to the top of the catalog. After looking my Apache logs I discovered that only about 5% of my visitors do not send the referer data with their request and only about 20% products are linked in multiple categories. If you have similar statistics then you can expect this to work correctly about 99% of the time. One percent of the time the user will get the default bread crumb behavior. It isn't like they won't be able view your product info or anything, but yet it isn't the perfect solution either, hence the name "More Accurate Bread Crumb Trail" rather than The Perfect Bread Crumb Trail.

I run a completely customized osC2.2 RC1 shop with mostly custom modifications that replicate the features of many contributions available except in a way that the data is more easily synced with Quickbooks on a continuous basis.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...