feat: infinity scroll, load more, resore scroll
This commit is contained in:
@@ -13,6 +13,7 @@ use Openguru\OpenCartFramework\ImageTool\ImageToolInterface;
|
||||
use Openguru\OpenCartFramework\QueryBuilder\Builder;
|
||||
use Openguru\OpenCartFramework\QueryBuilder\JoinClause;
|
||||
use Openguru\OpenCartFramework\Support\Arr;
|
||||
use Openguru\OpenCartFramework\Support\PaginationHelper;
|
||||
|
||||
class ProductsHandler
|
||||
{
|
||||
@@ -43,7 +44,7 @@ class ProductsHandler
|
||||
{
|
||||
$languageId = 1;
|
||||
$page = $request->get('page', 1);
|
||||
$perPage = $request->get('perPage', 10);
|
||||
$perPage = 10;
|
||||
$categoryId = (int) $request->get('categoryId', 0);
|
||||
$categoryName = '';
|
||||
|
||||
@@ -59,7 +60,7 @@ class ProductsHandler
|
||||
->value('name');
|
||||
}
|
||||
|
||||
$products = $this->queryBuilder->newQuery()
|
||||
$productsQuery = $this->queryBuilder->newQuery()
|
||||
->select([
|
||||
'products.product_id' => 'product_id',
|
||||
'products.quantity' => 'product_quantity',
|
||||
@@ -84,7 +85,13 @@ class ProductsHandler
|
||||
->where('product_to_category.category_id', '=', $categoryId);
|
||||
}
|
||||
);
|
||||
})
|
||||
});
|
||||
|
||||
$total = $productsQuery->count();
|
||||
$lastPage = PaginationHelper::calculateLastPage($total, $perPage);
|
||||
$hasMore = $page + 1 <= $lastPage;
|
||||
|
||||
$products = $productsQuery
|
||||
->forPage($page, $perPage)
|
||||
->orderBy('date_added', 'DESC')
|
||||
->get();
|
||||
@@ -152,6 +159,7 @@ class ProductsHandler
|
||||
|
||||
'meta' => [
|
||||
'currentCategoryName' => $categoryName,
|
||||
'hasMore' => $hasMore,
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user