Get all products - except those with parents

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)
Spam and unrelated posts will be removed immediately!
iresults
Posts: 18
Joined: 28 Aug 2020, 13:36

Get all products - except those with parents

Post by iresults » 22 Sep 2020, 18:28

I would like to receive all products that are not assigned to a parent product. With

Code: Select all

$manager = \Aimeos\MShop::create($context, 'product');
$search = $manager->createSearch();
$expr = $search->compare('==', 'product.type', 'select');
$search->setConditions($expr);
$items = $manager->searchItems( $search );
I get all products with type "select" (all parent products). But how can I retrieve also those products with type "default" who dont have a parent product.

In the end, I need all the products that are displayed in the list by default.

Thanks for a tip.

===
TYPO3 9.5.x
PHP 7.2
Aimeos 20.7.1

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Get all products - except those with parents

Post by aimeos » 23 Sep 2020, 14:46

It's possible but usually you want all products that are at least in one category (default and selection products):

Code: Select all

$manager = \Aimeos\MShop::create($context, 'index');
$search = $manager->createSearch(true);
$expr = [
	$search->compare('!=', 'index.catalog.id', null),
	$search->getConditions()
];
$search->setConditions($search->combine( '&&', $expr));
$items = $manager->searchItems( $search );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

iresults
Posts: 18
Joined: 28 Aug 2020, 13:36

Re: Get all products - except those with parents

Post by iresults » 23 Sep 2020, 17:30

Thank you very much. This is exactly what I was looking for.

User avatar
parmonov98
Posts: 33
Joined: 24 Sep 2020, 12:12

Re: Get all products - except those with parents

Post by parmonov98 » 10 Oct 2020, 09:26

aimeos wrote: 23 Sep 2020, 14:46 It's possible but usually you want all products that are at least in one category (default and selection products):

Code: Select all

$manager = \Aimeos\MShop::create($context, 'index');
$search = $manager->createSearch(true);
$expr = [
	$search->compare('!=', 'index.catalog.id', null),
	$search->getConditions()
];
$search->setConditions($search->combine( '&&', $expr));
$items = $manager->searchItems( $search );
What is context var here?
How to and what to assign to it?

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Get all products - except those with parents

Post by aimeos » 10 Oct 2020, 09:32

It's the central dependency container. How to retrieve it depends on your environment:
- Laravel: https://aimeos.org/docs/latest/laravel/ ... os-objects
- Symfony: https://aimeos.org/docs/latest/symfony/ ... os-objects
- TYPO3: https://aimeos.org/docs/latest/typo3/ex ... os-objects
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply