Forums / Templates, Stylesheets, Page Layout / Hiding product images under one category but not another

Hiding product images under one category but not another

Locked

Started by robgt on 3 Mar 2008, 11:34 PM · Views: 2,613

Results 1 to 20 of 22
This thread is locked. New replies are disabled.
3 Mar 2008, 11:34 PM
#1
robgt avatar

robgt

New Zenner

Join Date:
Dec 2007
Posts:
27
Plugin Contributions:
0

Hiding product images under one category but not another

Hi,
The product listing page displays with Image, Description, Price, etc columns.
This is fine for most pages, but how would I go about not displaying that product image when that same product is displayed under a different category (as a linked product in admin).

I can't provide a site URL I'm afriad, but hopefully the question is self explanatory?
Any ideas/suggestions?

I've hunted through the forums without success so far.
Cheers,
Rob

4 Mar 2008, 12:02 AM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Hiding product images under one category but not another

You could edit /includes/modules/your_template/product_listing.php to include a test for $cPath being equal to the category you wish to hide...

Gallery Category does exactly the kind of thing you want for the price and add button; you could transfer the logic to the image case and hide that on your selected categories.

4 Mar 2008, 12:21 AM
#3
robgt avatar

robgt

New Zenner

Join Date:
Dec 2007
Posts:
27
Plugin Contributions:
0

Re: Hiding product images under one category but not another

Thanks for the speedy reply.
Having read several threads on testing the $cPath - I have a question that relates to my main question.

If I have a category ID=20, would checking $cPath for 20 and hiding a column in product_listing.php carry through to sub categories of category 20 (20_243 etc), or do I have to specify all those sub categories too?

If so, I'm not sure how I might proceed, as there are a lot of categories and sub-categories within them that I want this modified product listing layout on - but it can't affect the rest of the site.

If this is the only way to go (adding them all manually) then ok... but could you suggest a code snippet to help me on my way please?
Cheers,
Rob

4 Mar 2008, 12:56 AM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Hiding product images under one category but not another

Here is one way. Replace 23 with your desired category id:

if (ereg("(^23$|^23_)",$cPath)) { //do something in category 23 and its subcats (replace 23 with your cat id)
  your code;
}
4 Mar 2008, 12:59 AM
#6
robgt avatar

robgt

New Zenner

Join Date:
Dec 2007
Posts:
27
Plugin Contributions:
0

Re: Hiding product images under one category but not another

Thank you for looking that up for me - very much appreciated!

I'll give it a go and post back if I have any further issues with it :D

Would I be right in thinking that to have the same effect on several top level categories and their sub cats, I could just keep adding the or pipe | and another pair of numbers, one with underscore?

i.e. (^23$|^23_|^45$|^45_) etc...
Cheers,
Rob

4 Mar 2008, 1:21 AM
#8
robgt avatar

robgt

New Zenner

Join Date:
Dec 2007
Posts:
27
Plugin Contributions:
0

Re: Hiding product images under one category but not another

Is it also possible to use the . character to simplify the regex slightly?

i.e. (^23.|^45.|^45_87_255.|^86_212.) etc...

Or is the . simply too greedy?
Cheers,
Rob

4 Mar 2008, 1:32 AM
#9
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Hiding product images under one category but not another

It's been a couple of years since I worked out how to use ereg(), but I tried a lot of things and found that the example is the simplest way possible to get the desired results (as far as I know).

You're welcome to test it, and maybe streamline it further.

I think the . allows for $cPath 234 as well as 23 and 23_56 etc, which is why it doesn't work.

4 Mar 2008, 1:37 AM
#10
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Hiding product images under one category but not another

I believe all you need to do is to put (int)$cPath

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

4 Mar 2008, 1:42 AM
#12
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Hiding product images under one category but not another

(int)129_90_80 -->129
Make sure you test first tho.

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

4 Mar 2008, 1:59 AM
#13
robgt avatar

robgt

New Zenner

Join Date:
Dec 2007
Posts:
27
Plugin Contributions:
0

Re: Hiding product images under one category but not another

