News:

Support the VirtueMart project and become a member

Main Menu

VM3 - Use random product image as category image

Started by SoTrue, November 19, 2015, 20:18:09 PM

Previous topic - Next topic

SoTrue

I have seen this discussed for VM 2 but have tried this solution and it does not work unfortunately. The solution for VM2 is below:
Create a template override with categories.php and change the below around line 74:

echo $category->images[0]->displayMediaThumb("",false);

With
$productModel = VmModel::getModel('product');
$prod_in_category = $productModel->getProductListing(false, 1, false, true, true, true, $category->virtuemart_category_id);
$productModel->addImages($prod_in_category[0],1);
if(!empty($prod_in_category[0]->images[0])){
    echo $prod_in_category[0]->images[0]->displayMediaThumb("",false);
} else {
    echo $category->images[0]->displayMediaThumb("",false);


Or for a random image from the category us:

$productModel = VmModel::getModel('product');
$prod_in_category = $productModel->getProductsInCategory($category->virtuemart_category_id);
$sel = array_rand($prod_in_category);
$productModel->addImages($prod_in_category[$sel],1);
if(!empty($prod_in_category[$sel]->images[0])){
    echo $prod_in_category[$sel]->images[0]->displayMediaThumb("",false);
} else {
    echo $category->images[0]->displayMediaThumb("",false);
}


I have tried both of the code snippets above but i just get an empty page so am guessing something may have changed between versions. Can anyone advise? I am using Joomla 3.4.5 and Virtuemart 3.0.9.

Best Regards
Donna

beltoforion

hey I want this in the new version as well. I am investigating how to do it too.
wanting to learn to create good templates

pinochico

Quotewanting to learn to create good templates

if you really mean it, then don't waiting answer from forum, but you must trying self.
Again, again and again.

Now I give you the best option for your learning: I don't send you instructions.
You can try self and after 14 days you send me info, what do you learn - send me result.

www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

beltoforion

that signature I have not changed since a long time ago but I am a persistent fellow so I dont mind learning :D show me
wanting to learn to create good templates