Fixes/changes for pull request #349

This commit is contained in:
Bernd Bestel
2019-08-31 14:08:15 +02:00
parent 6ec3872518
commit a4454f825a
2 changed files with 23 additions and 17 deletions

View File

@@ -556,23 +556,28 @@ class StockService extends BaseService
throw new \Exception('Shopping list does not exist');
}
$alreadyExistingEntry = $this->Database->shopping_list()->where('product_id', $productId->id)->fetch();
if ($alreadyExistingEntry) // Update
{
$alreadyExistingEntry->update(array(
'amount' => ($alreadyExistingEntry->amount + $amount),
'shopping_list_id' => $listId
));
}
else // Insert
{
$shoppinglistRow = $this->Database->shopping_list()->createRow(array(
'product_id' => $productId->id,
'amount' => $amount,
'shopping_list_id' => $listId
));
$shoppinglistRow->save();
}
if (!$this->ProductExists($productId))
{
throw new \Exception('Product does not exist');
}
$alreadyExistingEntry = $this->Database->shopping_list()->where('product_id = :1 AND shopping_list_id = :2', $productId, $listId)->fetch();
if ($alreadyExistingEntry) // Update
{
$alreadyExistingEntry->update(array(
'amount' => ($alreadyExistingEntry->amount + $amount),
'shopping_list_id' => $listId
));
}
else // Insert
{
$shoppinglistRow = $this->Database->shopping_list()->createRow(array(
'product_id' => $productId->id,
'amount' => $amount,
'shopping_list_id' => $listId
));
$shoppinglistRow->save();
}
}
private function ProductExists($productId)