Styling a product page based on custom field

  • Posts: 87
  • Thank you received: 5
  • Hikashop Business
13 years 1 month ago #49552

Hi,
I am considering buying Hikashop Business for a new project I am working on. I have read through some of the documentation and so far it looks like a really great product which can do most of the things I need straight from the box.
There is one thing I'd like to be able to do that I think requires some custom code though, and I would like to know if it is at all possible to do before I decide to buy the Business version.

I'd like to be able to style some elements on my product description pages based on a specific characteristic of my product. From what I've read so far I think I will have the best chance of doing so by using a custom field on the products. What I would like to achieve is this: Imagine my shop sells products in two categories: bicycles and scooters for example. And all products come in three different colors: yellow, blue and green. I want to be able to have the page background ans some text change color depending on the color of the selected item, preferably by adding a custom class to the <body> tag of the page. So when I open the product page of a yellow bicycle the background turns yellow and some other stuff on the page is styled yellow. What I open the product page for a yellow scooter the same change happens (stuff turns yellow). When I open the product page for a green bicycle or scooter the same changes happen but now with the color green, same for blue, etc.

I think this should be possible to do by using php to tell the page to add a class (.yellow or .green or .blue) to the body tag depending on the custom fields associated with the current product. But I don't know is this is possible and if so exactly how to do this.

Please Log in or Create an account to join the conversation.

  • Posts: 83933
  • Thank you received: 13588
  • MODERATOR
13 years 4 weeks ago #49639

Hi,

Yes, that's possible with a custom product field and then a few lines of code in your template file:

if(JRequest::getInt('cid')){
 if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;
 $class = hikashop_get('class.product');
 $product = $class->get(JRequest::getInt('cid'));
 echo 'background-color:'.@$product->color;
}

Last edit: 13 years 4 weeks ago by nicolas.

Please Log in or Create an account to join the conversation.

  • Posts: 87
  • Thank you received: 5
  • Hikashop Business
13 years 4 weeks ago #49703

Wow, thanks for the very quick reply!
I haven't bought the business edition yet, so I can't try it out right now, but I'll do so asap.

Is it possible to use a similar method to show the text for the product thumbnails in a category page in the color of the product? So can I add some php to request the color property (from a custom field) for each product shown as a thumbnail on a category page and add a class to the text?

Thanks a lot so far. This kind of product support is great!

Please Log in or Create an account to join the conversation.

  • Posts: 83933
  • Thank you received: 13588
  • MODERATOR
13 years 4 weeks ago #49814

Everything is possible but it's a bit more complicated.

You'll have to edit the file "listing_div" of the view "category" via the menu Display->Views and use $this->row->color in the foreach

Please Log in or Create an account to join the conversation.

Time to create page: 0.059 seconds
Powered by Kunena Forum