I think the . allows for $cPath 234 as well as 23 and 23_56 etc, which is why it doesn't work.
Ah yes, of course...

I believe all you need to do is to put (int)$cPath
Could you put that in sample code as per previous please?
Much appreciated.
Cheers,
Rob

4 Mar 2008, 2:15 AM
#14
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Hiding product images under one category but not another

I've been searching w3schools and the PHP site, and can't find any reference or description for int(). It seems logical, but I'd like to know where to find official info on it.

OK, found it. Not a function int(), but type casting (int)xxxx.

4 Mar 2008, 3:49 AM
#15
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Hiding product images under one category but not another

Yest, it's a type casting, not a function

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

4 Mar 2008, 9:00 PM
#16
robgt avatar

robgt

New Zenner

Join Date:
Dec 2007
Posts:
27
Plugin Contributions:
0

Re: Hiding product images under one category but not another

Hi Glenn,
Your solution is definitely working for me - subcaegories are all using my modified template override page :)

My next hurdle is understanding how the table columns are created, as I want to not create that first (image) column at all - currently, it is returning the column but without contents, as thats how I've modified the code to react.
What I want to have happen is to not generate that column at all.

Here's my code so far...

	case 'PRODUCT_LIST_IMAGE':
	/*
	Start of modification
	 - Test for category here
	 - If category should not display image column - then hide column header here
	*/
	if (ereg("(^217_281_283$|^217_281_283_)",$cPath)) {
	  //hide image column
    	$lc_text = '';
	}  else {
	//show image column
		$lc_text = TABLE_HEADING_IMAGE;
		$lc_align = 'center';
		$zc_col_count_description++;
	}
	/*
	End of modification
	*/
	break;

I understand that entering a blank string (underneath //Hide column image comment) will not hide the column - it's just that having tried to wrap the whole CASE statement in my conditional code, I got wierd results on the page - like content from the final column was being rendered again in the first column of the next row.

I have the same conditional code inside the case 'PRODUCT_LIST_IMAGE': code further down the page too...

Pointers would be greatly appreciated as I'm not a PHP coder... :D
Cheers,
Rob

4 Mar 2008, 10:26 PM
#17
robgt avatar

robgt

New Zenner

Join Date:
Dec 2007
Posts:
27
Plugin Contributions:
0

Re: Hiding product images under one category but not another

I think I'm starting to understand the logic in your gallery category mod :D

Testing begins...
Cheers,
Rob

4 Mar 2008, 10:53 PM
#18
robgt avatar

robgt

New Zenner

Join Date:
Dec 2007
Posts:
27
Plugin Contributions:
0

Re: Hiding product images under one category but not another

Wow, cool...
I have managed to use your gallery category code Glen, modified to suit my needs, so that now the product image column is not displayed on the sub category pages I want it hidden on (as per the earlier regex - thanks again!).

My next hurdle is to figure out how to split the prices from the quantity and add to cart button - i.e. split them over two colums on the modified pages only.

While I'm scratching my head over this one, if someone has code to point me in the riht direction, feel free to post it :D
Cheers,
Rob

5 Mar 2008, 6:56 PM
#19
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Hiding product images under one category but not another

Are you wanting to put the price or add button in with another field that is displayed, or have a new field in just those categories?

In either case, you can duplicate the code that you want to switch locations, and then use the same test or its inverse (if (!ereg(...)) {... ) around the code to display it in the desired location and hide it in the other location.

If you want a new field with heading in these categories, you will need to commandeer an unused field like weight or manufacturer, put the code in it, and use another instance of the gallery category field hiding/showing. Also turn on that field in admin so it will be operated on.

6 Mar 2008, 12:31 PM
#20
robgt avatar

robgt

New Zenner

Join Date:
Dec 2007
Posts:
27
Plugin Contributions:
0

Re: Hiding product images under one category but not another

Thanks Glenn,
I think I followed that and will experiment later...

Are you wanting to put the price or add button in with another field that is displayed, or have a new field in just those categories?
I want to create a new column and populate it with the price values (inc and ex vat) - only the prices to be displayed in this new column - leaving the quantity and add to cart elements in their own column.

Cheers,
Rob