Author Topic: Shows all products from subcategories in parent categories (all branch)  (Read 58258 times)

Mav3rick

  • Beginner
  • *
  • Posts: 7
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: [Select]
administrator/components/com_virtuemart/html/shop_browse_queries.php
---------------------------------------------------------------

after
Code: [Select]
mm_showMyFileName( __FILE__ ); (about row 20)

insert this code
Code: [Select]
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;
    }
}
---------------------------------------------------------------

after
Code: [Select]
// Filter Products by Category (about row 70)

replace this code
Code: [Select]

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;
}
}
by this
Code: [Select]
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;
       }
}
---------------------------------------------------------------

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: [Select]
http://pastebin.com/iP5nzkud
Sorry for my english  :-[

schwanengesang

  • Beginner
  • *
  • Posts: 1
WOW thanks so much! I've been trying to figure out how to show all my products!  ;D ;D ;D cheers  :D

iamalive

  • Jr. Member
  • **
  • Posts: 133
  • Life is good
    • Websites4U
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
David Jakob
..stressfreie Webseiten von http://websites4u.ch...

anaffelici

  • Beginner
  • *
  • Posts: 8
Perfect!  Thanks a Lot!

ann_rk

  • Beginner
  • *
  • Posts: 1
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

swordandstone

  • Beginner
  • *
  • Posts: 1
Re: Shows all products from subcategories in parent categories (all branch)
« Reply #5 on: August 01, 2011, 20:38:22 pm »
I just registered to thank you... THANK YOU! 8)

fonza

  • Beginner
  • *
  • Posts: 3
Re: Shows all products from subcategories in parent categories (all branch)
« Reply #6 on: August 04, 2011, 10:44:29 am »
Hello,
I have question: is posssible to adjust numbers of sub categories in one row?

balai

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1511
Re: Shows all products from subcategories in parent categories (all branch)
« Reply #7 on: August 04, 2011, 11:11:22 am »
Thank you

nickbkmediagroup

  • Beginner
  • *
  • Posts: 1
Re: Shows all products from subcategories in parent categories (all branch)
« Reply #8 on: August 04, 2011, 22:47:59 pm »
Is there anyway to show only sub categories and NOT products below? Thanks.

Mav3rick

  • Beginner
  • *
  • Posts: 7
Re: Shows all products from subcategories in parent categories (all branch)
« Reply #9 on: August 08, 2011, 19:21:12 pm »
Sorry, I dont know what you mean.. Can you explain it? I think it would be possible, it isnt hard to edit this part of virtuemart.

fonza

  • Beginner
  • *
  • Posts: 3
Re: Shows all products from subcategories in parent categories (all branch)
« Reply #10 on: August 10, 2011, 12:40:39 pm »
I think nickbkmediagroup mean that on page is just sub categories whitout all products of this sub categories.

Mav3rick

  • Beginner
  • *
  • Posts: 7
Re: Shows all products from subcategories in parent categories (all branch)
« Reply #11 on: August 11, 2011, 00:31:42 am »
Like only links to subcategories or what? Sorry, I really cant imagine what you mean "only subcategories". I would like to help you, bud I cant understand..  :(

vmbuilder

  • Beginner
  • *
  • Posts: 21
Re: Shows all products from subcategories in parent categories (all branch)
« Reply #12 on: August 12, 2011, 10:01:29 am »
Thanks Mav3rick - my sub-cat's are displaying now, which is brilliant.

I'd prefer this page to ONLY show the sub-category headings though, and not a list of their products below. Any ideas anyone?

@nickbkmediagroup - any luck with this..?
Joomla 1.5.23 VM 1.1.19

Joomlaapp

  • Beginner
  • *
  • Posts: 1
Re: Shows all products from subcategories in parent categories (all branch)
« Reply #13 on: August 12, 2011, 11:28:00 am »
After looking around for a solution to displaying subcategories in a different way, I think Mav3rick is our only hope to help us out.

Current VM set-up:
(1) Power Tools [Parent Category]
--- 1. Chain Saw
--- (2) Outside Tools [Sub Category]
------ 2. Leaf Blower
--- (2) Inside Tools [Sub Category]
------ 3. Power Drill

These are preset products, parent categories, and subcategories. However, when I attempt to create my own parent category, subcategory, and sub-subcategory, the links don't even show after I click on my own parent category. Instead, I get this category is empty.

Desired VM set-up:
(1) Computer Desks [Parent Category]
--- (2) Wood [Subcategory]
------ (3) Oak [Sub-subcategory]
--------- 1. oak table one [Product]
--------- 2. oak table two [Product]
--------- 3. oak table three [Product]
------ (3) Redwood [Sub-subcategory]
--------- 4. redwood table one [Product]
--------- 5. redwood table two [Product]
--------- 6. redwood table three [Product]
------ (3) ect...
--- (2) Metal [Subcategory]
------ (3) Steel [Sub-subcategory]
--------- 7. steel table one [Product]
--------- 8. steel table two [Product]
------ (3) Titanium [Sub-subcategory]
--------- 9. titanium table one [Product]
--------- 10. titanium table two [Product]
------ (3) ect...

Basically, this desired set-up displays subcategories as links to more subcategories and only the lowest level subcategory displays the actual products.

I'm a day old in the VM scene so I don't know if it's an either/or problem, but I can't seem to have my VM function the way I explained.

Thanks to Mav3rick in advance if you know what I'm hinting at!

vmbuilder

  • Beginner
  • *
  • Posts: 21
Re: Shows all products from subcategories in parent categories (all branch)
« Reply #14 on: August 12, 2011, 11:42:39 am »
Getting closer! Tried the following from myopicseer instead (thank you) on http://forum.virtuemart.net/index.php?topic=88352.0

Quote
New to 1.1.9, doesn't display empty categories or subcats.  You must apply an Exclamation point ("not") before the final "empty" to line 86 in admin/components/com_virtuemart/html/shop.browser.php, as such:

elseif( $num_rows == 0 && empty($product_type_id) && !empty($child_list)) {

Now sub-cat headings are displayed without a list of their products underneath - just how I want  :)

But I still need to hide the leftover product column headings (like "image", "price", "descriptions") which are still displaying..?!
Joomla 1.5.23 VM 1.1.19