News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

VM 2.0 - Random images of category and subcategory

Started by rossosat, January 21, 2012, 11:31:32 AM

Previous topic - Next topic

rossosat

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.

rossosat

#1
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

Gruz

Your installable language for VM2: http://gruz.org.ua/virtuemart-language-files.html

bdimov

This doesn't work for me and in my site bellow product image is text:
Data provided by Pastebin.com - Download Raw - See Original

Gruz

Your installable language for VM2: http://gruz.org.ua/virtuemart-language-files.html

bdimov

And nothing... my category picture is missing...and after picture is this text....and this solution doesn't work for me....

bdimov

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....