Category: Virtuemart
Hits: 21689

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active

Spider moonTask

Show a random product image as a category image.


I solved this at the Joomla template level.

So you need to perform the steps:

  1. Copy file components/com_virtuemart/views/category/tmpl/default.php to templates/YOURTEMPLATE/html/com_virtuemart/category/default.php, if doesn't exist.
  2. Copy file components/com_virtuemart/views/virtuemart/tmpl/default_categories.php to templates/YOURTEMPLATE/html/com_virtuemart/virtuemart/default_categories.php, if doesn't exist.
  3. Create file templates/YOURTEMPLATE/html/com_virtuemart/gruzsnippets/category_random_image.php with the following code:
  4. Edit templates/YOURTEMPLATE/html/com_virtuemart/category/default.php and find the place where the image is outputted. In VM 2.0.7d it's line 105:
    echo $category->images[0]->displayMediaThumb("",false);

    And add the following code above the line:
    include (dirname(__FILE__).DS.'..'.DS.'gruzsnippets'.DS.'category_random_image.php');
  5. Do p.4 for  templates/YOURTEMPLATE/html/com_virtuemart/virtuemart/default_categories.php also.


In the file templates/YOURTEMPLATE/html/com_virtuemart/gruzsnippets/category_random_image.php there is a line:

$ordering_is_set = false;

In my case I needed to use only the first product image, but the ordering in the #__virtuemart_product_medias table was not set. So I needed to make 2 DB queries instead of one to use the first image only.  You may set option to TRUE if you want to reduce the number of queries and don't care the product image ordering.

Found a typo? Please select it and press Ctrl + Enter.
FaLang translation system by Faboba