Improved documentation and added example CSV file

This commit is contained in:
Jan Böhmer 2023-03-15 21:33:18 +01:00
parent 2c799d894b
commit b7aae7d87b
4 changed files with 27 additions and 1 deletions

View file

@ -33,6 +33,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use UnexpectedValueException;
class PartImportExportController extends AbstractController
@ -93,6 +94,9 @@ class PartImportExportController extends AbstractController
$errors = $this->entityImporter->importFileAndPersistToDB($file, $options, $entities);
} catch (UnexpectedValueException $e) {
$this->addFlash('error', 'parts.import.flash.error.invalid_file');
if ($e instanceof NotNormalizableValueException) {
$this->addFlash('error', $e->getMessage());
}
goto ret;
}

View file

@ -103,13 +103,24 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface, Cach
$data['ipn'] = null;
}
//Fill empty needs_review and needs_review_comment fields with false
if (empty($data['needs_review'])) {
$data['needs_review'] = false;
}
if (empty($data['favorite'])) {
$data['favorite'] = false;
}
if (empty($data['minamount'])) {
$data['minamount'] = 0.0;
}
$object = $this->normalizer->denormalize($data, $type, $format, $context);
if (!$object instanceof Part) {
throw new \InvalidArgumentException('This normalizer only supports Part objects!');
}
if (isset($data['instock']) || isset($data['storelocation'])) {
if ((isset($data['instock']) && trim($data['instock']) !== "") || (isset($data['storelocation']) && trim($data['storelocation']) !== "")) {
$partLot = new PartLot();
if (isset($data['instock']) && $data['instock'] !== "") {