import hiltes
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
namespace App\Helper;
|
||||
|
||||
|
||||
use App\Entity\Product;
|
||||
use App\Entity\Stock;
|
||||
use App\Entity\Warehouse;
|
||||
use App\Repository\ProductRepository;
|
||||
use App\Repository\StockRepository;
|
||||
use App\Repository\WarehouseRepository;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
@@ -13,17 +15,19 @@ use Symfony\Component\Finder\Finder;
|
||||
|
||||
class HiltesImport
|
||||
{
|
||||
private $productRepository;
|
||||
private $stockRepository;
|
||||
private $warehouseRepository;
|
||||
private $logger;
|
||||
protected $currentDirPath;
|
||||
protected $arrData = array();
|
||||
|
||||
public function __construct(StockRepository $stockRepository, WarehouseRepository $warehouseRepository, LoggerInterface $logger)
|
||||
public function __construct(ProductRepository $productRepository, LoggerInterface $logger)
|
||||
{
|
||||
$this->stockRepository = $stockRepository;
|
||||
$this->warehouseRepository = $warehouseRepository;
|
||||
// $this->stockRepository = $stockRepository;
|
||||
// $this->warehouseRepository = $warehouseRepository;
|
||||
|
||||
$this->productRepository = $productRepository;
|
||||
$this->logger = $logger;
|
||||
|
||||
$this->currentDirPath = getcwd();
|
||||
@@ -50,7 +54,6 @@ class HiltesImport
|
||||
}
|
||||
protected function getFiles()
|
||||
{
|
||||
$return = true;
|
||||
$finder = Finder::create();
|
||||
$finder
|
||||
->in($this->currentDirPath.'/hiltes/h2c/')
|
||||
@@ -65,47 +68,34 @@ class HiltesImport
|
||||
'fileSize' => $file->getFileInfo()->getSize(),
|
||||
'onlyFileName' => $file->getRelativePathname(),
|
||||
);
|
||||
/*
|
||||
$absoluteFilePath = $file->getRealPath();
|
||||
$fileInfo = $file->getFileInfo();
|
||||
$fileNameWithExtension = $file->getRelativePathname();
|
||||
dump($absoluteFilePath);
|
||||
dump($fileInfo->getSize());
|
||||
dump($fileNameWithExtension);
|
||||
*/
|
||||
#dump($this->arrData);
|
||||
}
|
||||
return $return;
|
||||
}else{
|
||||
return $return;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#print_r(\iterator_to_array($finder,true));
|
||||
return true;
|
||||
}
|
||||
protected function loadFiles($srcFile,$size)
|
||||
{
|
||||
# $t = memory_get_usage();
|
||||
# dump($t);
|
||||
|
||||
$file = new \SplFileObject($srcFile);
|
||||
# dump(memory_get_usage()-$t);
|
||||
|
||||
|
||||
dump($file->getRealPath());
|
||||
|
||||
$this->logger->info('Starte Import von ' . $file->getRealPath());
|
||||
|
||||
$c = 0;
|
||||
while (!$file->eof()) {
|
||||
$c++;
|
||||
// Header überspringen
|
||||
if($c == 1){ continue; }
|
||||
|
||||
$c++;
|
||||
#*** Convertiert die Zeile in UTF8
|
||||
//$str = iconv('ISO-8859-1','UTF-8',$file->fgets());
|
||||
|
||||
#*** Zerlegt die Zeile **********
|
||||
$arr = $this->splitLine($file->fgets());
|
||||
$this->switchSaveData($arr);
|
||||
$data = $file->fgets();
|
||||
if($c <= 1){ continue; }
|
||||
|
||||
$this->switchSaveData($this->splitLine($data));
|
||||
}
|
||||
|
||||
dump($c . ' Datensätze importiert');
|
||||
@@ -180,9 +170,7 @@ class HiltesImport
|
||||
$arr[$k] = trim($v);
|
||||
}
|
||||
}
|
||||
protected function saveInfoDatei(Array $arr){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $arr
|
||||
@@ -190,41 +178,57 @@ class HiltesImport
|
||||
*/
|
||||
protected function saveData(Array $arr){
|
||||
#dump($arr);
|
||||
$stock = new Stock();
|
||||
$prod = new Product();
|
||||
|
||||
$stock = new Stock();
|
||||
$stock->setInstock((int)$arr[2]);
|
||||
|
||||
$warehouse = new Warehouse();
|
||||
$warehouse->setName($arr[0]);
|
||||
// $stock->setWarehouse($warehouse);
|
||||
|
||||
#menge;
|
||||
$stock->setStock((int)$arr[2]);
|
||||
$prod->setStock($stock);
|
||||
|
||||
#gtin;
|
||||
$prod->setGtin($arr[1]);
|
||||
|
||||
$prod->setShopwareId("");
|
||||
|
||||
|
||||
// dump($prod);
|
||||
|
||||
$this->productRepository->save($prod,true);
|
||||
|
||||
//$stock->setStock((int)$arr[2]);
|
||||
|
||||
#filiale;
|
||||
|
||||
$warehouse = $this->warehouseRepository->findOneBy(['id'=> $arr[2]]);
|
||||
|
||||
|
||||
|
||||
if($warehouse instanceof Warehouse){
|
||||
$stock->setWarehouseId($warehouse->getId());
|
||||
}else{
|
||||
$warehouse = new Warehouse();
|
||||
$warehouse->setId((int)$arr[2]);
|
||||
$warehouse->setPriority(0);
|
||||
$id = $this->warehouseRepository->add($warehouse, true);
|
||||
# $stock->setWarehouseId($id);
|
||||
}
|
||||
//
|
||||
// $warehouse = $this->warehouseRepository->findOneBy(['id'=> $arr[2]]);
|
||||
//
|
||||
//
|
||||
//
|
||||
// if($warehouse instanceof Warehouse){
|
||||
// $stock->setWarehouseId($warehouse->getId());
|
||||
// }else{
|
||||
// $warehouse = new Warehouse();
|
||||
// $warehouse->setId((int)$arr[2]);
|
||||
// $warehouse->setPriority(0);
|
||||
// $id = $this->warehouseRepository->add($warehouse, true);
|
||||
// # $stock->setWarehouseId($id);
|
||||
// }
|
||||
|
||||
#
|
||||
|
||||
// $stock->setWarehouseId($warehouse->getId());
|
||||
|
||||
#gtin;
|
||||
$stock->setGtin($arr[1]);
|
||||
|
||||
try{
|
||||
$this->stockRepository->upsert($stock);
|
||||
}catch (\Exception $e){
|
||||
$this->logger->error($e->getMessage());
|
||||
dump($e->getMessage());
|
||||
}
|
||||
// try{
|
||||
// $this->stockRepository->upsert($stock);
|
||||
// }catch (\Exception $e){
|
||||
// $this->logger->error($e->getMessage());
|
||||
// dump($e->getMessage());
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user