From 411aad239832b9dcff65bee1622f8582c35f8395 Mon Sep 17 00:00:00 2001 From: Forceu Date: Tue, 13 Aug 2019 12:20:14 +0200 Subject: [PATCH] Set stock amount to 0 instead of null if product not in stock Without this the API returns null instead of 0 when queried for product stock amount --- services/StockService.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/StockService.php b/services/StockService.php index cf616707..2dd33c4d 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -78,6 +78,10 @@ class StockService extends BaseService $product = $this->Database->products($productId); $productStockAmount = $this->Database->stock()->where('product_id', $productId)->sum('amount'); + if ($productStockAmount == null) + { + $productStockAmount = 0; + } $productStockAmountOpened = $this->Database->stock()->where('product_id = :1 AND open = 1', $productId)->sum('amount'); $productLastPurchased = $this->Database->stock_log()->where('product_id', $productId)->where('transaction_type', self::TRANSACTION_TYPE_PURCHASE)->where('undone', 0)->max('purchased_date'); $productLastUsed = $this->Database->stock_log()->where('product_id', $productId)->where('transaction_type', self::TRANSACTION_TYPE_CONSUME)->where('undone', 0)->max('used_date');