User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

Spider moonTask

Show a random product image as a category image.

Solution

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.

Options

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.

Comments   

Guest
# Guest 2012-12-12 15:46
Thanks a lot ! That's perfect !!
Guest
# Guest 2012-12-25 18:39
could you make a slight mod to this where i would only have 1 alternative image and that one would be functioning as a rollover swap.
regards.
gruz
# gruz 2012-12-25 19:19
Sorry, I have no time to play around with it. It doesn't seem to be so "slight" as you expect.
MySite
# MySite 2013-08-23 08:54
Hi,

This is now working to me....
I'm with a new version of virtuemart 2.0.20b and it is now working.
gruz
# gruz 2013-08-23 10:25
Now working or not working?
al_bel
# al_bel 2013-10-08 14:02
Perfect job. Works great. Virtuemart 2.0.24b out from the box.

Please register to post comments.

Found a typo? Please select it and press Ctrl + Enter.
FaLang translation system by Faboba
ОУН-УПА: легенда спротиву Українська Дивізія «Галичина» Зиновій Книш: спогади й матеріали до діяння УВО і ОУН Реаніматор електронних текстів Забуттю не підлягає 1917-1991

See a typo?

Select the text block and press

CTRL+Enter

Comments

  • NotificationAry - get emails on Joomla content is submitted, added or changed

    gruz gruz 22.05.2019 12:02
    http://gruz.ml/images/x/2019_05_22_12_00_08_lm.png

    Read more...

     
  • NotificationAry - get emails on Joomla content is submitted, added or changed

    Berndi Berndi 22.05.2019 11:35
    How can I activate this? It istn't shown on my Joomla! installation (3.9.6) ...

    Read more...

     
  • NotificationAry - get emails on Joomla content is submitted, added or changed

    gruz gruz 22.05.2019 10:50
    It's implemented http://gruz.ml/images/x/2019_05_22_10_28_53_oa.png

    Read more...

     
  • NotificationAry - get emails on Joomla content is submitted, added or changed

    Berndi Berndi 22.05.2019 10:15
    Hello Gruz, thank you for this great Joomla!extension. Would it be possible to give the writer the ...

    Read more...

     
  • NotificationAry - get emails on Joomla content is submitted, added or changed

    gruz gruz 30.04.2019 12:50
    1. You can build mail body using PHP. So you are able to write PHP code in a way to check the language ...

    Read more...