VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: rossosat on January 21, 2012, 11:31:32 AM

Title: VM 2.0 - Random images of category and subcategory
Post by: rossosat on January 21, 2012, 11:31:32 AM
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.
Title: Re: VM 2.0 - Random images of category and subcategory
Post by: rossosat on January 21, 2012, 11:47:28 AM
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
Title: Re: VM 2.0 - Random images of category and subcategory
Post by: Gruz on May 27, 2012, 13:01:48 PM
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.
Title: Re: VM 2.0 - Random images of category and subcategory
Post by: bdimov on December 08, 2012, 02:42:48 AM
This doesn't work for me and in my site bellow product image is text:
Data provided by Pastebin.com - Download Raw - See Original
Title: Re: VM 2.0 - Random images of category and subcategory
Post by: Gruz on December 08, 2012, 09:42:45 AM
And?
Title: Re: VM 2.0 - Random images of category and subcategory
Post by: bdimov on December 08, 2012, 14:15:14 PM
And nothing... my category picture is missing...and after picture is this text....and this solution doesn't work for me....
Title: Re: VM 2.0 - Random images of category and subcategory
Post by: bdimov on March 16, 2013, 11:35:34 AM
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....