VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: Kuubs on February 07, 2020, 08:50:21 AM

Title: Loop through child products in category view
Post by: Kuubs 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.
Title: Re: Loop through child products in category view
Post by: Studio 42 on February 07, 2020, 16:39:09 PM

In product model ou have getUncategorizedChildren

$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
}
}
Title: Re: Loop through child products in category view
Post by: PRO on February 07, 2020, 17:06:05 PM
Quote from: Huubs 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.


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

Title: Re: Loop through child products in category view
Post by: Kuubs on February 07, 2020, 17:15:53 PM
Quote from: PRO on February 07, 2020, 17:06:05 PM
Quote from: Huubs 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.


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

Quote from: Studio 42 on February 07, 2020, 16:39:09 PM

In product model ou have getUncategorizedChildren

$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!