import hiltes
This commit is contained in:
@@ -4,7 +4,9 @@ namespace App\Helper;
|
||||
|
||||
|
||||
use App\Entity\Stock;
|
||||
use App\Entity\Warehouse;
|
||||
use App\Repository\StockRepository;
|
||||
use App\Repository\WarehouseRepository;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
@@ -12,13 +14,16 @@ use Symfony\Component\Finder\Finder;
|
||||
class HiltesImport
|
||||
{
|
||||
private $stockRepository;
|
||||
private $warehouseRepository;
|
||||
private $logger;
|
||||
protected $currentDirPath;
|
||||
protected $arrData = array();
|
||||
|
||||
public function __construct(StockRepository $stockRepository, LoggerInterface $logger)
|
||||
public function __construct(StockRepository $stockRepository, WarehouseRepository $warehouseRepository, LoggerInterface $logger)
|
||||
{
|
||||
$this->stockRepository = $stockRepository;
|
||||
$this->warehouseRepository = $warehouseRepository;
|
||||
|
||||
$this->logger = $logger;
|
||||
|
||||
$this->currentDirPath = getcwd();
|
||||
@@ -87,6 +92,8 @@ class HiltesImport
|
||||
|
||||
dump($file->getRealPath());
|
||||
|
||||
$this->logger->info('Starte Import von ' . $file->getRealPath());
|
||||
|
||||
$c = 0;
|
||||
while (!$file->eof()) {
|
||||
$c++;
|
||||
@@ -176,30 +183,73 @@ class HiltesImport
|
||||
protected function saveInfoDatei(Array $arr){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $arr
|
||||
* @return void
|
||||
*/
|
||||
protected function saveData(Array $arr){
|
||||
#dump($arr);
|
||||
$stock = new Stock();
|
||||
|
||||
|
||||
#menge;
|
||||
$stock->setStock((int)$arr[2]);
|
||||
|
||||
#filiale;
|
||||
//$stock->setWarehouseId((int)$arr[0]);
|
||||
|
||||
$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]);
|
||||
|
||||
|
||||
//ump($stock);
|
||||
|
||||
try{
|
||||
$this->stockRepository->upsert($stock);
|
||||
}catch (\Exception $e){
|
||||
$this->logger->error($e->getMessage());
|
||||
dump($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
private function getWarehouseId($id){
|
||||
$warehouse = $this->warehouseRepository->findOneBy(array('id'=>$id));
|
||||
if($warehouse instanceof Warehouse){
|
||||
return $warehouse->getId();
|
||||
}else{
|
||||
$warehouse = new Warehouse();
|
||||
|
||||
|
||||
$warehouse->setPriority(0);
|
||||
$warehouse->setId($this->warehouseRepository->add($warehouse, true));
|
||||
|
||||
dump($warehouse);
|
||||
|
||||
|
||||
|
||||
return $warehouse;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Helper;
|
||||
|
||||
use App\Entity\Products;
|
||||
use App\Repository\ProductsRepository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Vin\ShopwareSdk\Client\AdminAuthenticator;
|
||||
use Vin\ShopwareSdk\Client\GrantType\ClientCredentialsGrantType;
|
||||
@@ -64,13 +66,23 @@ class Shopware
|
||||
}
|
||||
}
|
||||
|
||||
public function setProduct(){
|
||||
public function setProduct(Products $product){
|
||||
$context = new Context($_ENV['SHOPWARE_API_URL'], $this->shopwareAuth());
|
||||
|
||||
$productRepository = RepositoryFactory::create(ProductDefinition::ENTITY_NAME);
|
||||
$productRepository->update($product, $context);
|
||||
}
|
||||
|
||||
$productRepository->update();
|
||||
public function pushStock()
|
||||
{
|
||||
$productRepository = new ProductsRepository();
|
||||
$products = $productRepository->findAll();
|
||||
|
||||
|
||||
|
||||
|
||||
foreach ($products as $product) {
|
||||
$this->setProduct($product);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user