Easily retrieve properties along with products?
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Easily retrieve properties along with products?
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;
}
Re: Easily retrieve properties along with products?
It's very inefficient because you fetch the properties for each product separately. Better use this:
Then you have the properties grouped by the product ID and can access them in a very efficient way while using only one additional query.
Code: Select all
// ...
$myitems = $manager->searchItems($search, array('text'));
$propManager = \Aimeos\MShop\Index\Manager\Factory::createManager($context, 'product/property');
$search = $propManager->createSearch(true);
$expr = array(
$search->compare('==', 'product.property.parentid', array_keys($myitems)),
$search->getConditions(),
);
$search->setConditions($search->combine('&&', $expr);
$search->setSlice(0, 0x7fffffff);
$propItems = $propManager->searchItems($search);
$result = array();
foreach($propItems as $item) {
$result[$item->getParentId()][$item->getId()] = $item;
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star