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 )
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);
Thanks.
Very useful ;)
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?
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)
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.
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.
Just made an update to 2.0.9b but I get the same results.
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]
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)
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).
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.
seems to not work for VM 2.0.10 :-\
it worked, thanks!
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
Quote from: cloudti on August 31, 2012, 20:17:34 PM
Please, could someone have a solution for child count result in the search result page?
Thanks
Same needs for me :)
I think there is no way to fix that directly on the template.
Someone know which file return products ?
We just have to add a condition to the sql query, something like "WHERE product_parent_id LIKE '0'"
I am too having this problem. I cannot think of any reason why child products would need to be displayed on the category browse page/layout. The should only be searchable and viewable from the product details page drop-down.
The only way to eliminate child products from being viewable from the category page is to not select a category for which they belong to. But doing that screws up the SEO URL associated for the child products.
Here's my reply in another thread:
http://forum.virtuemart.net/index.php?topic=109920.msg370036#msg370036 (http://forum.virtuemart.net/index.php?topic=109920.msg370036#msg370036)
Thank you very much gkolomvos! It works perfectly for me in Joomla 2.5.9 and Virtuemart 2.0.18a.
Is there another solution for mod_virtuemart_product that no requires to modify Virtuemart's core files?
Thank you and best regards!
As for the modification of the category/default.php file it would be cleaner to do this right inside the loop:
if ($product->product_parent_id !== "0") {
//this is a child product
continue;
}
As for the modification of the products module, and hence the modifications of the core VM files, I am against doing that - it is not a good practice and either you will be stuck with current VM version or worse if you by accident update the component you will have all mods gone (with the obvious results).
So, I would suggest to do this(it is even simpler):
mod_virtuemart_product uses template files inside /modules/mod_virtuemart_product/tmpl - and you cannot bring this into your template directory(if you check on the mod_virtuemart_product.xml file you will see why). But you can duplicate the dafault.php file into let's say: mylisting.php
1) open it
NOTE: inside there are two loops: one for the div based and one for the ul/li based visualization. So to make sure let's mod both of them
2) find line "<?php foreach ($products as $product) { ?>" ~@line:25
and insert right after the same break out as before so your code will look like this:
<?php foreach ($products as $product) {
if ($product->product_parent_id !== "0") {continue;}//NO CHILD PRODUCTS
?>
3) find line "<?php foreach ($products as $product) :?>" ~@line:79
and do ita again so your code will look like this:
<?php foreach ($products as $product) :
if ($product->product_parent_id !== "0") {continue;}//NO CHILD PRODUCTS
?>
4) save
5) check
6) enjoy
Quote from: adamjakab on June 15, 2013, 15:17:33 PM
As for the modification of the category/default.php file it would be cleaner to do this right inside the loop:
if ($product->product_parent_id !== "0") {
//this is a child product
continue;
}
That works perfectly for me. Only a short piece of code to add inside the override - I like K.I.S.S
*** Edited *** Actually there is a problem remaining with items per page displaying incorrectly as it would seem despite being hidden the page is still counting child products on the page - any ideas how to get around this?
for example. I have a category with 4 parent products, in each are 3 child products. if the page is set to display 10 items per page you are shown 3 of them and then have to click next page for the fourth
Hello,
I have the same problem. I hide child products but in category view appear only parent products, bun with an issue. The category must show 18 product per page, but sometimes shows 2, sometimes 4, in next page 3, and it seems to count the child products in navigation, but without showing them. Is there a solution for that?
The only way I have found around this is not to assign child products to a category so the parent still shows in the correct place and it pulls through the child product information. It does make administering child products a little more irritating and less logical for instance you drill down in the backend to a category, find the product(s) you want to edit, click where is says "x number of child products" and the page shows nothing because now you are trying to find child products that are not in that category anymore. To get round this you go back to the category dropdown and just go back to filtering all categories - THEN they show up.
It works, it works well but takes a few more steps to deal with and isn't ideal - but it does work at least.
In that case, you will have to hack core product model.
Open administrator\components\com_virtuemart\models\product.php
Find the following codes between lines 334 to 336:
if ($this->product_parent_id) {
$where[] = ' p.`product_parent_id` = ' . $this->product_parent_id;
}
Replace above by:
if ($this->product_parent_id) {
$where[] = ' p.`product_parent_id` = ' . $this->product_parent_id;
}
else {
$where[] = ' p.`product_parent_id` = 0';
}
Now this should ignore all child products in all products listing areas including category page.
Quote from: Jumbo! on November 05, 2013, 14:18:03 PM
In that case, you will have to hack core product model.
Open administrator\components\com_virtuemart\models\product.php
Find the following codes between lines 334 to 336:
if ($this->product_parent_id) {
$where[] = ' p.`product_parent_id` = ' . $this->product_parent_id;
}
Replace above by:
if ($this->product_parent_id) {
$where[] = ' p.`product_parent_id` = ' . $this->product_parent_id;
}
else {
$where[] = ' p.`product_parent_id` = 0';
}
Now this should ignore all child products in all products listing areas including category page.
ok, but in this way... don't child products disappear from admin products list in VM backend too?
Hello,
Thanks alot. I am using Stockable Custom Fields with Custom fields for all and Custom Fields Pro and I managed to tinker with the various product scripts to ensure that the child products are counted in each category but are not returned in search and category pages only the parent products are returned.
Files I tinkered with are:
templates\MY_TEMPLATE\html\com_virtuemart\category\default.php
components\com_virtuemart\models\product.php
components\com_customfilters\models\products.php
Thanks again