Improve API related changes regarding multiple shopping lists (references #190)

This commit is contained in:
Bernd Bestel
2019-04-22 08:21:57 +02:00
parent 49d16b458d
commit 162adeb359
3 changed files with 66 additions and 16 deletions

View File

@@ -432,6 +432,11 @@ class StockService extends BaseService
public function AddMissingProductsToShoppingList($listId = 1)
{
if (!$this->ShoppingListExists($listId))
{
throw new \Exception('Shopping list does not exist');
}
$missingProducts = $this->GetMissingProducts();
foreach ($missingProducts as $missingProduct)
{
@@ -463,6 +468,11 @@ class StockService extends BaseService
public function ClearShoppingList($listId = 1)
{
if (!$this->ShoppingListExists($listId))
{
throw new \Exception('Shopping list does not exist');
}
$this->Database->shopping_list()->where('shopping_list_id = :1', $listId)->delete();
}
@@ -472,6 +482,12 @@ class StockService extends BaseService
return $productRow !== null;
}
private function ShoppingListExists($listId)
{
$shoppingListRow = $this->Database->shopping_lists()->where('id = :1', $listId)->fetch();
return $shoppingListRow !== null;
}
private function LoadBarcodeLookupPlugin()
{
$pluginName = defined('GROCY_STOCK_BARCODE_LOOKUP_PLUGIN') ? GROCY_STOCK_BARCODE_LOOKUP_PLUGIN : '';