how can get Bestsellers or Most Popular products?
					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!
	Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Re: how can get Bestsellers or Most Popular products?
@aimeos
how can I get just top 10 product, I mean I want to query that sent to mysql just get top 10 not all products?
			
			
			
									
									
						how can I get just top 10 product, I mean I want to query that sent to mysql just get top 10 not all products?
Re: how can get Bestsellers or Most Popular products?
You can use slice():
See: https://github.com/aimeos/ai-controller ... #L158-L175
			
			
			
									
									Code: Select all
$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' );
$items = $cntl->use( ['text', 'price', 'media'] )->product( <ids> )->slice( 0, 10 )->search();
Professional support and custom implementation are available at  Aimeos.com
If you like Aimeos,
 give us a star
						If you like Aimeos,
Re: how can get Bestsellers or Most Popular products?
Hi, 
In case it is useful to anyone, I have made the following function to return the best-selling products. It works with the latest version (2022.07.2) of Laravel Aimeos to date.
This function must be in a decorator.
Regards,
			
			
			
									
									
						In case it is useful to anyone, I have made the following function to return the best-selling products. It works with the latest version (2022.07.2) of Laravel Aimeos to date.
Code: Select all
public function getBestSellersByCategory ($categoryID, $domains, $context, $limit = 10) {
        $manager = \Aimeos\MShop::create( $context, 'order/base/product' );
        $result = $manager->aggregate(
            $manager->filter(),
            'order.base.product.productid', 'order.base.product.quantity', 'sum'
        )->slice( 0, $limit );
        // 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' );
        return $cntl
                    ->uses( $domains )
                    ->category([$categoryID])
                    ->product( $result->keys()->toArray() )
                    ->search();
    }Regards,
Re: how can get Bestsellers or Most Popular products?
Very cool!  
			
			
			
									
									Professional support and custom implementation are available at  Aimeos.com
If you like Aimeos,
 give us a star
						If you like Aimeos,
Re: how can get Bestsellers or Most Popular products?
I have created a decorator in \Aimeos\MShop\Service\Provider\Decorator and included this function, but how can I use it? Aren't decorators configured via the Services tab and limited to Delivery and Payment?
			
			
			
									
									
						Re: how can get Bestsellers or Most Popular products?
A service decorator is the wrong place because it's only used for delivery/payment options as you've already stated.
Create a HTML client decorator for the component you want (e.g. catalog/lists) instead:
https://aimeos.org/docs/latest/frontend ... omponents/
			
			
			
									
									Create a HTML client decorator for the component you want (e.g. catalog/lists) instead:
https://aimeos.org/docs/latest/frontend ... omponents/
Professional support and custom implementation are available at  Aimeos.com
If you like Aimeos,
 give us a star
						If you like Aimeos,