how can get Bestsellers or Most Popular products?

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!
Ahmad
Posts: 72
Joined: 05 Jul 2017, 15:19

Re: how can get Bestsellers or Most Popular products?

Post by Ahmad » 12 Nov 2020, 08:39

@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?

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

Re: how can get Bestsellers or Most Popular products?

Post by aimeos » 13 Nov 2020, 13:08

You can use slice():

Code: Select all

$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' );
$items = $cntl->use( ['text', 'price', 'media'] )->product( <ids> )->slice( 0, 10 )->search();
See: https://github.com/aimeos/ai-controller ... #L158-L175
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
peter69
Posts: 98
Joined: 09 Jun 2022, 19:31

Re: how can get Bestsellers or Most Popular products?

Post by peter69 » 21 Oct 2022, 22:28

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.

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();
    }
This function must be in a decorator.

Regards,

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

Re: how can get Bestsellers or Most Popular products?

Post by aimeos » 24 Oct 2022, 17:31

Very cool! :D
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
peter69
Posts: 98
Joined: 09 Jun 2022, 19:31

Re: how can get Bestsellers or Most Popular products?

Post by peter69 » 24 Oct 2022, 22:13

Thanks!!! :))

User avatar
loeffe1
Posts: 54
Joined: 21 Feb 2020, 10:33

Re: how can get Bestsellers or Most Popular products?

Post by loeffe1 » 20 Mar 2023, 08:30

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?

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

Re: how can get Bestsellers or Most Popular products?

Post by aimeos » 21 Mar 2023, 08:04

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/
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply