X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Load different style sheets for main categories (https://forum.x-cart.com/showthread.php?t=63616)

tech@vrve.co 05-14-2012 07:02 AM

Load different style sheets for main categories
 
I need to change the style sheet and store logo based on different main categories.
I am using the latest Version 4.5.0
I need the new style sheet to persist in all sub categories and products.
I know it can probably be done with an if...else block but need help.
Thanks

totaltec 05-14-2012 07:12 AM

Re: Load different style sheets for main categories
 
Not an easy request unfortunately. I am thinking about how this might be accomplished...

It is easy to write an if statement for the category page itself in smarty:
PHP Code:

{if $cat eq 1}
 Do 
this
{elseif $cat eq 2}
 Do 
that
{/if} 


Getting it to stick on all the sub cats and products is going to be the tough part. You will have to write some php code that looks at the entire category structure, then determines which main category this particular product or category is in. Certainly not impossible, but a little daunting.

tech@vrve.co 05-14-2012 07:29 AM

Re: Load different style sheets for main categories
 
What if i had a comma separated list of cat IDs.
If $catid IN '22,23,25,35" .........

Where would I put this if statement, in which file?
many thanks

cflsystems 05-14-2012 07:53 AM

Re: Load different style sheets for main categories
 
I have done this for a client. You need to get your main cats assigned to smarty at all times with the one being used assigned as well so you can base the css file load on it. Then in templates you just use an if statement which css file to load. It has to be done in php

tech@vrve.co 05-14-2012 08:11 AM

Re: Load different style sheets for main categories
 
Thanks. I don't fully understand what you mean by 'cats assigned to smarty at all times'.
Appreciate your help here.
Thanks

cflsystems 05-14-2012 08:14 AM

Re: Load different style sheets for main categories
 
Your php code have to pick the main categories you want to use and assign them to smarty on each and every page, as well as specifically point out which one is to be used.

tech@vrve.co 05-14-2012 08:30 AM

Re: Load different style sheets for main categories
 
Sorry still don't understand.
Is this something you could do for me?
Thanks

cflsystems 05-14-2012 08:44 AM

Re: Load different style sheets for main categories
 
Yes I can code this for you. Email me with details what exactly is needed

kdw 05-15-2012 07:23 AM

Re: Load different style sheets for main categories
 
Had an idea!
With clean URLs set the URL can/will contain the category name?
What smarty or PHP code would look for a word inside the URL and load image/css based on what it finds eg. {if strpos($smarty.get.page, "SWCHS.html") !== false}
<p>SWCHS image/CSS</p>
{else}
default image/css
{/if}

Would something like that work?
If so what code should I use as my example is not finding SWCHS
Keith

totaltec 05-15-2012 07:31 AM

Re: Load different style sheets for main categories
 
Have you tested by simply putting {$smarty.get.page} and seeing what the results are? I believe that variable shows the result of _get requests.

Try {$smarty.server.REQUEST_URI}:
PHP Code:

{if strpos($smarty.server.REQUEST_URI"SWCHS.html") !== false}
  <
p>SWCHS image/CSS</p>
{else}
  default 
image/css
{/if} 


kdw 05-15-2012 07:46 AM

Re: Load different style sheets for main categories
 
This seeems to work -
{if strpos($smarty.server.REQUEST_URI, "SWCHS") !== false}
<p>SWCHS image/CSS</p>
{else}
default image/css
{/if}

Needs proper testing but seems like a possible simple solution.

Where and in what template is this needed to load override CSS?

many thanks for your help. Much appreciated.

totaltec 05-15-2012 07:53 AM

Re: Load different style sheets for main categories
 
No sweat, glad to help.

Look in:
/common_files/customer/service_css.tpl - or your custom skin directory instead of common_files.

Look a how it calls in the altskin near the bottom:
PHP Code:

{if $AltSkinDir}
  {
load_defer file="css/altskin.css" type="css"

If you call another style sheet after this, with the same classes defined, then the styles from main.css and altskin.css should be overwritten. I say "should be" because I have never tried it.

kdw 05-15-2012 08:03 AM

Re: Load different style sheets for main categories
 
Thanks.
My simple solution is fine until you get to product page. The category name is then not present in the URL.
Plan B?
Keith

kdw 05-15-2012 08:10 AM

Re: Load different style sheets for main categories
 
I have just realised I can manually add the correct category name to the Clean URL.
It might just solve my problems. No doubt your coded solution would be more elegant?
Can you see any real problem with my approach here?
Thanks

totaltec 05-15-2012 09:26 AM

Re: Load different style sheets for main categories
 
I tell you what, I think the category name not being present represents an SEO problem. But that's just my opinion. I don't see a problem, if the solution works, than it works.

Coding the solution in PHP would be more elegant and consistent, without worrying about changing url's around. Another solution to this issue that just occurred to me, is to put a select box on category and product pages, "theme" and then just set the proper themes based on the contents of that box. You could even do it with extra fields....maybe.

tartaglia 05-15-2012 09:54 AM

Re: Load different style sheets for main categories
 
Not to get "dreamy" here, but it is a shame this is sooo hard in XC. I have had a LC store running for 6 yrs and this functionality, to define different layouts for the subcategory, product list, and product details and to decide whether a particular subcat would inherit from above in the hierarchy, etc. has been built in as far back as I can remember.

I feel you pain in wanting this functionality back as I move towards XC 4.5.0

cherie 05-23-2012 01:35 PM

Re: Load different style sheets for main categories
 
Quote:

Originally Posted by tech@vrve.co
What if i had a comma separated list of cat IDs.
If $catid IN '22,23,25,35" .........

You can do this in Smarty:
PHP Code:

{assign var=myCats value=","|explode:"22,23,25,35"}
{if 
in_array($catid$myCats)} 


kdw 05-23-2012 11:59 PM

Re: Load different style sheets for main categories
 
Thanks cherie.
I will have 6 main categories, 2 main sub cats in those and 20 or so categories in each of the 2 sub cats so quite a few to add to array.
Also if client added a category it would need adding to code. Is there a way of testing for the main category only so that all sub and sub sub cats inherit the style and logo?

cherie 05-24-2012 07:56 AM

Re: Load different style sheets for main categories
 
I use this on product or category pages to get the top category id of the current location:

PHP Code:

{assign var=topId value="="|explode:$location.1.1}
{
assign var=topId value=$topId|@end


totaltec 05-24-2012 08:08 AM

Re: Load different style sheets for main categories
 
Elegant and simple solution Cherie! Thanks

kdw 03-25-2014 04:35 AM

Re: Load different style sheets for main categories
 
Hi again
I have
{if $topId eq 52}
{load_defer file="css/shoes.css" type="css"}
{/if}
in service_css.tpl
and
{elseif $topId eq 52}
<img src="{$AltImagesDir}/schools/school_shoes.png" alt="" />
in head.tpl


Works fine.
This changes the styles in the product pages too which is what is needed.
Now I need to do the same for a sub category?
Have different styles and main logo for different sub cats.

I can use if $catid and styles change when I go to that category page BUT when I then click on a product the style reverts to the main category style.
Can anyone advise what to use so that the sub cat style is maintained as long as it is when using if $topid ie. through cat pages, product listing pages and product details page.

Assuming this is possible of course!


Thanks

cherie 03-25-2014 09:08 AM

Re: Load different style sheets for main categories
 
Not clear on what you are looking for. Are you no longer wanting to check the top categoryid (topId) or are you ending up on a product page that does not have the correct topId?

If the subcategories and products are under the same topId then they should maintain the style if you are keying off topId.

kdw 03-25-2014 09:17 AM

Re: Load different style sheets for main categories
 
Thanks for getting back on this.
At the moment I have different logo and style sheet working based on $topid.
Works fine and the chosen image and stylesheet stays in place through category and product pages.
However I would like to be able to have a different image and style sheet based on the sub category, overriding the top level once in the sub category and it's product pages.
Is there a $subcatid or something I can use like I am using $topid?

Here is the site
http://www.graypalmer.co.uk/store/

EG. Default styles show when entering shop.
Clicking a main category changes img and stylesheet and this persists through sub cats to product details etc.
On some sub cats however I now want to also override the main img and styles.
Hope that clarifies?
Many thanks.
Keith

cherie 04-01-2014 04:53 PM

Re: Load different style sheets for main categories
 
Wouldn't post 17 do the trick?

If you are looking for $catid you could see if $current_category or $product.categoryid will do the trick. Check the Smarty variables for the page you are on to see if something looks like it might work.

totaltec 04-02-2014 05:18 PM

Re: Load different style sheets for main categories
 
@tech990

Dude, have you been working on this for 2 years? :-)


All times are GMT -8. The time now is 03:27 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.