Filter Group By or DISTINCT column

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
IvanIgniter
Posts: 58
Joined: 01 Dec 2021, 07:41

Filter Group By or DISTINCT column

Post by IvanIgniter » 05 Oct 2022, 10:55

I am using laravel 6.x, PHP 7.4, Docker desktop/Ubuntu and the Aimeos 2021 (aimeos-laravel: 2021.10.4 / aimeos-core: 2021.10.13)

I have a question about model manager filtering in https://aimeos.org/docs/2021.x/models/search-filter/
I would like to know how can I make a filter like a group by or DISTINCT column name customerid in mshop_order_base table?

Please help..

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

Re: Filter Group By or DISTINCT column

Post by aimeos » 05 Oct 2022, 11:45

The order and order base manager implements the aggregate() method which you can use to group by keys, e.g.

Code: Select all

$manager = \Aimeos\MShop::create( $this->context(), 'order/base' );
$filter = $manager->filter();
$result = $manager->aggregate( $filter, 'order.base.customerid' );
The result will be an associative list of customer IDs and the number of orders per customer.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
IvanIgniter
Posts: 58
Joined: 01 Dec 2021, 07:41

Re: Filter Group By or DISTINCT column

Post by IvanIgniter » 06 Oct 2022, 08:15

Thank you that was working but not as I wanted because it only return an array of customerid and qty it exist.
I would like to get the rows of orderbase those customerid have existed?
Is there a way to filter orderbase table based from the returned aggregated values?

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

Re: Filter Group By or DISTINCT column

Post by aimeos » 07 Oct 2022, 07:05

You have to use the found customer IDs to retrieve their orders afterwards using the search() method of the order/base manager.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
IvanIgniter
Posts: 58
Joined: 01 Dec 2021, 07:41

Re: Filter Group By or DISTINCT column

Post by IvanIgniter » 11 Oct 2022, 10:13

Yap I found a way. Thank you.

Post Reply