Redo the import tradein price command. #270

This commit is contained in:
Korina Cordero 2019-10-11 09:13:30 +00:00
parent 02b88bca64
commit 6d0af26981

View file

@ -57,7 +57,7 @@ class ImportCMBBatteryTradeInPriceCommand extends Command
// loop through the rows
$row_num = 0;
error_log('Processing battery price csv file...');
error_log('Processing battery tradein price csv file...');
while (($fields = fgetcsv($fh)) !== false)
{
// data starts at row 2
@ -78,11 +78,9 @@ class ImportCMBBatteryTradeInPriceCommand extends Command
$size = $size_info[1];
$batt_size = $this->findBatterySize($size);
if (isset($this->bsize_hash[$batt_size]))
if (isset($this->bsize_hash[$size]))
{
$battery_size = $this->bsize_hash[$batt_size];
$battery_size = $this->bsize_hash[$size];
// use TIPriceMotolite
$battery_size->setTIPriceMotolite($clean_price);
@ -99,54 +97,6 @@ class ImportCMBBatteryTradeInPriceCommand extends Command
}
}
protected function findBatterySize($bsize)
{
$batt_size = null;
// check if battery size has parenthesis
$pos = stripos($bsize, '(');
if ($pos == true)
{
// parse battery size because of Q85(insert string here) and M42? M-42?(insert string here)
// explode and get the first element
$batts = explode('(', $bsize);
$bsize = trim($batts[0]);
//error_log('new battery size ' . $bsize);
}
// check if size is set
if (!isset($this->bsize_hash[$bsize]))
{
// loop through the hash since the size might be part of the sizes with '/'
foreach ($this->bsize_hash as $key => $data)
{
$pos = stripos($key, '/');
if ($pos == true)
{
// explode the key
$key_strings = explode('/', $key);
foreach ($key_strings as $ks)
{
$clean_ks = trim($ks);
if (strcasecmp($bsize, $clean_ks) == 0)
{
// bsize is one of the sizes with '/'
$batt_size = $key;
//error_log($batt_size);
return $batt_size;
}
}
}
}
}
else
{
$batt_size = $bsize;
}
return $batt_size;
}
protected function loadBatterySizes()
{
$this->bsize_hash = [];