VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: goldlink on April 01, 2020, 15:30:40 PM

Title: How to hide child products (categorized)
Post by: goldlink on April 01, 2020, 15:30:40 PM
Good morning forum, I would have a need.

I would like to hide the child products even if they belong to a category, since being virtuemart connected to a management system, I also receive the data of the belonging categories.

I saw that a change had already been proposed http://forum.virtuemart.net/index.php?topic=103702.0, but the post is very old and it was for the version of Virtuemart 2.

Could anyone help me? Thanks.

Joomla 3.9.16
VirtueMart 3.6.10
Title: Re: How to hide child products (categorized)
Post by: Studio 42 on April 01, 2020, 20:43:45 PM
The linked fix is poor!
You need to modify the search query, or directly in the product model or better, with a system plugin to load your own productmodel so you dont destroy the virtuemart core files changes on update.
Title: Re: How to hide child products (categorized)
Post by: goldlink on April 02, 2020, 16:16:55 PM
Thanks Studio 42, I knew that the link was obsolete, I posted it to start from something that had already been done previously.
I was hoping someone could make the change from that. I believe it is a problem common to many and not just an isolated case.

Thanks anyway for your advice, I will look for some ready solution if you say there are.
Title: Re: How to hide child products (categorized)
Post by: Studio 42 on April 02, 2020, 18:29:52 PM
No plugin exist, you have to write it.
You can try to find one, but i never here about this.
But a plugin have the advantage to not destroy core files and can be unpublished if you have a problem a day.
Title: Re: How to hide child products (categorized)
Post by: PRO on April 07, 2020, 21:04:55 PM

Here is a little function that checks if a product has a parent

function hasParent($pid){
$productModel = VmModel::getModel('product');
$id = $productModel->getProductParentId($pid);
if (!empty($id)){
return 1;
}
}


so in category view
products.php

after this
   foreach ($products as $product ) {

add this

              if(hasChilds($product->virtuemart_product_id)==1) continue;


Title: Re: How to hide child products (categorized)
Post by: dr.spot86 on May 24, 2021, 08:57:54 AM
What about creating a category just for the child products and not showing it in the front views / category views?

E.g.
Category:
• Products
• Services
• Child Products

In Products, you have products that are parents of some child products. But when you go on Products category, you see only them and not the child products.