import hiltes
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
mmoeller
2023-01-30 15:36:20 +01:00
parent d420c00036
commit 3493e038e3
31 changed files with 27498 additions and 20940 deletions

View File

@@ -3,15 +3,24 @@
namespace App\Helper;
use App\Entity\Stock;
use App\Repository\StockRepository;
use Doctrine\ORM\EntityManager;
use Psr\Log\LoggerInterface;
use Symfony\Component\Finder\Finder;
class HiltesImport
{
private $stockRepository;
private $logger;
protected $currentDirPath;
protected $arrData = array();
public function __construct()
public function __construct(StockRepository $stockRepository, LoggerInterface $logger)
{
$this->stockRepository = $stockRepository;
$this->logger = $logger;
$this->currentDirPath = getcwd();
}
@@ -76,25 +85,23 @@ class HiltesImport
$file = new \SplFileObject($srcFile);
# dump(memory_get_usage()-$t);
dump($file->getRealPath());
$c = 0;
while (!$file->eof()) {
$c++;
// Header überspringen
if($c == 1){ continue; }
#*** Convertiert die Zeile in UTF8
$str = iconv('ISO-8859-1','UTF-8',$file->fgets());
//$str = iconv('ISO-8859-1','UTF-8',$file->fgets());
#*** Zerlegt die Zeile **********
$arr = $this->splitLine($str);
$arr = $this->splitLine($file->fgets());
$this->switchSaveData($arr);
#
#dump('-----------------------');
#dump($str);
#dump($arr);
$c++;
# if($c>=50){
# dump(memory_get_usage()-$t);
# die();
# }
}
# dump(memory_get_usage()-$t);
# die();
dump($c . ' Datensätze importiert');
}
protected function splitLine($str){
return str_getcsv($str,';','"');
@@ -111,51 +118,54 @@ class HiltesImport
#*** Leerzeichen löschen bei den einzelnen Einträgen **********
$this->trimArray($arr);
#***
$arr[0] = strtolower($arr[0]);
switch ($arr[0]){
case 'datei': # Datei
$this->saveInfoDatei($arr);
break;
case 'filiale': # Filiale
#$this->saveInfoFiliale($arr);
break;
case 'land': # Länder
$this->saveInfoLand($arr);
break;
case 'hwg': # Hauptwarengruppe
#$this->saveInfoHauptWarenGruppe($arr);
break;
case 'wg': # Warengruppe
#$this->saveInfoWarenGruppe($arr);
break;
case 'anrede': # Anrede
#$this->saveInfoAnrede($arr);
break;
case 'lieferant': # Lieferant
#$this->saveInfoLieferant($arr);
break;
case 'farb': # Farbcodierung
#$this->saveInfoFarbCodierung($arr);
break;
case 'nlart': # NachlassArt
#$this->saveInfoNachlassArt($arr);
break;
case 'kollektion': # Kollektion
#$this->saveInfoKollektion($arr);
break;
case 'bestand': # Bestand
#$this->saveInfoBestand($arr);
break;
case 'merkmale': # Made In XXXX = Land
#$this->saveInfoMerkmale($arr);
break;
case 'material': # MAterial
#$this->saveInfoMaterial($arr);
break;
default: #
dump('!!!!! KEIN DEFINIERTER ANFANG "'.$arr[0].'" !!!!!!!!!');
break;
}
// $arr[0] = strtolower($arr[0]);
// switch ($arr[0]){
// case 'datei': # Datei
// $this->saveInfoDatei($arr);
// break;
// case 'filiale': # Filiale
// #$this->saveInfoFiliale($arr);
// break;
// case 'land': # Länder
// $this->saveInfoLand($arr);
// break;
// case 'hwg': # Hauptwarengruppe
// #$this->saveInfoHauptWarenGruppe($arr);
// break;
// case 'wg': # Warengruppe
// #$this->saveInfoWarenGruppe($arr);
// break;
// case 'anrede': # Anrede
// #$this->saveInfoAnrede($arr);
// break;
// case 'lieferant': # Lieferant
// #$this->saveInfoLieferant($arr);
// break;
// case 'farb': # Farbcodierung
// #$this->saveInfoFarbCodierung($arr);
// break;
// case 'nlart': # NachlassArt
// #$this->saveInfoNachlassArt($arr);
// break;
// case 'kollektion': # Kollektion
// #$this->saveInfoKollektion($arr);
// break;
// case 'bestand': # Bestand
// #$this->saveInfoBestand($arr);
// break;
// case 'merkmale': # Made In XXXX = Land
// #$this->saveInfoMerkmale($arr);
// break;
// case 'material': # MAterial
// #$this->saveInfoMaterial($arr);
// break;
// default: #
// dump('!!!!! KEIN DEFINIERTER ANFANG "'.$arr[0].'" !!!!!!!!!');
// break;
// }
$this->saveData($arr);
}
}
protected function trimArray(Array &$arr){
@@ -166,10 +176,29 @@ class HiltesImport
protected function saveInfoDatei(Array $arr){
}
protected function saveInfoLand(Array $arr){
protected function saveData(Array $arr){
#dump($arr);
$stock = new Stock();
#menge;
$stock->setStock((int)$arr[2]);
#filiale;
//$stock->setWarehouseId((int)$arr[0]);
#gtin;
$stock->setGtin($arr[1]);
//ump($stock);
try{
$this->stockRepository->upsert($stock);
}catch (\Exception $e){
dump($e->getMessage());
}
dd($arr);
}
}

76
src/Helper/Shopware.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
namespace App\Helper;
use Psr\Log\LoggerInterface;
use Vin\ShopwareSdk\Client\AdminAuthenticator;
use Vin\ShopwareSdk\Client\GrantType\ClientCredentialsGrantType;
use Vin\ShopwareSdk\Data\Context;
use Vin\ShopwareSdk\Data\Criteria;
use Vin\ShopwareSdk\Data\Entity\Order\OrderDefinition;
use Vin\ShopwareSdk\Data\Filter\EqualsFilter;
use Vin\ShopwareSdk\Factory\RepositoryFactory;
class Shopware
{
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
//parent::__construct();
}
/**
* Anmeldung bei der Shopwar API
* @return \Vin\ShopwareSdk\Data\AccessToken|void
*/
public function shopwareAuth()
{
try {
$grantType = new ClientCredentialsGrantType($_ENV['SHOPWARE_API_ID'], $_ENV['SHOPWARE_API_KEY']);
$adminClient = new AdminAuthenticator($grantType, $_ENV['SHOPWARE_API_URL']);
return $adminClient->fetchAccessToken();
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
}
}
/**
* @param string $orderId
* @return OrderDefinition
*/
public function getOrders(string $orderId):OrderDefinition{
$context = new Context($_ENV['SHOPWARE_API_URL'], $this->shopwareAuth());
// Create the repository for the entity
$orderRepository = RepositoryFactory::create(OrderDefinition::ENTITY_NAME);
// Create the criteria
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('id', $orderId));
//Beziehungen zu Produkten holen
$criteria->addAssociation('lineItems');
try {
$orders = $orderRepository->search($criteria, $context);
return $orders->getEntities();
//$value->setData((array)$orders->getEntities());
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
}
}
public function setProduct(){
$context = new Context($_ENV['SHOPWARE_API_URL'], $this->shopwareAuth());
$productRepository = RepositoryFactory::create(ProductDefinition::ENTITY_NAME);
$productRepository->update();
}
}