Fix the adding of compatible batteries for a vehicle. #270
This commit is contained in:
parent
dcd34f6f73
commit
547c13d73b
1 changed files with 41 additions and 22 deletions
|
|
@ -94,6 +94,7 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
|
||||
while (($fields = fgetcsv($fh)) !== false)
|
||||
{
|
||||
$comp_batteries = [];
|
||||
if ($row_num < 1)
|
||||
{
|
||||
$row_num++;
|
||||
|
|
@ -161,17 +162,6 @@ 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]))
|
||||
|
|
@ -190,12 +180,11 @@ 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, $vehicle);
|
||||
$this->addBattery($brand_sdfc, $sdfc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -203,7 +192,7 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
{
|
||||
if (!(empty($ultramax)))
|
||||
{
|
||||
$this->addBattery($brand_ultramax, $ultramax, $vehicle);
|
||||
$this->addBattery($brand_ultramax, $ultramax);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -211,7 +200,7 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
{
|
||||
if (!(empty($motolite)))
|
||||
{
|
||||
$this->addBattery($brand_motolite, $motolite, $vehicle);
|
||||
$this->addBattery($brand_motolite, $motolite);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +208,7 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
{
|
||||
if (!(empty($marathoner)))
|
||||
{
|
||||
$this->addBattery($brand_marathoner, $marathoner, $vehicle);
|
||||
$this->addBattery($brand_marathoner, $marathoner);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -227,10 +216,36 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
{
|
||||
if (!(empty($excel)))
|
||||
{
|
||||
$this->addBattery($brand_excel, $excel, $vehicle);
|
||||
$this->addBattery($brand_excel, $excel);
|
||||
}
|
||||
}
|
||||
|
||||
// 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]))
|
||||
{
|
||||
if (!(empty($sdfc)))
|
||||
$comp_batteries[] = $this->batt_hash[$brand_sdfc][$brand_sdfc][$sdfc];
|
||||
|
||||
if (!(empty($ultramax)))
|
||||
$comp_batteries[] = $this->batt_hash[$brand_ultramax][$brand_ultramax][$ultramax];
|
||||
|
||||
if (!(empty($motolite)))
|
||||
$comp_batteries[] = $this->batt_hash[$brand_motolite][$brand_motolite][$motolite];
|
||||
|
||||
if (!(empty($marathoner)))
|
||||
$comp_batteries[] = $this->batt_hash[$brand_marathoner][$brand_marathoner][$marathoner];
|
||||
|
||||
if (!(empty($excel)))
|
||||
$comp_batteries[] = $this->batt_hash[$brand_excel][$brand_excel][$excel];
|
||||
|
||||
$this->addVehicleMake($manufacturer, $make, $year, $comp_batteries);
|
||||
}
|
||||
|
||||
$row_num++;
|
||||
}
|
||||
}
|
||||
|
|
@ -279,7 +294,7 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
}
|
||||
}
|
||||
|
||||
protected function addBattery($brand, $size, $vehicle)
|
||||
protected function addBattery($brand, $size)
|
||||
{
|
||||
// save to db
|
||||
$bmanu = $this->bmanu_hash[$brand];
|
||||
|
|
@ -294,9 +309,6 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
->setWarrantyCommercial(6)
|
||||
->setWarrantyTnv(12);
|
||||
|
||||
// add compatible vehicles to battery
|
||||
$battery->addVehicle($vehicle);
|
||||
|
||||
$this->em->persist($battery);
|
||||
$this->em->flush();
|
||||
|
||||
|
|
@ -329,7 +341,7 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
$this->vmanu_hash[$name] = $vehicle_manufacturer;
|
||||
}
|
||||
|
||||
protected function addVehicleMake($manufacturer, $make, $year)
|
||||
protected function addVehicleMake($manufacturer, $make, $year, $batteries)
|
||||
{
|
||||
// save to db
|
||||
$vehicle = new Vehicle();
|
||||
|
|
@ -358,6 +370,13 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
->setModelYearFrom($year_from)
|
||||
->setModelYearTo($year_to);
|
||||
|
||||
// add vehicle to battery
|
||||
foreach ($batteries as $battery)
|
||||
{
|
||||
$battery->addVehicle($vehicle);
|
||||
$this->em->persist($battery);
|
||||
}
|
||||
|
||||
// add vehicle to manufacturer
|
||||
$vmanu->addVehicle($vehicle);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue