Page 1 of 2

how can get Bestsellers or Most Popular products?

Posted: 11 Nov 2017, 17:02
by Ahmad
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?

Re: how can get Bestsellers or Most Popular products?

Posted: 12 Nov 2017, 11:40
by aimeos
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 );

Re: how can get Bestsellers or Most Popular products?

Posted: 12 Nov 2017, 13:11
by Ahmad
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...

Re: how can get Bestsellers or Most Popular products?

Posted: 13 Nov 2017, 15:55
by aimeos
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!

Re: how can get Bestsellers or Most Popular products?

Posted: 07 Sep 2020, 16:28
by Ahmad
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.

Re: how can get Bestsellers or Most Popular products?

Posted: 08 Sep 2020, 15:14
by aimeos
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();

Re: how can get Bestsellers or Most Popular products?

Posted: 08 Sep 2020, 21:15
by Ahmad
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?

Re: how can get Bestsellers or Most Popular products?

Posted: 09 Sep 2020, 06:43
by aimeos
Please note that this works in 2020.07+ and older versions like 2020.04 are not supported any more.

Re: how can get Bestsellers or Most Popular products?

Posted: 09 Sep 2020, 08:34
by Ahmad
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?

Re: how can get Bestsellers or Most Popular products?

Posted: 09 Sep 2020, 08:39
by aimeos
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.