jasonabc Posted April 12, 2007 Posted April 12, 2007 I need to do a bit of logic based around what category is showing. Ordinarily I'd just use the $_GET['cPath'] value from the querystring - but this variable does not appear in the querystring on the product detail page. Anyone got any idea how I can get the cPath value from product_info.php? I basically need to show something if the cPath == 3 and hide it if it's anything else on this page. cheers Jase Jason My Contributions: Paypal Payflow PRO | Rollover Category Images | Authorize.net Invoice Number Fix
Guest Posted April 12, 2007 Posted April 12, 2007 I need to do a bit of logic based around what category is showing. Ordinarily I'd just use the $_GET['cPath'] value from the querystring - but this variable does not appear in the querystring on the product detail page. Anyone got any idea how I can get the cPath value from product_info.php? I basically need to show something if the cPath == 3 and hide it if it's anything else on this page. cheers Jase Hi Jason, use the tep_generate_category_path. It's in the catalog\admin\includes\functions\general.php. copy it over to the catalog end then call it with the products_id passed and specify the $from to be product. It will return an array of categories which you can use to build the entire path.
jasonabc Posted April 12, 2007 Author Posted April 12, 2007 Hey Mark - appreciate the response ;-) I've copied the entire tep_generate_category_path into product_info.php as you suggest and then written a bit of code underneath to access it. It fails when it gets to the for loop to access the returned array. Here's the code - any thoughts as to where I'm going wrong? $catProductID = $_GET['products_id']; $productCat = tep_generate_category_path($catProductID, 'product', $categories_array, $index); for($i = 0, $u = count($productCat);$i < $u;$i++) { echo $productCat[$i] . '<br />'; } cheers Jason Jason My Contributions: Paypal Payflow PRO | Rollover Category Images | Authorize.net Invoice Number Fix
Guest Posted April 12, 2007 Posted April 12, 2007 Hey Mark - appreciate the response ;-) I've copied the entire tep_generate_category_path into product_info.php as you suggest and then written a bit of code underneath to access it. It fails when it gets to the for loop to access the returned array. Here's the code - any thoughts as to where I'm going wrong? $catProductID = $_GET['products_id']; $productCat = tep_generate_category_path($catProductID, 'product', $categories_array, $index); for($i = 0, $u = count($productCat);$i < $u;$i++) { echo $productCat[$i] . '<br />'; } cheers Jason The product path is an md array so you need to echo echo $productCat[$i]['id'] Also when you call the function you either need to pass an array and index or leave them blank so try $productCat = tep_generate_category_path($catProductID, 'product');
jasonabc Posted April 13, 2007 Author Posted April 13, 2007 Hi Mark - many thanks for that! I'm *almost* there!! I'm now successfully echoing the cPath in the product_info page. However - where categories have subcategories (cPath=2_29) for example it's echoing 229. This causes probs because some of my categories have a one digit cPath and others have two digits. 229 could be 2_29 or it could be 22_9 which makes evaluating the string a bit tricky for the conditional. Do you know a way I can just get the top level category number (i.e. just the '2'?) from the function? The sub category number isn't necessary - I just need the top level cPath. Here's my new code: $catProductID = $_GET['products_id']; $product_categories = tep_generate_category_path($catProductID, 'product'); for ($i = 0, $n = sizeof($product_categories); $i < $n; $i++) { echo $product_categories[$i][sizeof($product_categories[$i])-1]['id'] . '<br />'; } cheers! Jason Jason My Contributions: Paypal Payflow PRO | Rollover Category Images | Authorize.net Invoice Number Fix
Guest Posted April 13, 2007 Posted April 13, 2007 Well I do not understand, the result should be an md array of (id/text). So you should have no trouble differentiating the array elements. The stcok osC admin calls the function to display the drop-down categories for the search. So you should have: [0]['id'] => 2 [0]['text'] => 'Accessories' Now I see you're trying to use some other element? what's this middle field? sizeof(...) it's incorrect $product_categories[$i][sizeof($product_categories[$i])-1]['id']
jasonabc Posted April 13, 2007 Author Posted April 13, 2007 Hi Mark, echo $productCat[$i]['id'] didn't return anything - it was blank. So I tried a couple of other things. I got $product_categories[$i][sizeof($product_categories[$i])-1]['id'] straight out of /admin/categories.php which is the only place that the tep_generate_category_path function is called? Jason My Contributions: Paypal Payflow PRO | Rollover Category Images | Authorize.net Invoice Number Fix
Guest Posted April 13, 2007 Posted April 13, 2007 yes there is another element ok I missed it. try: for ($i = 0, $n = sizeof($product_categories); $i < $n; $i++) { echo $product_categories[$i][0]['id'] . '<br />'; echo $product_categories[$i][0]['text'] . '<br />'; } does that return the ids separately?
jasonabc Posted April 13, 2007 Author Posted April 13, 2007 It does - except if I'm in a subcategory and click a product - it only returns the subcategory cPath - not the top level one? I just want to get the top level cPath value as that's what I'm using in the conditional (the sub cats don't matter) Thanks for all your help on this so far. Jason My Contributions: Paypal Payflow PRO | Rollover Category Images | Authorize.net Invoice Number Fix
Guest Posted April 13, 2007 Posted April 13, 2007 ok do something else then. Copy from the admin end also the function tep_get_generated_category_path_ids then get the categories_id using the products_to_categories table and pass the category id to the tep_get_generated_category_path_ids it should return a full cpath where the product is. You need both functions so just copy them in general.php in the catalog end. Or you can specify product id directly. (you may not need the extra query)
jasonabc Posted November 21, 2007 Author Posted November 21, 2007 Just an update to this (in case anyone needs to do this in the future) - I found a much simpler solution to the one above. There's a variable in application top which keeps track of the category ID. So in product_info.php all you need to do is reference it: $current_category_id As in if ($current_category_id == 3) { // do something } :-) Jason My Contributions: Paypal Payflow PRO | Rollover Category Images | Authorize.net Invoice Number Fix
Recommended Posts
Archived
This topic is now archived and is closed to further replies.