About Club osCommerce

Showcasing osCommerce…the good, the bad and the ugly!

Follow osc_pro on Twitter

Passing $cPath thru Advanced Search…

Written By Gary on Apr 01 2008 · Comments (2) Follow osc_pro on Twitter

In the official osCommerce Forum, someone asked for the ability to pass the $cPath variable through the Advanced Search Result "link" for each product.

Basically, instead of a direct link to a product, eg: product_info.php?products_id=10, he wanted product_info.php?cPath=3_11&products_id=10

The example obviously assumes that Product 10, is inside Subcategory 11 which is inside Category 3. Got that :D

The code changes are minimal. There's only two files to change and it goes like this:

advanced_search_result (about line 207)

Find this:

$select_str = "select distinct " . $select_column_list . " m.manufacturers_id, p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price ";

Change to:

$select_str = "select distinct " . $select_column_list . " m.manufacturers_id, p.products_id, p2c.categories_id, pd.products_name, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price ";

/includes/modules/product_listing.php (about line 90)

Find this:

for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
$lc_align = ";

Right below it, add:

if (tep_not_null($listing['categories_id'])) {
$cPath = tep_get_product_path($listing['categories_id']);
}

Done!  Save the files, upload and test the product links.  Feel free to Paypal me a donation if you find it useful ;)


Buy Gary A Beer?
Buying me a "beer" helps me to keep my contributions updated and keep this blog alive - and you get a link from my homepage to your site. Cheers!


2 Comments

  1. Advanced_search_result is returning the incorrect cpath. For example, it returns a cpath of 37_54 when the correct cpath is 72_398_80.
    I suspect it must be one of the category functions, but they all look correct when compared to the stock install.

    Any pointers on where to start?

    Comment by Eli — June 30, 2011 @ 4:45 pm


  2. Good spot. Forget the change in the advanced_search file. In the listing module, just make this code change in place of the other;

    if (tep_not_null($listing['products_id'])) {
    $cPath = tep_get_product_path($listing['products_id']);
    }

    Comment by Gary — July 1, 2011 @ 5:15 pm


Leave a comment

RSS feed for comments on this post · TrackBack URL

Hot 100 osCommerce Shops

View the osCommerce HOT 100These are the best looking, most exceptional osCommerce Stores as voted for by you.

New to osCommerce - get inspiration from these beautiful shops. Reckon your site has what it takes to become a member of the HOT 100? Submit it!