This commit is contained in:
@@ -19,7 +19,7 @@ use Symfony\Component\Finder\Finder;
|
||||
class HiltesImport
|
||||
{
|
||||
protected $currentDirPath;
|
||||
protected $cachedWarehouseIds;
|
||||
protected $cachedWarehouse;
|
||||
protected $arrData = array();
|
||||
private $productRepository;
|
||||
private $stockRepository;
|
||||
@@ -29,6 +29,8 @@ class HiltesImport
|
||||
private $cachedStockIds;
|
||||
private $rootPath;
|
||||
|
||||
private $deleteFiles = false;
|
||||
|
||||
public function __construct(ProductRepository $productRepository, WarehouseRepository $warehouseRepository, StockRepository $stockRepository, LoggerInterface $logger, string $rootPath)
|
||||
{
|
||||
$this->productRepository = $productRepository;
|
||||
@@ -129,8 +131,10 @@ class HiltesImport
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
|
||||
unlink($srcFile);
|
||||
unlink($srcFile . '.Ende');
|
||||
if ($this->deleteFiles) {
|
||||
unlink($srcFile);
|
||||
unlink($srcFile . '.Ende');
|
||||
}
|
||||
|
||||
$this->logger->info($count . ' Datensätze importiert');
|
||||
|
||||
@@ -151,7 +155,7 @@ class HiltesImport
|
||||
* @param array $arr
|
||||
* @return void
|
||||
*/
|
||||
protected function trimArray(array &$arr): void
|
||||
private function trimArray(array &$arr): void
|
||||
{
|
||||
foreach ($arr as $k => $v) {
|
||||
$arr[$k] = trim($v);
|
||||
@@ -160,11 +164,16 @@ class HiltesImport
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return void
|
||||
* @return false
|
||||
*/
|
||||
protected function saveData(array $data): void
|
||||
protected function saveData(array $data): bool
|
||||
{
|
||||
$warehouse = $this->checkWarehouseName($data[3]);
|
||||
if (!isset($data[3])) {
|
||||
$this->logger->error('No Warehouse' . $data[3]);
|
||||
return false;
|
||||
}
|
||||
|
||||
$warehouse = $this->checkWarehouseName(trim($data[3]));
|
||||
$gtin = $this->checkProduct(substr($data[0], 1));
|
||||
|
||||
if (!empty($warehouse) && !empty($this->cachedStockIds[$gtin][$warehouse->getId()])) {
|
||||
@@ -177,33 +186,35 @@ class HiltesImport
|
||||
|
||||
$stock->setInstock((int)$data[1] / 100);
|
||||
$this->stockRepository->save($stock, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $warehouseName
|
||||
* @return Warehouse|false|mixed|null
|
||||
* @return int
|
||||
*/
|
||||
private function checkWarehouseName(string $warehouseName)
|
||||
{
|
||||
$warehouseName = ltrim($warehouseName, 0);
|
||||
|
||||
if (empty($this->cachedWarehouseIds[$warehouseName])) {
|
||||
$warehouse = $this->warehouseRepository->findOneBy(['id' => (int)$warehouseName]);
|
||||
if (empty($this->cachedWarehouse[$warehouseName])) {
|
||||
$warehouse = $this->warehouseRepository->findOneBy(['name' => $warehouseName]);
|
||||
|
||||
//Wenn kein Lager gefunden wurde, dann lege es an
|
||||
if (empty($warehouse)) {
|
||||
$warehouse = new Warehouse();
|
||||
$warehouse->setId((int)$warehouseName);
|
||||
//$warehouse->setId((int)$warehouseName);
|
||||
$warehouse->setName($warehouseName);
|
||||
$this->warehouseRepository->save($warehouse, true);
|
||||
$warehouseId = $this->warehouseRepository->save($warehouse, true);
|
||||
$newWarehouse = $this->warehouseRepository->findOneBy(['id' => $warehouseId]);
|
||||
|
||||
$this->cachedWarehouse[$warehouseName] = $newWarehouse;
|
||||
} else {
|
||||
$this->cachedWarehouse[$warehouseName] = $warehouse;
|
||||
}
|
||||
$this->cachedWarehouseIds[$warehouseName] = $warehouse;
|
||||
}
|
||||
|
||||
if (!empty($this->cachedWarehouseIds[$warehouseName])) {
|
||||
return $this->cachedWarehouseIds[$warehouseName];
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this->cachedWarehouse[$warehouseName];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user