Jump to content

Change product display background color as per product category.


Recommended Posts

I am working on a shop for a puppy breeder, and would like to customize the color of the product container (in featured products as well as in the category display) to match the gender of the puppy (pink/female, blue/male).

 

I'm at a little bit of a loss on where to start. I know that I can create Male/Female associations and at least capture the data that way when a puppy is entered, but how do I use that information to change the background color of the product container?

 

Thanks in advance for any help.

Link to comment
Share on other sites

What I've done so far is to add Gender as a feature. I realize this at least gets the information on to the page, but I believe what I need to do is repurpose that information into an additional part of the page, specifically the background portion of the product container CSS. I feel like it would be a hack, but if I could create two images (male.jpg and female.jpg) and just set those images as the colors I want, I can import the gender in at the appropriate place and cause the code to grab the appropriate image.

 

I'm at a loss as to how to get product-list.tpl to grab information from the features db. As you can probably tell, I know next to nothing about how to work with db information.

 

The portion of product-list.tpl that I'm trying to customize is

 

<div class="product-container" style="background:none;" itemscope itemtype="http://schema.org/Product">
<div class="left-block">
<div class="product-image-container" style="background:none;">
 
I've modified the inline CSS to ensure these are the lines I need to change. I need them both to pull the same information depending on what the Gender field is set to.
Edited by prestandrew (see edit history)
Link to comment
Share on other sites

Since no one else has offered any suggestions I will suggest how I would try this -- I'm not very experienced so not sure if this will help.

 

I have a few products that require that the product page be different. To accomplish this I just used a conditional -- basically if the product id = one of 3 numbers my alternative elements get displayed and if the product id does not equal those then that part of the code gets skipped and the standard product page is displayed.

 

That would solve your problem if you had a fixed product list but it won't work for your situation since as you add new animals they will all have new product ids. So you need to find something else to make the conditional. I assume you can query features and use that. I know some modules use UPC code field so you probably could use that if features are not an option.

 

So my approach would be to create a male and female entry in the css file then use whatever conditional I could get to work to alternate between which of the two css styles get used. 

 

That is pretty vague and untested but the best I can do without devoting time that I don't really have to spare.

Link to comment
Share on other sites

Hi,
 
You can use smarty.
Assign a specific id/class to your <div>, <img> etc. depending on the category.

For example : 

<div class="myProduct category-{if isset($category->id)}{else}noCategory{/if}"</div>

And in your CSS you can apply style in function

For example :

 .products_block.category-57{
background: #b9e1a2;}
Link to comment
Share on other sites

 

Hi,

 

You can use smarty.

Assign a specific id/class to your <div>, <img> etc. depending on the category.

 

For example : 

<div class="myProduct category-{if isset($category->id)}{else}noCategory{/if}"</div>

And in your CSS you can apply style in function

 

For example :

 .products_block.category-57{
background: #b9e1a2;}

 

Thanks for the help. I'm sure this is probably the answer I'm looking for, but I can't make it work. When I put that code in, the rendered html is just "category-" and I have no clue how to make it change as a result of a specific category...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...