Merge DataObject Listings


#1

Hello,

I have this DataObjects hierarchy:

  • Brand
    • ProductCategory
      • Product

I want to get all Products by Brand and the way I am doing this is (pseudocode ish):

$cats = ProductCategory::getByBrand($brand);

$mergedProductListing = ;
foreach($cats as cat){
    $mergedProductListing += $cats::getAllProducts(); // I know this is not possible
}

Is there a way of merging to listings (DataObject specifically)?

Thanks


#2

If Brand is connected to Product only by parent-child relation, you can easily get all products from this tree by something like this:

$productListing->setCondition("o_path LIKE '/Brand/%');

#3

Or like this:

$brands = Brand::getListing();
$brands->load();
$allBrandIds = array_map(function($brand) {
    return $brand->getId();
}, $brands);

$productListing->setCondition("brand__id IN (". implode(',', $allBrandIds) .")");