Fix adding of compatible batteries to vehicles. #270

This commit is contained in:
Korina Cordero 2019-10-03 04:12:12 +00:00
parent 2b48c702d4
commit dcd34f6f73

View file

@ -92,8 +92,6 @@ class ImportCMBBatteryDataCommand extends Command
$brand_marathoner = '';
$brand_excel = '';
$comp_batteries = [];
while (($fields = fgetcsv($fh)) !== false)
{
if ($row_num < 1)
@ -163,6 +161,17 @@ class ImportCMBBatteryDataCommand extends Command
{
// vehicle and battery data
// vehicle data
// check if vehicle manufacturer has been added
if (!isset($this->vmanu_hash[$manufacturer]))
$this->addVehicleManufacturer($manufacturer);
// check if vehicle make has been added
if (!isset($this->vmake_hash[$manufacturer][$make]))
{
$this->addVehicleMake($manufacturer, $make, $year);
}
// battery size
// check if battery size has been added
if (!isset($this->bsize_hash[$sdfc]))
@ -181,12 +190,12 @@ class ImportCMBBatteryDataCommand extends Command
$this->addBatterySize($excel);
// check if battery has been added
$vehicle = $this->vmake_hash[$manufacturer][$make];
if (!isset($this->batt_hash[$brand_sdfc][$brand_sdfc][$sdfc]))
{
if (!(empty($sdfc)))
{
$this->addBattery($brand_sdfc, $sdfc);
$comp_batteries[] = $this->batt_hash[$brand_sdfc][$brand_sdfc][$sdfc];
$this->addBattery($brand_sdfc, $sdfc, $vehicle);
}
}
@ -194,8 +203,7 @@ class ImportCMBBatteryDataCommand extends Command
{
if (!(empty($ultramax)))
{
$this->addBattery($brand_ultramax, $ultramax);
$comp_batteries[] = $this->batt_hash[$brand_ultramax][$brand_ultramax][$ultramax];
$this->addBattery($brand_ultramax, $ultramax, $vehicle);
}
}
@ -203,8 +211,7 @@ class ImportCMBBatteryDataCommand extends Command
{
if (!(empty($motolite)))
{
$this->addBattery($brand_motolite, $motolite);
$comp_batteries[] = $this->batt_hash[$brand_motolite][$brand_motolite][$motolite];
$this->addBattery($brand_motolite, $motolite, $vehicle);
}
}
@ -212,8 +219,7 @@ class ImportCMBBatteryDataCommand extends Command
{
if (!(empty($marathoner)))
{
$this->addBattery($brand_marathoner, $marathoner);
$comp_batteries[] = $this->batt_hash[$brand_marathoner][$brand_marathoner][$marathoner];
$this->addBattery($brand_marathoner, $marathoner, $vehicle);
}
}
@ -221,22 +227,10 @@ class ImportCMBBatteryDataCommand extends Command
{
if (!(empty($excel)))
{
$this->addBattery($brand_excel, $excel);
$comp_batteriesp[] = $this->batt_hash[$brand_excel][$brand_excel][$excel];
$this->addBattery($brand_excel, $excel, $vehicle);
}
}
// vehicle data
// check if vehicle manufacturer has been added
if (!isset($this->vmanu_hash[$manufacturer]))
$this->addVehicleManufacturer($manufacturer);
// check if vehicle make has been added
if (!isset($this->vmake_hash[$manufacturer][$make]))
{
$this->addVehicleMake($manufacturer, $make, $year, $comp_batteries);
}
$row_num++;
}
}
@ -280,13 +274,12 @@ class ImportCMBBatteryDataCommand extends Command
$this->em->persist($batt_size);
$this->em->flush();
// add new size into hash
$this->bsize_hash[$name] = $batt_size;
}
}
protected function addBattery($brand, $size)
protected function addBattery($brand, $size, $vehicle)
{
// save to db
$bmanu = $this->bmanu_hash[$brand];
@ -301,6 +294,9 @@ class ImportCMBBatteryDataCommand extends Command
->setWarrantyCommercial(6)
->setWarrantyTnv(12);
// add compatible vehicles to battery
$battery->addVehicle($vehicle);
$this->em->persist($battery);
$this->em->flush();
@ -333,7 +329,7 @@ class ImportCMBBatteryDataCommand extends Command
$this->vmanu_hash[$name] = $vehicle_manufacturer;
}
protected function addVehicleMake($manufacturer, $make, $year, $batteries)
protected function addVehicleMake($manufacturer, $make, $year)
{
// save to db
$vehicle = new Vehicle();
@ -365,15 +361,12 @@ class ImportCMBBatteryDataCommand extends Command
// add vehicle to manufacturer
$vmanu->addVehicle($vehicle);
// add battery to vehicle
foreach ($batteries as $battery)
{
$vehicle->addBattery($battery);
}
$this->em->persist($vmanu);
$this->em->persist($vehicle);
$this->em->flush();
// add to hash
$this->vmake_hash[$manufacturer][$make] = $vehicle;
}
protected function loadBatteryManufacturers()