@@ -27,7 +27,7 @@ class ManufacturerImporter extends ItemImporter
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a supplier if a duplicate does not exist.
|
||||
* Create a manufacturer if a duplicate does not exist.
|
||||
* @todo Investigate how this should interact with Importer::createManufacturerIfNotExists
|
||||
*
|
||||
* @author A. Gianotto
|
||||
@@ -39,16 +39,16 @@ class ManufacturerImporter extends ItemImporter
|
||||
|
||||
$editingManufacturer = false;
|
||||
|
||||
$supplier = Manufacturer::where('name', '=', $this->findCsvMatch($row, 'name'))->first();
|
||||
$manufacturer = Manufacturer::where('name', '=', $this->findCsvMatch($row, 'name'))->first();
|
||||
|
||||
if ($this->findCsvMatch($row, 'id')!='') {
|
||||
// Override supplier if an ID was given
|
||||
\Log::debug('Finding supplier by ID: '.$this->findCsvMatch($row, 'id'));
|
||||
$supplier = Manufacturer::find($this->findCsvMatch($row, 'id'));
|
||||
// Override manufacturer if an ID was given
|
||||
\Log::debug('Finding manufacturer by ID: '.$this->findCsvMatch($row, 'id'));
|
||||
$manufacturer = Manufacturer::find($this->findCsvMatch($row, 'id'));
|
||||
}
|
||||
|
||||
|
||||
if ($supplier) {
|
||||
if ($manufacturer) {
|
||||
if (! $this->updating) {
|
||||
$this->log('A matching Manufacturer '.$this->item['name'].' already exists');
|
||||
return;
|
||||
@@ -58,8 +58,8 @@ class ManufacturerImporter extends ItemImporter
|
||||
$editingManufacturer = true;
|
||||
} else {
|
||||
$this->log('No Matching Manufacturer, Create a new one');
|
||||
$supplier = new Manufacturer;
|
||||
$supplier->created_by = auth()->id();
|
||||
$manufacturer = new Manufacturer;
|
||||
$manufacturer->created_by = auth()->id();
|
||||
}
|
||||
|
||||
// Pull the records from the CSV to determine their values
|
||||
@@ -79,21 +79,21 @@ class ManufacturerImporter extends ItemImporter
|
||||
|
||||
|
||||
if ($editingManufacturer) {
|
||||
Log::debug('Updating existing supplier');
|
||||
$supplier->update($this->sanitizeItemForUpdating($supplier));
|
||||
Log::debug('Updating existing manufacturer');
|
||||
$manufacturer->update($this->sanitizeItemForUpdating($manufacturer));
|
||||
} else {
|
||||
Log::debug('Creating supplier');
|
||||
$supplier->fill($this->sanitizeItemForStoring($supplier));
|
||||
Log::debug('Creating manufacturer');
|
||||
$manufacturer->fill($this->sanitizeItemForStoring($manufacturer));
|
||||
}
|
||||
|
||||
if ($supplier->save()) {
|
||||
$this->log('Manufacturer '.$supplier->name.' created or updated from CSV import');
|
||||
return $supplier;
|
||||
if ($manufacturer->save()) {
|
||||
$this->log('Manufacturer '.$manufacturer->name.' created or updated from CSV import');
|
||||
return $manufacturer;
|
||||
|
||||
} else {
|
||||
Log::debug($supplier->getErrors());
|
||||
$this->logError($supplier, 'Manufacturer "'.$this->item['name'].'"');
|
||||
return $supplier->errors;
|
||||
Log::debug($manufacturer->getErrors());
|
||||
$this->logError($manufacturer, 'Manufacturer "'.$this->item['name'].'"');
|
||||
return $manufacturer->errors;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user