top products by customer, controller, view

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!
columbo
Advanced
Posts: 157
Joined: 09 Oct 2019, 09:42

top products by customer, controller, view

Post by columbo » 23 Jun 2021, 20:06

Hi,

we'd like to provide in the customer-profiles a list of their 10 most frequently bought products. (quantity of products / customer).
I already found this forum post: laravel-package-f18/how-can-get-bestsel ... t1193.html

Code: Select all

$manager = \Aimeos\MShop::create( $context, 'order/base/product' );
$result = $manager->aggregate( $manager->filter(), 'order.base.product.productid', 'order.base.product.quantity', 'sum' ); 

// find the products which are sold most in $result (product ID is the key, count is the value)

$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' );
$items = $cntl->uses( ['text', 'price', 'media'] )->product( <ids> )->search();
Does "order.base.product.quantity" already takes order-quantities by customers into account or do we have to add the current customer id?
We created a new controller with the code above. Is it possible to use / copy the default Aimeos product list “html client” / view, that is already used for our product catalog? How would the controller look like?

Thank you!

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

Re: top products by customer, controller, view

Post by aimeos » 26 Jun 2021, 07:06

columbo wrote: 23 Jun 2021, 20:06 Does "order.base.product.quantity" already takes order-quantities by customers into account or do we have to add the current customer id?
As your filter is empty, the result wouldn't be limited to the customer. The customer ID is stored in the mshop_order_base table, so the code must be something like this:

Code: Select all

$manager = \Aimeos\MShop::create( $context, 'order/base' );
$filter = $manager->filter()->add( 'customer.id', '==', '<customer id>' );
$result = $manager->aggregate( $filter, 'order.base.product.productid', 'order.base.product.quantity', 'sum' ); 
columbo wrote: 23 Jun 2021, 20:06 We created a new controller with the code above. Is it possible to use / copy the default Aimeos product list “html client” / view, that is already used for our product catalog? How would the controller look like?
The catalog/list component doesn't contain that code so it won't work that way but you can create a new "account/top10" component and use the templates of the catalog/list component:
https://aimeos.org/docs/latest/frontend ... omponents/
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply