Feature request : api/stock can return detailed products #487 (#503)

The response of the call '/api/stock' now returns a new attribute
('product') which contains the details of the related product.
This commit is contained in:
Grégory SACRE
2020-01-19 09:14:07 +01:00
committed by Bernd Bestel
parent cd522220ce
commit 61a45c030f
2 changed files with 35 additions and 15 deletions

View File

@@ -4065,6 +4065,9 @@
"is_aggregated_amount": {
"type": "boolean",
"description": "Indicates wheter this product has sub-products or not / if the fields `amount_aggregated` and `amount_opened_aggregated` are filled"
},
"product": {
"$ref": "#/components/schemas/Product"
}
}
},

View File

@@ -27,7 +27,24 @@ class StockService extends BaseService
$sql = 'SELECT * FROM stock_current WHERE best_before_date IS NOT NULL UNION SELECT id, 0, 0, null, 0, 0, 0 FROM ' . $missingProductsView . ' WHERE id NOT IN (SELECT product_id FROM stock_current)';
}
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
$current_stock = $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
$stock_array = [];
foreach ($current_stock as $cur) {
$stock_array[$cur->product_id] = $cur;
}
$list_of_product_ids = implode(",", array_keys($stock_array));
$sql = 'SELECT * FROM products WHERE id in (' . $list_of_product_ids . ')';
$products = $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
foreach ($products as $product) {
$stock_array[$product->id]->product = $product;
}
return $stock_array;
}
public function GetCurrentStockLocationContent()