How to configure and adapt Aimeos based shops as developer
Forum rules: Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
#1669 by Yvler
22 Jun 2015, 11:27
Is it possible to retrieve the category of a product?
In the breadcrumb of the detail page of the shop, the category is echo'd. But I don't seem to find how this works :)
#1670 by aimeos
22 Jun 2015, 11:52
Yvler wrote:Is it possible to retrieve the category of a product?
In the breadcrumb of the detail page of the shop, the category is echo'd. But I don't seem to find how this works :)


Product can be in several categories, so there's no 1:1 relationship.
You can retrieve the categories of a product by using the catalog or catalog list manager and searching for the refid and the domain 'product':

Code: Select all$manager = \MShop_Factory::createManager($context, 'catalog');
$search = $manager->createSearch();
$expr = array(
    $search->compare('==', 'catalog.list.refid', $prodid),
    $search->compare('==', 'catalog.list.domain', 'product'),
//  $search->compare('==', 'catalog.list.type.code', 'default'), // no promotion products, etc.
);
$search->setConditions($search->combine('&&', $expr));
$categoryItems = $manager->searchItems($search);
#1672 by Yvler
23 Jun 2015, 06:39
I already thought that it'd be this way. But i was hoping I could retrieve them the same way we retrieve media or the price
The problem is that we're using this on a productlist page, so we'd have to query for all the item id's :)
#1673 by aimeos
23 Jun 2015, 07:13
[quote="Yvler"The problem is that we're using this on a productlist page, so we'd have to query for all the item id's :)[/quote]

The most efficient way is to add all product IDs of that list page to your query (compare() also accepts an array as third parameter), execute that query once and map the product/categories in your view. Beware to set the slice to a higher value, otherwise only 100 items will be retrieved.