Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Different header, logo, colors and other per category


piller

Recommended Posts

Posted

Hello,

 

Does anyone know how to dynamically change design objects every time a different category is clicked?, for example the logo, or header, or colors?.

I have this clothes store, and have three main categories, "Man", "Woman" and "Kids", and need to change the look of the site depending on what category the visitor is in.

 

I normally integrate a template to my OS Commerce, so it make more sense to do this. However, I believe this question may apply for the regular theme as well.

 

I'd really appreciate any contribution.

 

Thanks,

 

Piller

Posted

In it's simplest form it would be best to create stylesheets for each "look".

 

To alternate between them, you'd find the line for your stylesheet in each of your files, probably looks like this:

 

<link rel="stylesheet" type="text/css" href="stylesheet.css">

Then replace it with code something like this:

 

<?php
// kids 
$style_flag = false;
if ( strpos($cPath, '11') === 0 ) {
 echo '<link rel="stylesheet" type="text/css" href="stylesheetkids.css">';
 $style_flag = true;
}

// womens
if ( strpos($cPath, '22') === 0 ) {
 echo '<link rel="stylesheet" type="text/css" href="stylesheetwomen.css">';
 $style_flag = true;
}

// mens
if ( strpos($cPath, '33') === 0 ) {
 echo '<link rel="stylesheet" type="text/css" href="stylesheetmen.css">';
 $style_flag = true;
}

// default
if ( ! $style_flag ) {
 echo '<link rel="stylesheet" type="text/css" href="stylesheet.css">';
}
?>

In that code you'd have to replace the numbers '11', '22', and '33' with what your categories are.

 

Hopefully that would cover most of your changes.

 

One it wouldn't cover would be the header banner.

 

If you wanted to alternate it, the code would be in /catalog/includes/header.php.

 

Change this code (your's will have a different image name) :

 

	<td valign="middle"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image(DIR_WS_IMAGES . 'oscommerce.gif', 'osCommerce') . '</a>'; ?></td>

To something like:

 

<?php
// kids 
$style_flag = false;
if ( strpos($cPath, '11') === 0 ) {
 $banner_name = 'kids.gif';
 $style_flag = true;
}

// womens
if ( strpos($cPath, '22') === 0 ) {
 $banner_name = 'womens.gif';
 $style_flag = true;
}

// mens
if ( strpos($cPath, '33') === 0 ) {
 $banner_name = 'mens.gif';
 $style_flag = true;
}

//default
if ( ! $style_flag ) {
 $banner_name = 'default.gif';
}
?>
<td valign="middle"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image(DIR_WS_IMAGES . $banner_name, 'YOUR ALT TEXT HERE') . '</a>'; ?></td>

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

  • 3 weeks later...
Posted

This has been really helpful Germ.

 

Thanks a lot.

 

Do you know how can I handle this so the respective design remains when entering a product description?.

I mean, when someone enter the "Women" category, URL contains the "cPath" variable, which is the one I am validating for selecting the proper stylesheet, but once the user click on a product the URL completely changes to something like this: /product_info.php?products_id=81

 

Since the product ID are consecutive assigned, I guess there is no way to validate this variable. But I was hoping you have an idea for this. (Maybe including the cPath variable in the product URL).

 

One more time, thanks a lot for your help. I will officially start the site.

 

Piller

Posted

I believe it would still be possible to associate a product to a category even without the presence of cPath in the URL.

 

$cPath is a global variable accessible at any time in any module.

 

I have a test area on my site that displays the value of $cPath in the footer. Even on the product info page (with no cpath in the URL) it's still there and still correct.

 

It's usually in the format of a string numerical value like xx, where xx is the category value.

 

If the category has sub-categories. then it's in the format of xx_yy, where xx is the category value and yy is the sub-category value.

 

I hope this helps.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Posted

I am pretty sure it will help.

 

I will let you know.

 

Thanks a lot for your help!

 

Piller

Archived

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

×
×
  • Create New...