VirtueMart 1.1.x [ Old version - no longer supported ] > Products, Prices, Tax and Categories VM 1.1

Shows all products from subcategories in parent categories (all branch)

(1/8) > >>

Mav3rick:
Problem with not showing subcategories when you enter to category. I couldn't find any solution on the internet so I coded my solution. Here it go:

---------------------------------------------------------------
file

--- Code: ---administrator/components/com_virtuemart/html/shop_browse_queries.php
--- End code ---

---------------------------------------------------------------

after

--- Code: ---mm_showMyFileName( __FILE__ ); (about row 20)
--- End code ---


insert this code

--- Code: ---class children_class{
    var $cat_children; // where clause
    var $db_browse; // db controler

    function get_children($parent){
        $q  = "SELECT `category_child_id` FROM `#__{vm}_category_xref` WHERE `category_parent_id`=$parent";
        $this->db_browse->query($q);
        $cat_children_id = array();
    while ($this->db_browse->next_record()){
        array_push($cat_children_id,$this->db_browse->f("category_child_id"));
    }
    foreach($cat_children_id as $cat_child_id){
        $this->cat_children .= " OR `#__{vm}_product_category_xref`.`category_id`=$cat_child_id";
        $this->get_children($cat_child_id);
    }

    return $this->cat_children;
    }
}

--- End code ---
---------------------------------------------------------------

after

--- Code: ---// Filter Products by Category (about row 70)

--- End code ---

replace this code

--- Code: ---
if( $category_id ) {
if( !empty( $search_this_category ) && (!empty( $keyword ) || !empty( $manufacturer_id ) )) {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
} elseif( empty( $keyword ) && empty( $manufacturer_id )) {
$where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
}
}

--- End code ---
by this

--- Code: ---if( $category_id ) {
        if( !empty( $search_this_category ) && (!empty( $keyword ) || !empty( $manufacturer_id ) )) {
               $where_clause[] = "`#__{vm}_product_category_xref`.`category_id`=".$category_id;
    } elseif( empty( $keyword ) && empty( $manufacturer_id )) {
         $cat_child = "(`#__{vm}_product_category_xref`.`category_id`=".$category_id."";

           // Find Child Category Products
           $children = new children_class;
           $children->db_browse = $db_browse;
           $cat_child .= $children->get_children($category_id);
           $cat_child .= substr($this->cat_children, 0, -3);
           $cat_child .= ")";
           $where_clause[] = $cat_child;
       }
}

--- End code ---
---------------------------------------------------------------

After save the file it will shows recursively all products from subcategories and their subcategories  in parent cateogy to the end of the branch.
---------------------------------------------------------------

all edited file

--- Code: ---http://pastebin.com/iP5nzkud

--- End code ---
Sorry for my english  :-[

schwanengesang:
WOW thanks so much! I've been trying to figure out how to show all my products!  ;D ;D ;D cheers  :D

iamalive:
Thanks a lot! This saved my bacon.

Virtuemart team: Can you build this in? Categories used to be shown and somehow this bit seems to have gone missing in the latest (1.1.9) Version.

Regards

David

anaffelici:
Perfect!  Thanks a Lot!

ann_rk:
Is there a way to get it to sort by subcategory name and the add the name above the section?

So for example it shows
Cherry Antique Cabinets
Cherry Antique Base Cabinets
Products of Cherry Antique Base Cabinets
Cherry Antique Wall Cabinets
Products of Cherry Antique Wall Cabinets

Currently I just have one long list of products on the category browse page.
http://www.aaahomedesign.com/index.php?option=com_virtuemart&page=shop.browse&category_id=3&Itemid=6

Any assistance would be greatly appreciated.
Sincerely,
Ann

Navigation

[0] Message Index

[#] Next page

Go to full version