Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Different content based on category parent..


lindsayanng

Recommended Posts

Posted

I have not yet tried this, but I was curious how nested categories work on the product pages.. For instance, lets say I have a product in the tshirts parent category and the kids sub category... I want to create an if statement in the product_info.php that says something like this:

 

<?php

if ( basename($PHP_SELF) == FILENAME_DEFAULT ) {

if ( $cPath!='2' )

 

 

echo <img src="images/tshirt1.jpg"> <img src="images/tshirt2.jpg"> <img src="images/tshirt3.jpg">;

 

elseif ( $cPath!='3' )

 

echo <img src="images/longsleeve1.jpg"> <img src="images/longsleeve2.jpg"> <img src="images/longsleeve3.jpg">;

}

else

echo <img src="images/longsleeve1.jpg"> <img src="images/longsleeve2.jpg"> <img src="images/longsleeve3.jpg">;

 

?>

 

 

So the main concern is.. if the category displayed in the if statement is a parent category, and you are viewing any product in any sub category, will this work?

A great place for newbies to start

Road Map to oscommerce File Structure

DO NOT PM ME FOR HELP. My time is valuable, unless i ask you to PM me, please dont. You will get better help if you post publicly. I am not as good at this as you think anyways!

 

HOWEVER, you can visit my blog (go to my profile to see it) and post a question there, i will find time to get back and answer you

 

Proud Memeber of the CODE BREAKERS CLUB!!

Posted

At the moment.. I have this for testing..

 

  <?php 

if ( $cPath!='28' ){


echo' <img src="images/tshirt1.jpg"> <img src="images/tshirt2.jpg"> <img src="images/tshirt3.jpg">';

}else {

echo '<img src="images/longsleeve1.jpg"> <img src="images/longsleeve2.jpg"> <img src="images/longsleeve3.jpg">';

}
?>

 

What should happen is if you are on any product with the category cPath of 28, it should show the tshirt images, all other cats should show the longsleeve images.. This is not happening..

 

You can see here

A great place for newbies to start

Road Map to oscommerce File Structure

DO NOT PM ME FOR HELP. My time is valuable, unless i ask you to PM me, please dont. You will get better help if you post publicly. I am not as good at this as you think anyways!

 

HOWEVER, you can visit my blog (go to my profile to see it) and post a question there, i will find time to get back and answer you

 

Proud Memeber of the CODE BREAKERS CLUB!!

Posted

The code

if ( basename($PHP_SELF) == FILENAME_DEFAULT ) {
if ( $cPath!='2' )

would never happen on the product_info page since it isn't the index.php page (FILENAME_DEFAULT) and doesn't use cPath. You will need to create a database call to get the category ID using the product ID for that page.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Posted

Gahh that would explain it.. I forgot that I I can really use the cpath on the index page.. ok.. Since i'm not so great with mysql i will really have to spend some time with this..

 

SO i need to query the DB for the current category and then use that in the if/else statement??

A great place for newbies to start

Road Map to oscommerce File Structure

DO NOT PM ME FOR HELP. My time is valuable, unless i ask you to PM me, please dont. You will get better help if you post publicly. I am not as good at this as you think anyways!

 

HOWEVER, you can visit my blog (go to my profile to see it) and post a question there, i will find time to get back and answer you

 

Proud Memeber of the CODE BREAKERS CLUB!!

Posted

Yea, apparently it works in mysterious ways :)

 

This is my exact code:

    <?php 

if ( $cPath!='28' ){


echo' <img src="images/tshirt1.jpg"> <img src="images/tshirt2.jpg"> <img src="images/tshirt3.jpg">';

}else {

echo '<img src="images/longsleeve1.jpg"> <img src="images/longsleeve2.jpg"> <img src="images/longsleeve3.jpg">';

}
?>

 

Does anyone see any typos or weirdness on my part.. Because if you can echo the cpath, you should be able to use it in an if statement (i would THINK)

A great place for newbies to start

Road Map to oscommerce File Structure

DO NOT PM ME FOR HELP. My time is valuable, unless i ask you to PM me, please dont. You will get better help if you post publicly. I am not as good at this as you think anyways!

 

HOWEVER, you can visit my blog (go to my profile to see it) and post a question there, i will find time to get back and answer you

 

Proud Memeber of the CODE BREAKERS CLUB!!

Posted

So any thoughts on this code here??

A great place for newbies to start

Road Map to oscommerce File Structure

DO NOT PM ME FOR HELP. My time is valuable, unless i ask you to PM me, please dont. You will get better help if you post publicly. I am not as good at this as you think anyways!

 

HOWEVER, you can visit my blog (go to my profile to see it) and post a question there, i will find time to get back and answer you

 

Proud Memeber of the CODE BREAKERS CLUB!!

Posted

cPath is handled in application top and it may be safe to use it but I don't know that I would depend on it. Is it valid if someone directly links to the product page? I would prefer to call it explictly so there's no question about it. You can try

$cPath = tep_get_product_path($_GET['products_id']);

Your code for the image looks fine.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Posted

