hi guys, would be amazing if was possible to use random images of products in each category as category images, i don't know "vm 2.0" structure and is very difficult for me change some code. Can you help me? I tried to import 30000 products with csvi beta 3, all works perfectly but i have too many categories that are all without images.
Thank you, great works, and many thanks to Roland also.
For vm 1.1.2 there was a modification that works but vm 2.0 structure is different and there isn't categorychildlist.php, so i can't try this code.
After:
<?php
if ( $category["category_thumb_image"] ) {
echo ps_product::image_tag( $category["category_thumb_image"], "alt=\"".$category["category_name"]."\"", 0, "category");
echo "<br /><br/>\n";
}
Add:
else {
$category_a = array($category["category_id"]);
$db2 = new ps_DB;
while(list($key,$val) = each($category_a)) {
$q2 = "SELECT category_child_id FROM #__{vm}_category_xref,#__{vm}_category";
$q2 .= " WHERE #__{vm}_category_xref.category_parent_id=$val";
$q2 .= " AND category_id=category_child_id AND category_publish='Y'";
$db2->setQuery($q2);
$db2->query();
while ($db2->next_record()) {
array_push($category_a,$db2->f("category_child_id"));
}
}
$product_a = array();
foreach($category_a as $val) {
$q2 = "SELECT #__{vm}_product_category_xref.product_id as products";
$q2 .= " FROM #__{vm}_product, #__{vm}_product_category_xref";
$q2 .= " WHERE #__{vm}_product_category_xref.category_id=$val";
$q2 .= " AND #__{vm}_product.product_id=#__{vm}_product_category_xref.product_id";
$q2 .= " AND #__{vm}_product.product_publish='Y'";
$db2->setQuery($q2);
$db2->query();
while ($db2->next_record()) {
array_push($product_a,$db2->f("products"));
}
}
if ($product_a) {
$rand_key = array_rand($product_a);
$category_image = $product_a[$rand_key];
$q2 = "SELECT product_thumb_image FROM #__{vm}_product";
$q2 .= " WHERE product_id='".$category_image."' ";
$db2->setQuery($q2);
$db2->query();
echo ps_product::image_tag( $db2->f("product_thumb_image"), "alt=\"".$category["category_name"]."\"", 0, "product");
echo "<br /><br/>\n";
}
}
Mod edit: bump message removed. http://forum.virtuemart.net/index.php?board=66.0
Have a look here: http://gruz.org.ua/en/about-joomla/34-virtuemart/53-vm-20-random-images-of-category-and-subcategory.html
There is my solution at the link.
This doesn't work for me and in my site bellow product image is text:
Data provided by Pastebin.com - Download Raw - See Original
And?
And nothing... my category picture is missing...and after picture is this text....and this solution doesn't work for me....
I tried this again in other site but again it isn't working for me... The picture is the same (no picture) and this code doesn't put the picture and change it in category....