Author Topic: How to hide child products  (Read 29210 times)

gkolomvos

  • Beginner
  • *
  • Posts: 45
How to hide child products
« on: June 08, 2012, 18:31:30 pm »
To hide all the child products from category and search view, do the following:

1) Copy the file "components/com_virtuemart/views/category/tmpl/default.php" to your template directory at folder: templates/my_Joomla_template/html/com_virtuemart/category/  (change "my_Joomla_template" with the folder name for your true joomla template). If the file already exists there, you do not need to copy it. Just go to the next step 

2) Edit file  templates/my_Joomla_template/html/com_virtuemart/category/default.php and do the following modifications:

2.a) Just after the statement (~ line 197):
Code: [Select]
foreach ( $this->products as $product ) {
insert the following code:
Code: [Select]
if ($product->product_parent_id !== "0") {
   $BrowseTotalProducts --;
 }
 else { 

2.b) Just after the statement (~ line 306):
Code: [Select]
  $iBrowseProduct ++; insert the following code:
Code: [Select]
} //end of if ($product->product_parent_id !== "0") make sure that this new code will be inserted just before the following code:
Code: [Select]
} // end of foreach ( $this->products as $product )
Georgios Kolomvos
Patras, Greece

gkolomvos

  • Beginner
  • *
  • Posts: 45
Re: How to hide child products
« Reply #1 on: June 08, 2012, 18:37:17 pm »
To hide all the child products from mod_virtuemart_product (Featured, Best Sell, Latest products) do the following

1) Edit the file  "administrator/components/com_virtuemart/models/product.php" and make the following modifications:
1.a) Modify statement (~ line 174):
Code: [Select]
function sortSearchListQuery($onlyPublished=true,$virtuemart_category_id = false, $group=false,$nbrReturnProducts=false){ to:
Code: [Select]
function sortSearchListQuery($onlyPublished=true,$virtuemart_category_id = false, $group=false,$nbrReturnProducts=false, $only_parent_products=false){
1.b) After statement (~ line 245)
Code: [Select]
if($onlyPublished){ $where[] = ' p.`published`="1" '; }Add the following code:
Code: [Select]
if ($only_parent_products) { $where[] = ' p.`product_parent_id`="0" '; }       
1.c) Modify statement (~line 834):
Code: [Select]
public function getProductListing($group = false, $nbrReturnProducts = false, $withCalc = true, $onlyPublished = true, $single = false,$filterCategory= true, $category_id=0){ to:
Code: [Select]
public function getProductListing($group = false, $nbrReturnProducts = false, $withCalc = true, $onlyPublished = true, $single = false,$filterCategory= true, $category_id=0, $only_parent_products=false){
1.d) Modify statement (~line 863 ):
Code: [Select]
$ids = $this->sortSearchListQuery($onlyPublished, $this->virtuemart_category_id, $group, $nbrReturnProducts); to:
Code: [Select]
$ids = $this->sortSearchListQuery($onlyPublished, $this->virtuemart_category_id, $group, $nbrReturnProducts, $only_parent_products);
2) Edit the file "modules/mod_virtuemart_product/mod_virtuemart_product.php" and modify statement (~ line 59):   
Code: [Select]
$products = $productModel->getProductListing($Product_group, $max_items, $show_price, true, false,$filter_category, $category_id); to:
Code: [Select]
$products = $productModel->getProductListing($Product_group, $max_items, $show_price, true, false,$filter_category, $category_id, true);
Georgios Kolomvos
Patras, Greece

FilipeRuivo

  • Jr. Member
  • **
  • Posts: 62
Re: How to hide child products
« Reply #2 on: July 09, 2012, 17:36:21 pm »
Thanks.
Very useful  ;)

Menace

  • Jr. Member
  • **
  • Posts: 53
Re: How to hide child products
« Reply #3 on: August 16, 2012, 18:01:34 pm »
Hello!
I just implemented the provided code from the first posting and it works great for me. Unfortunately there is another related problem I am faced with now.

The childs disapeared from the search results page, just like I wanted, but they are still counted by the module. That means for example on top of the results page I get "results 1-10 from 20" while there are just 3 results shown as VM still counts the childs as matching products but diplays only the parents.

Is it possible to change that additionally?

jjk

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3728
  • using Matomo instead of Google Analytics