Ok yes... I have a basic hack that would totally work..

 

 <?php 
switch ($current_category_id){
case "28":
echo' <img src="images/tshirt1.jpg" width="200px"> <img src="images/tshirt2.jpg" width="200px"> <img src="images/tshirt3.jpg" width="200px"><img src="images/productadd/hugmeup_2412-2.jpg" width="200px">';
	break;
		case "31":
echo' <img src="images/productadd/hugmeup_2386.jpg" width="200px"> <img src="images/productadd/hugmeup_2389-2.jpg" width="200px"> <img src="images/productadd/hugmeup_2422.jpg" width="200px"><img src="images/productadd/hugmeup_2477-2.jpg" width="200px">';
	break;
	}

?>

 

 

Where the case # is the cpath number.. works perfectly.. Now the next step is to move this out of the core code and have people enter it via an admin area.. but thats more work than I have time to do..

A great place for newbies to start

Road Map to oscommerce File Structure

DO NOT PM ME FOR HELP. My time is valuable, unless i ask you to PM me, please dont. You will get better help if you post publicly. I am not as good at this as you think anyways!

 

HOWEVER, you can visit my blog (go to my profile to see it) and post a question there, i will find time to get back and answer you

 

Proud Memeber of the CODE BREAKERS CLUB!!

Posted

watch out, $cPath == $current_category_id only for the toplevel categories,

it might be ok for your case, just make sure you are aware of the difference as they've been both in above code snippets

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Posted

$category_is_on = (isset($cPath_array) && (sizeof($cPath_array) > 1)) ? (int)$cPath_array[1] : (int)$current_category_id;

 

Do what you want with $category_is_on;

 

Should work on any page that affects the category menu; index, product_info, reviews

Posted

Instead, try this:

 

$category_is_on = (isset($cPath_array) && (sizeof($cPath_array) > 1)) ? (int)$cPath_array[sizeof($cPath_array) - 2] : (int)$current_category_id ;

 

echo $category_is_on;

 

Untested, but you should be able to work something out from that.

  • 3 weeks later...
Posted

hey Burt.. I came back to revisit this.. I currently have my site set up like this..

 

PARENT CATEGORY (no prods. just for organizational purposes)

Subcat 1

Subcat 2

 

I FINALLY got it so that when you click on the parent category you see a link to the sub cat and beneath that you see all of the products in subcat 1 and subcat 2

 

This means that the path is different now.. If you go to a product that is in subcat1 from the parent cat listing, the switch statement does work (as expected and pointed out above)

 

So my question is.. how do you find out which category a product is in WITHOUT querying the cpath and instead actually getting the category..

A great place for newbies to start

Road Map to oscommerce File Structure

DO NOT PM ME FOR HELP. My time is valuable, unless i ask you to PM me, please dont. You will get better help if you post publicly. I am not as good at this as you think anyways!

 

HOWEVER, you can visit my blog (go to my profile to see it) and post a question there, i will find time to get back and answer you

 

Proud Memeber of the CODE BREAKERS CLUB!!

Posted

Oops.. heres my code as it is now

 

   <?php 
$category_is_on = (isset($cPath_array) && (sizeof($cPath_array) > 1)) ? (int)$cPath_array[1] : (int)$current_category_id;
switch ($category_is_on){
	//case "28":
case "29":
case "32":
	case "47":
		case "46":
		case "44":
		case "45":

echo' <img src="images/tshirt1.jpg" width="200px"> <img src="images/tshirt2.jpg" width="200px"> <img src="images/tshirt3.jpg" width="200px"><img src="images/productadd/hugmeup_2412-2.jpg" width="200px">';
	break;
		case "31":
		case "48":
		case "49":
echo' <img src="pagegraphics/dogsinclothes//hugmeup_2386-2.jpg" width="200px"> <img src="pagegraphics/dogsinclothes/products-258.jpg" width="200px"> <img src="pagegraphics/dogsinclothes/products-252.jpg" width="200px"><img src="pagegraphics/dogsinclothes/hugmeup_2481-2.jpg" width="200px">';
	break;
	}

?>

A great place for newbies to start

Road Map to oscommerce File Structure

DO NOT PM ME FOR HELP. My time is valuable, unless i ask you to PM me, please dont. You will get better help if you post publicly. I am not as good at this as you think anyways!

 

HOWEVER, you can visit my blog (go to my profile to see it) and post a question there, i will find time to get back and answer you

 

Proud Memeber of the CODE BREAKERS CLUB!!

Posted

Well I found a function that is pretty useful .. It gets the product's category not by the cpath but via the product ID (because it is associated with the category)

 

  $category_path =tep_get_product_path($product_info['products_id']);

A great place for newbies to start

Road Map to oscommerce File Structure

DO NOT PM ME FOR HELP. My time is valuable, unless i ask you to PM me, please dont. You will get better help if you post publicly. I am not as good at this as you think anyways!

 

HOWEVER, you can visit my blog (go to my profile to see it) and post a question there, i will find time to get back and answer you

 

Proud Memeber of the CODE BREAKERS CLUB!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...