Merge DataObject Listings



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)?



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/%');


Or like this:

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

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