Re: How to hide child products
« Reply #4 on: August 16, 2012, 20:59:46 pm »
Just a note - on my own site I'm using "Generic Child Variants" and my child products do not show up and are not counted when I search for a specific product. In other words, if I have a parent product with 5 child products, searching for the product name shows and counts only the parent product. Even if I search for a part of the product name which is only present in the child products, the search result only shows the parent product.

(Joomla 2.5.6/VM 2.0.9a/No modification of the files mentioned above)
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

Menace

  • Jr. Member
  • **
  • Posts: 53
Re: How to hide child products
« Reply #5 on: August 18, 2012, 13:47:15 pm »
Thank you jjk,

I use J! 2.5.6 and VM 2.0.8e

The count of products and results navigation works fine on all my categories. Somehow in 'searchview' and on sites where ALL products of the shop have to be shown it breaks and it shows the parents AND their childs. I don't get this to work.

Only my parents have categories, the childs don't. This is my setup and I have to make it work from here.

I thought of adding a codeline like
Code: [Select]
if ($product->product_parent_id !== "0") an a place where the productcount is done but I don't know if it works and even where I could add it.

I really need help on this one.

jjk

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3728
  • using Matomo instead of Google Analytics
Re: How to hide child products
« Reply #6 on: August 18, 2012, 19:12:33 pm »
Only my parents have categories, the childs don't.
I have the same. Maybe version 2.0.9.b makes the difference. If I remember correctly, child product did show up seperately in search results in 2.0.8x versions.
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

Menace

  • Jr. Member
  • **
  • Posts: 53
Re: How to hide child products
« Reply #7 on: August 19, 2012, 14:46:01 pm »
Just made an update to 2.0.9b but I get the same results.

jjk

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3728
  • using Matomo instead of Google Analytics
Re: How to hide child products
« Reply #8 on: August 20, 2012, 13:43:24 pm »
Child products still show up as seperate products, if you forget to assign a custom field of the "Generic child variant" type to your product. Maybe this is the difference beteween your site and my site (works for me). See screenshots attached


[attachment cleanup by admin]
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

Menace

  • Jr. Member
  • **
  • Posts: 53
Re: How to hide child products
« Reply #9 on: August 20, 2012, 14:02:38 pm »
Maybe this is the reason.

I don't use any customfields at all. And I can't as I get hundreds of products updated every day by different csv lists of manufacturers. This would change my whole shop.
But still I don't really think, this is the probelm, because of the following facts:

1. The category page looks fine and doesn't display any childs neither in the page or results counter nor on the product list when I choose a category, that is not on highest shoplevel.
2. Also the search works correctly, if I set "use category filter" to "yes" in the backend and search from categories.

The problem just occures when I am on toplevel category or when I perform a search without category filter (what I want customers to be able to do)

jjk

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3728
  • using Matomo instead of Google Analytics
Re: How to hide child products
« Reply #10 on: August 20, 2012, 14:11:29 pm »
The problem just occures when I am on toplevel category or when I perform a search without category filter (what I want customers to be able to do)

That is the type of search I've been talking about.
I would suggest to try a custom field defined as "Generic Child Variant" on one of your products in order to find out if this is the problem. (I'm pretty shure it is).
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

Menace

  • Jr. Member
  • **
  • Posts: 53
Re: How to hide child products
« Reply #11 on: August 20, 2012, 14:21:45 pm »
Just tried but no changes on frontend.

I can handle the problem with the category view by wrapping another category around all products and assign this one to my menue instead of top level category. But this solves only half of the problem, because still the searchview is not effected by this.

renatomiranda

  • Beginner
  • *
  • Posts: 4
  • Freelancer Joomla!
    • Renato Miranda Joomla! Freelancer
Re: How to hide child products
« Reply #12 on: August 25, 2012, 16:47:31 pm »
seems to not work for VM 2.0.10  :-\

renatomiranda

  • Beginner
  • *
  • Posts: 4
  • Freelancer Joomla!
    • Renato Miranda Joomla! Freelancer
Re: How to hide child products
« Reply #13 on: August 25, 2012, 17:02:59 pm »
it worked, thanks!

cloudti

  • Beginner
  • *
  • Posts: 3
Re: How to hide child products
« Reply #14 on: August 31, 2012, 20:17:34 pm »
I cannot use a Generic Child Variant custom field for my parent products because im using the stockable plugin for size and color purposes and it is doing the job well.

When I tried Generic Child in, hiding it, it didn't work.

Please, could someone have a solution for child count result in the search result page?

Thanks