From 1a27e28ff533c2481a665690aab9cf7bf44e4e29 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 25 Dec 2016 12:32:11 +0200 Subject: [PATCH] Support importing products using JSON --- app/Services/ImportService.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index bb80ba840383..f35bb14b077e 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -150,6 +150,16 @@ class ImportService $this->checkClientCount(count($json['clients'])); + foreach ($json['products'] as $jsonProduct) { + if (EntityModel::validate($jsonProduct, ENTITY_PRODUCT) === true) { + $product = $this->productRepo->save($jsonProduct); + $this->addSuccess($product); + } else { + $this->addFailure(ENTITY_PRODUCT, $jsonProduct); + continue; + } + } + foreach ($json['clients'] as $jsonClient) { if (EntityModel::validate($jsonClient, ENTITY_CLIENT) === true) { @@ -677,7 +687,7 @@ class ImportService { EntityModel::$notifySubscriptions = false; - foreach ([ENTITY_CLIENT, ENTITY_INVOICE, ENTITY_PAYMENT, ENTITY_QUOTE] as $entityType) { + foreach ([ENTITY_CLIENT, ENTITY_INVOICE, ENTITY_PAYMENT, ENTITY_QUOTE, ENTITY_PRODUCT] as $entityType) { $this->results[$entityType] = [ RESULT_SUCCESS => [], RESULT_FAILURE => [],