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

goldlink

  • Beginner
  • *
  • Posts: 17
How to hide child products (categorized)
« 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

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4455
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: How to hide child products (categorized)
« Reply #1 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.

goldlink

  • Beginner
  • *
  • Posts: 17
Re: How to hide child products (categorized)
« Reply #2 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.

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4455
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: How to hide child products (categorized)
« Reply #3 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.

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10428
  • VirtueMart Version: 3+
Re: How to hide child products (categorized)
« Reply #4 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;



dr.spot86

  • Beginner
  • *
  • Posts: 15
  • I'm Ouksider
  • Skype Name: Vincenzo Tortora
Re: How to hide child products (categorized)
« Reply #5 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.
Vincenzo T | Oukside | oukside.com