News:

Looking for documentation? Take a look on our wiki

Main Menu

Different Background for Each Product

Started by Jack Stiles, August 21, 2018, 20:30:01 PM

Previous topic - Next topic

Jack Stiles

So I have one more thing here... Lets say I only have like 5 products on a whole shop but I really need every one of them to be well designed. Is there a way to use a different background color for each product? Didn't find such a thing here on forum...

Iam on latest Joomla and latest VM

PRO

for category page?

sublayouts/products.php

change this
    // Show Products ?>
   <div class="product vm-col<?php echo ' vm-col-' . $products_per_row . $show_vertical_separator ?>">

to this

    // Show Products ?>
   <div class="color<?php echo $product->virtuemart_product_id ?> product vm-col<?php echo ' vm-col-' . $products_per_row . $show_vertical_separator ?>">

then you will have a class set for each product


.colorTHE_PRODUCT_ID

Then just style it in your style sheet like you want.

Jack Stiles

OK great  :) - one question though. I am not really sure how sublayouts work but - if I change anything in it - does the update overwrite it?

Jack Stiles

Quote from: PRO on August 21, 2018, 21:07:10 PM
for category page?

Nah not really - I need to be able to change is on a product detail page - the whole page background.

GJC Web Design

same idea but on the over ridden product details template
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Jack Stiles

So this doesn't work. It always adds "color" to a class but no ID behind it :-(

Jack Stiles

I should add that I cannot add this to a product details because I need to adjust the whole background on a whole product page so I added this as a body class to my template index.php. But it wasnt working in product description as well. I always adds only COLOR which means its unable to understand this: <?php echo $product->virtuemart_product_id ?>

Jörgen

It should work in sublayout products.php. You must be in the right context. Within this for example:

foreach ( $products as $product ) {

Otherwise $product may be meaningless.

use

print_r($product);

to see the contents of product.


Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Jack Stiles

Well I used another approach. But thank you guys cause this thread help me to understand how to proceed.

What I did was this - each product has a unique url so I did this:

color<?php if(strpos($_SERVER['REQUEST_URI'], 'productname') !== false):?>productname<?php else: ?><?php endif; ?>


Studio 42

Quote from: Jack Stiles on August 22, 2018, 16:22:02 PM

color<?php if(strpos($_SERVER['REQUEST_URI'], 'productname') !== false):?>productname<?php else: ?><?php endif; ?>

One of the poorest code i have see!

GJC Web Design

<div class="color<?php echo $this->product->virtuemart_product_id ?>" >

if your on details
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Jack Stiles

Quote from: Studio 42 on August 22, 2018, 22:59:02 PM
One of the poorest code i have see!

Well thank you for letting me know it was really helpful  :o

Studio 42

Jack, i think this helps you.
You have solution using virtuemart product id, this is set in all case when you show a product.
IF you need to use it in the template directly and not in virtuemart, you can get it from the input query.
see in general for joomla https://docs.joomla.org/Retrieving_request_data_using_JInput
in your case :
<?php 
$jinput 
JFactory::getApplication()->input;
$id$jinput->getInt('virtuemart_product_id',null);
if(empty(
$id)) $id='';
?>

<div class="color<?php echo $id ?>">





Jack Stiles

Quote from: Studio 42 on August 23, 2018, 10:25:31 AM
Jack, i think this helps you.
You have solution using virtuemart product id, this is set in all case when you show a product.

Thanks! Works as a charm!  ;)