mirror of
https://github.com/grocy/grocy.git
synced 2025-08-15 02:04:38 +00:00
Added on option to only show in-stock products on the /products page (closes #1388)
This commit is contained in:
@@ -233,15 +233,19 @@ class StockController extends BaseController
|
||||
|
||||
public function ProductsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
if (isset($request->getQueryParams()['include_disabled']))
|
||||
$products = $this->getDatabase()->products();
|
||||
if (!isset($request->getQueryParams()['include_disabled']))
|
||||
{
|
||||
$products = $this->getDatabase()->products()->orderBy('name', 'COLLATE NOCASE');
|
||||
$products = $products->where('active = 1');
|
||||
}
|
||||
else
|
||||
|
||||
if (isset($request->getQueryParams()['only_in_stock']))
|
||||
{
|
||||
$products = $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE');
|
||||
$products = $products->where('id IN (SELECT product_id from stock_current WHERE amount_aggregated > 0)');
|
||||
}
|
||||
|
||||
$products = $products->orderBy('name', 'COLLATE NOCASE');
|
||||
|
||||
return $this->renderPage($response, 'products', [
|
||||
'products' => $products,
|
||||
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
|
||||
|
Reference in New Issue
Block a user