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

how can get Bestsellers or Most Popular products?

Post by Ahmad » 11 Nov 2017, 17:02

i have a home page and want to show top 10 bestsellers products and top 10 most popular products in this page or sidebar of another pages?
What should I do?

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

Re: how can get Bestsellers or Most Popular products?

Post by aimeos » 12 Nov 2017, 11:40

Add the "catalog/lists" component to your controller action that is rendering the home page: https://aimeos.org/docs/Laravel/Create_new_pages
Please read https://aimeos.org/docs/Laravel/Adapt_pages too.

Add your top seller products to the "home" category (the root category node). In the action for the home page, configure the default category ID of your "home" category (https://aimeos.org/docs/Configuration/C ... id-default):

Code: Select all

$context = $this->app->make('\Aimeos\Shop\Base\Context')->get();
$context->getConfig()->set( 'client/html/catalog/lists/catid-default', 123 );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Ahmad
Posts: 72
Joined: 05 Jul 2017, 15:19

Re: how can get Bestsellers or Most Popular products?

Post by Ahmad » 12 Nov 2017, 13:11

aimeos wrote:Add the "catalog/lists" component to your controller action that is rendering the home page: https://aimeos.org/docs/Laravel/Create_new_pages
Please read https://aimeos.org/docs/Laravel/Adapt_pages too.

Add your top seller products to the "home" category (the root category node). In the action for the home page, configure the default category ID of your "home" category (https://aimeos.org/docs/Configuration/C ... id-default):

Code: Select all

$context = $this->app->make('\Aimeos\Shop\Base\Context')->get();
$context->getConfig()->set( 'client/html/catalog/lists/catid-default', 123 );
Thank you, but you did not understand my question correctly

I want to get a list of the top 10 products that have the most sales
In other words, I want to get a list of 10 products, bought by customers more than other products
Also, consider that the products may be in different categories, but it does not matter which category they are to get the list
Or if we want to specify that the products with the most sales are in this category, we specify that if they are in category 1 or 2 or 3 or any category id that i set.

i want to get this list with product controller as an array

please help me and if you can code it for me...

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 2017, 15:55

If you want to evalute the top seller products dynamically, you first have to find out which products are sold most:

Code: Select all

$manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' );
$filter = $manager->createSearch();
$result = $manager->aggregate( $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\Factory::createController( $context, 'product' );
$items = $cntl->getProductItems( <ids>, ['text', 'price', 'media'] );
We always suggest to do this once a day in a job controller instead and populate a special category with that products!
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Ahmad
Posts: 72
Joined: 05 Jul 2017, 15:19

Re: how can get Bestsellers or Most Popular products?

Post by Ahmad » 07 Sep 2020, 16:28

aimeos wrote: 13 Nov 2017, 15:55 If you want to evalute the top seller products dynamically, you first have to find out which products are sold most:

Code: Select all

$manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' );
$filter = $manager->createSearch();
$result = $manager->aggregate( $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\Factory::createController( $context, 'product' );
$items = $cntl->getProductItems( <ids>, ['text', 'price', 'media'] );
We always suggest to do this once a day in a job controller instead and populate a special category with that products!
@aimeos
hi, because of i get Factory class and getProductItems not found,
please put updated above code (or new solution) that work in version 2020.04.

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

Re: how can get Bestsellers or Most Popular products?

Post by aimeos » 08 Sep 2020, 15:14

For 2020.x use:

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

Ahmad
Posts: 72
Joined: 05 Jul 2017, 15:19

Re: how can get Bestsellers or Most Popular products?

Post by Ahmad » 08 Sep 2020, 21:15

aimeos wrote: 08 Sep 2020, 15:14 For 2020.x use:

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->use( ['text', 'price', 'media'] )->product( <ids> )->search();
i use this code but get this errors:
ArgumentCountError
Too few arguments to function Aimeos\MW\Common\Manager\Base::filter(), 0 passed and exactly 1 expected


when i change $manager->filter() to $manager->createSearch() get another error:

Aimeos\Controller\Frontend\Exception
Unable to call method "use"


What change should I make?

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

Re: how can get Bestsellers or Most Popular products?

Post by aimeos » 09 Sep 2020, 06:43

Please note that this works in 2020.07+ and older versions like 2020.04 are not supported any more.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Ahmad
Posts: 72
Joined: 05 Jul 2017, 15:19

Re: how can get Bestsellers or Most Popular products?

Post by Ahmad » 09 Sep 2020, 08:34

aimeos wrote: 09 Sep 2020, 06:43 Please note that this works in 2020.07+ and older versions like 2020.04 are not supported any more.
in version 2020.04 what can i do to get this result?

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

Re: how can get Bestsellers or Most Popular products?

Post by aimeos » 09 Sep 2020, 08:39

Sorry, it must be "uses()" and you can use "$manager->createSearch()" for 2020.04 even if it's highly recommended to update to 2020.07.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply