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

Florentp

  • Jr. Member
  • **
  • Posts: 86
Re: How to hide child products
« Reply #15 on: September 12, 2012, 17:06:29 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'"
Web programmer. Passionate.
PHP, SQL, Javascript, JQuery, css.
Skype : florent.indienboutique

klattr1

  • Jr. Member
  • **
  • Posts: 80
Re: How to hide child products
« Reply #16 on: November 12, 2012, 20:05:14 pm »
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.

klattr1

  • Jr. Member
  • **
  • Posts: 80
Re: How to hide child products
« Reply #17 on: November 25, 2012, 19:36:58 pm »

PabloArias

  • Beginner
  • *
  • Posts: 16
    • Pablo Arias
Re: How to hide child products
« Reply #18 on: February 08, 2013, 17:04:44 pm »
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!

adamjakab

  • Beginner
  • *
  • Posts: 2
Re: How to hide child products - no VM Core Mods
« Reply #19 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:
Code: [Select]
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:
Code: [Select]
<?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:
Code: [Select]
<?php foreach ($products as $product) :
if ($product->product_parent_id !== "0") {continue;}//NO CHILD PRODUCTS
?>

4) save
5) check
6) enjoy

bunglehaze

  • Jr. Member
  • **
  • Posts: 487
Re: How to hide child products
« Reply #20 on: August 02, 2013, 16:44:34 pm »
As for the modification of the category/default.php file it would be cleaner to do this right inside the loop:
Code: [Select]
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




nmihos

  • Beginner
  • *
  • Posts: 16
Re: How to hide child products
« Reply #21 on: November 04, 2013, 21:44:51 pm »
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?

bunglehaze

  • Jr. Member
  • **
  • Posts: 487
Re: How to hide child products
« Reply #22 on: November 05, 2013, 12:33:52 pm »
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.

Jumbo!

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 668
  • Full-stack Web Developer
    • www.virtueplanet.com
  • VirtueMart Version: Always latest
Re: How to hide child products
« Reply #23 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:
Code: [Select]
if ($this->product_parent_id) {
$where[] = ' p.`product_parent_id` = ' . $this->product_parent_id;
}
Replace above by:
Code: [Select]
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.

merlyno79

  • Beginner
  • *
  • Posts: 2
Re: How to hide child products
« Reply #24 on: March 05, 2014, 17:42:11 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:
Code: [Select]
if ($this->product_parent_id) {
$where[] = ' p.`product_parent_id` = ' . $this->product_parent_id;
}
Replace above by:
Code: [Select]
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?

munyiva

  • Beginner
  • *
  • Posts: 2
Re: How to hide child products
« Reply #25 on: May 29, 2015, 19:37:20 pm »
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