Author Topic: Loop through child products in category view  (Read 987 times)

Huubs

  • Jr. Member
  • **
  • Posts: 213
Loop through child products in category view
« on: February 07, 2020, 08:50:21 am »
Hello,

I want to loop through my child products on the category page to get all the product_s_desc of the child products to display on the category page. How can I do this?

Is there some sort of function to get the data of the child products? I don't see anything in the $this->product array.

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4329
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Loop through child products in category view
« Reply #1 on: February 07, 2020, 16:39:09 pm »

In product model ou have getUncategorizedChildren
Code: [Select]
$productModel = VmModel::getModel ('product');
$productModel->setId($product->virtuemart_product_id);
$uncatChildren = $productModel->getUncategorizedChildren(false);
if($uncatChildren){
foreach ($uncatChildren as $k => $child) {
$child = $productModel->getProduct((int)$child,true);
//you can acces to this $child  here
}
}

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10404
  • VirtueMart Version: 3+
Re: Loop through child products in category view
« Reply #2 on: February 07, 2020, 17:06:05 pm »
Hello,

I want to loop through my child products on the category page to get all the product_s_desc of the child products to display on the category page. How can I do this?

Is there some sort of function to get the data of the child products? I don't see anything in the $this->product array.


Child products that are displayed?
Or are you referring to the children on a parent that is displayed?

J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Huubs

  • Jr. Member
  • **
  • Posts: 213
Re: Loop through child products in category view
« Reply #3 on: February 07, 2020, 17:15:53 pm »
Hello,

I want to loop through my child products on the category page to get all the product_s_desc of the child products to display on the category page. How can I do this?

Is there some sort of function to get the data of the child products? I don't see anything in the $this->product array.


Child products that are displayed?
Or are you referring to the children on a parent that is displayed?

No the child products don't have categoires so the parent is only visible in the category for a clean shop. Now you can select the child products via a custom field, but I want to show certain data from the child productts on the category page


In product model ou have getUncategorizedChildren
Code: [Select]
$productModel = VmModel::getModel ('product');
$productModel->setId($product->virtuemart_product_id);
$uncatChildren = $productModel->getUncategorizedChildren(false);
if($uncatChildren){
foreach ($uncatChildren as $k => $child) {
$child = $productModel->getProduct((int)$child,true);
//you can acces to this $child  here
}
}

Thanks im gonna check it out that works!