Help for integrating the Laravel package
Forum rules: Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
#4939 by Ahmad
11 Nov 2017, 22:30
i have a home page for my aimeos laravel shop,
i want to show in this page on different section a list of products,
for example:
In one section, the list of products that have the most sales,
In the other section, see the list of popular products,
In one section, the list of products that have special discounts (not regular discounts),
In one section, the product list is a specified category

i want to get this lists in home page controller (For example, in the form of an array) with label/title in locale language, photos, price and stocklevel and show them in view

Please guide me as you can
#4946 by aimeos
12 Nov 2017, 12:02
For performance reasons it's best to organize your products in different categories and fetch them via the product controller (
Code: Select all$context = $this->app->make('\Aimeos\Shop\Base\Context')->get();
$cntl = \Aimeos\Controller\Frontend\Factory::createController( $context, 'product' );
$filter = $filter->addFilterCategory( $cntl->createFilter(), <catid> );
$items = $cntl->searchItems( $filter, ['text', 'price', 'media'] );

Otherwise, you would have to aggregate over all orders to see if which products have the most sales or define somehow what are popular products or products with "special" discounts.

Stock levels must be retrieved separately for the products (
Code: Select all$cntl = \Aimeos\Controller\Frontend\Factory::createController( $context, 'stock' );
$filter = $filter->addFilterCodes( $cntl->createFilter(), <list of product codes> );
$stockItems = $cntl->searchItems( $filter );

The the "catalog/lists" component, this is done in a separate request for performance reasons because stock levels can't be cached like the rest of the product data.