News:

Support the VirtueMart project and become a member

Main Menu

How to hide child products

Started by Georgios Kolomvos, June 08, 2012, 18:31:30 PM

Previous topic - Next topic

Georgios Kolomvos

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):
foreach ( $this->products as $product ) {

insert the following code:

if ($product->product_parent_id !== "0") {
   $BrowseTotalProducts --;
}
else { 


2.b) Just after the statement (~ line 306):
  $iBrowseProduct ++;
insert the following code:

} //end of if ($product->product_parent_id !== "0")

make sure that this new code will be inserted just before the following code:
} // end of foreach ( $this->products as $product )
Georgios Kolomvos
Patras, Greece

Georgios Kolomvos

#1
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):
function sortSearchListQuery($onlyPublished=true,$virtuemart_category_id = false, $group=false,$nbrReturnProducts=false){
to:
function sortSearchListQuery($onlyPublished=true,$virtuemart_category_id = false, $group=false,$nbrReturnProducts=false, $only_parent_products=false){

1.b) After statement (~ line 245)
if($onlyPublished){ $where[] = ' p.`published`="1" '; }
Add the following code:
if ($only_parent_products) { $where[] = ' p.`product_parent_id`="0" '; }
      
1.c) Modify statement (~line 834):
public function getProductListing($group = false, $nbrReturnProducts = false, $withCalc = true, $onlyPublished = true, $single = false,$filterCategory= true, $category_id=0){
to:
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 ):
$ids = $this->sortSearchListQuery($onlyPublished, $this->virtuemart_category_id, $group, $nbrReturnProducts);
to:
$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):   
$products = $productModel->getProductListing($Product_group, $max_items, $show_price, true, false,$filter_category, $category_id);
to:
$products = $productModel->getProductListing($Product_group, $max_items, $show_price, true, false,$filter_category, $category_id, true);
Georgios Kolomvos
Patras, Greece

FilipeRuivo


Menace

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

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

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

Quote from: Menace on August 18, 2012, 13:47:15 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

Just made an update to 2.0.9b but I get the same results.

jjk

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

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

Quote from: Menace on August 20, 2012, 14:02:38 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

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

seems to not work for VM 2.0.10  :-\

renatomiranda

#13
it worked, thanks!

cloudti

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