Easily retrieve properties along with products?
Posted: 26 Jul 2016, 01:06
i just saw that properties are not of the same domain like products. Now what is the efficient and easy way to retrieve the properties? see here: https://aimeos.org/docs/Developers/Libr ... ta_domains
I ended up doing something like this, which seems stupid:
I ended up doing something like this, which seems stupid:
Code: Select all
/**
* @param $context
* @param $catIdsArr
* @param bool|true $retrievePropItems
* @return array[\Aimeos\MShop\Common\Item\Iface[], \Aimeos\MShop\Product\Item\Property\Standard[]]
* @throws \Aimeos\MShop\Exception
*/
public static function GetProductsInExactlyTheseCats($context, $catIdsArr, $retrievePropItems = true){
$manager = \Aimeos\MShop\Index\Manager\Factory::createManager($context );
$search = $manager->createSearch(true);
$expr[] = $search->getConditions();
$fcn = $search->createFunction( 'index.catalogcount', array( 'default', $catIdsArr ) );
$search->setConditions( $search->compare( '==', $fcn, sizeof($catIdsArr) ) );
/** @var \Aimeos\MShop\Common\Item\Iface[] $myitems */
$myitems = $manager->searchItems($search, array('text'));
/** @var \Aimeos\MShop\Product\Item\Property\Standard[] $myPropItems */
if($retrievePropItems && sizeof($myitems) > 0){
foreach($myitems as $key => $item){
$propManager = \Aimeos\MShop\Factory::createManager( $context, 'product/property' );
$search = $propManager->createSearch(true);
$expr = $search->compare( '==', 'product.property.parentid', array($item->getId()) );
$search->setConditions( $expr );
$myPropItems = $propManager->searchItems($search);
if(sizeof($myPropItems) > 0){
$myitems[$key] = array($item, $myPropItems);
}
}
}
return $myitems;
}