Added on option to only show in-stock products on the /products page (closes #1388)

This commit is contained in:
Bernd Bestel
2021-07-06 20:08:02 +02:00
parent 6530d0f9df
commit 1ead23cb87
5 changed files with 50 additions and 8 deletions

View File

@@ -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'),