import hiltes
This commit is contained in:
parent
3493e038e3
commit
7100cc5a89
@ -8,7 +8,7 @@
|
|||||||
<jdbc-url>jdbc:mysql://127.0.0.1:3306</jdbc-url>
|
<jdbc-url>jdbc:mysql://127.0.0.1:3306</jdbc-url>
|
||||||
<working-dir>$ProjectFileDir$</working-dir>
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
</data-source>
|
</data-source>
|
||||||
<data-source source="LOCAL" name="DDEV" uuid="86e47706-4e5a-4e03-b691-7edcb432774a">
|
<data-source source="LOCAL" name="DDEV" uuid="9b7b5206-4cfe-4e94-a0d7-6375cca27cab">
|
||||||
<driver-ref>mariadb</driver-ref>
|
<driver-ref>mariadb</driver-ref>
|
||||||
<synchronize>true</synchronize>
|
<synchronize>true</synchronize>
|
||||||
<configured-by-url>true</configured-by-url>
|
<configured-by-url>true</configured-by-url>
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="PublishConfigData" serverName="local">
|
|
||||||
<serverData>
|
|
||||||
<paths name="aluformat">
|
|
||||||
<serverdata>
|
|
||||||
<mappings>
|
|
||||||
<mapping local="$PROJECT_DIR$" web="/" />
|
|
||||||
</mappings>
|
|
||||||
</serverdata>
|
|
||||||
</paths>
|
|
||||||
<paths name="caravan">
|
|
||||||
<serverdata>
|
|
||||||
<mappings>
|
|
||||||
<mapping local="$PROJECT_DIR$" web="/" />
|
|
||||||
</mappings>
|
|
||||||
</serverdata>
|
|
||||||
</paths>
|
|
||||||
<paths name="corona">
|
|
||||||
<serverdata>
|
|
||||||
<mappings>
|
|
||||||
<mapping local="$PROJECT_DIR$" web="/" />
|
|
||||||
</mappings>
|
|
||||||
</serverdata>
|
|
||||||
</paths>
|
|
||||||
<paths name="geschenke">
|
|
||||||
<serverdata>
|
|
||||||
<mappings>
|
|
||||||
<mapping local="$PROJECT_DIR$" web="/" />
|
|
||||||
</mappings>
|
|
||||||
</serverdata>
|
|
||||||
</paths>
|
|
||||||
<paths name="local">
|
|
||||||
<serverdata>
|
|
||||||
<mappings>
|
|
||||||
<mapping local="$PROJECT_DIR$" web="/" />
|
|
||||||
</mappings>
|
|
||||||
</serverdata>
|
|
||||||
</paths>
|
|
||||||
</serverData>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
584
composer.lock
generated
584
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,7 @@ namespace App\Command;
|
|||||||
|
|
||||||
use App\Helper\HiltesImport;
|
use App\Helper\HiltesImport;
|
||||||
use App\Repository\StockRepository;
|
use App\Repository\StockRepository;
|
||||||
|
use App\Repository\WarehouseRepository;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
@ -22,10 +23,12 @@ use Symfony\Component\Finder\Finder;
|
|||||||
class HiltesImportCommand extends Command
|
class HiltesImportCommand extends Command
|
||||||
{
|
{
|
||||||
private $stockRepository;
|
private $stockRepository;
|
||||||
|
private $warehouseRepository;
|
||||||
private $logger;
|
private $logger;
|
||||||
public function __construct(StockRepository $stockRepository, LoggerInterface $logger)
|
public function __construct(StockRepository $stockRepository, WarehouseRepository $warehouseRepository, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
$this->stockRepository = $stockRepository;
|
$this->stockRepository = $stockRepository;
|
||||||
|
$this->warehouseRepository = $warehouseRepository;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
@ -45,14 +48,16 @@ class HiltesImportCommand extends Command
|
|||||||
if ($arg1) {
|
if ($arg1) {
|
||||||
$io->note(sprintf('You passed an argument: %s', $arg1));
|
$io->note(sprintf('You passed an argument: %s', $arg1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var HiltesImport
|
* @var HiltesImport
|
||||||
*/
|
*/
|
||||||
$hiltesImport = new HiltesImport($this->stockRepository,$this->logger);
|
$hiltesImport = new HiltesImport($this->stockRepository,$this->warehouseRepository,$this->logger);
|
||||||
|
|
||||||
$hiltesImport->startImport();
|
$hiltesImport->startImport();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$io->success('Done.');
|
$io->success('Done.');
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Command;
|
namespace App\Command;
|
||||||
|
|
||||||
|
use App\Helper\Shopware;
|
||||||
use App\Repository\StockRepository;
|
use App\Repository\StockRepository;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
@ -47,13 +48,9 @@ class SwPushStockCommand extends Command
|
|||||||
// // ...
|
// // ...
|
||||||
// }
|
// }
|
||||||
|
|
||||||
$stock = $this->getStock();
|
$shopware = new Shopware();
|
||||||
|
|
||||||
if($stock){
|
$shopware->pushStock();
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
dump($stock);
|
|
||||||
|
|
||||||
$io->success('Done.');
|
$io->success('Done.');
|
||||||
|
|
||||||
@ -61,9 +58,5 @@ class SwPushStockCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getStock(){
|
|
||||||
return $this->stockRepository->findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -69,12 +69,12 @@ class Stock
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWarehouseId(): ?Warehouse
|
public function getWarehouseId(): ?int
|
||||||
{
|
{
|
||||||
return $this->warehouse_id;
|
return $this->warehouse_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setWarehouseId(?Warehouse $warehouse_id): self
|
public function setWarehouseId(int $warehouse_id): self
|
||||||
{
|
{
|
||||||
$this->warehouse_id = $warehouse_id;
|
$this->warehouse_id = $warehouse_id;
|
||||||
|
|
||||||
@ -92,4 +92,10 @@ class Stock
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setWarehouse(Warehouse $warehouse): self
|
||||||
|
{
|
||||||
|
$this->warehouse_id = $warehouse->getId();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,20 @@ class Warehouse
|
|||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setID(int $id): self
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWarehouseId(int $warehouse_id): self
|
||||||
|
{
|
||||||
|
$this->warehouse_id = $warehouse_id;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection<int, Stock>
|
* @return Collection<int, Stock>
|
||||||
*/
|
*/
|
||||||
|
@ -4,7 +4,9 @@ namespace App\Helper;
|
|||||||
|
|
||||||
|
|
||||||
use App\Entity\Stock;
|
use App\Entity\Stock;
|
||||||
|
use App\Entity\Warehouse;
|
||||||
use App\Repository\StockRepository;
|
use App\Repository\StockRepository;
|
||||||
|
use App\Repository\WarehouseRepository;
|
||||||
use Doctrine\ORM\EntityManager;
|
use Doctrine\ORM\EntityManager;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
@ -12,13 +14,16 @@ use Symfony\Component\Finder\Finder;
|
|||||||
class HiltesImport
|
class HiltesImport
|
||||||
{
|
{
|
||||||
private $stockRepository;
|
private $stockRepository;
|
||||||
|
private $warehouseRepository;
|
||||||
private $logger;
|
private $logger;
|
||||||
protected $currentDirPath;
|
protected $currentDirPath;
|
||||||
protected $arrData = array();
|
protected $arrData = array();
|
||||||
|
|
||||||
public function __construct(StockRepository $stockRepository, LoggerInterface $logger)
|
public function __construct(StockRepository $stockRepository, WarehouseRepository $warehouseRepository, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
$this->stockRepository = $stockRepository;
|
$this->stockRepository = $stockRepository;
|
||||||
|
$this->warehouseRepository = $warehouseRepository;
|
||||||
|
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
|
||||||
$this->currentDirPath = getcwd();
|
$this->currentDirPath = getcwd();
|
||||||
@ -87,6 +92,8 @@ class HiltesImport
|
|||||||
|
|
||||||
dump($file->getRealPath());
|
dump($file->getRealPath());
|
||||||
|
|
||||||
|
$this->logger->info('Starte Import von ' . $file->getRealPath());
|
||||||
|
|
||||||
$c = 0;
|
$c = 0;
|
||||||
while (!$file->eof()) {
|
while (!$file->eof()) {
|
||||||
$c++;
|
$c++;
|
||||||
@ -176,29 +183,72 @@ class HiltesImport
|
|||||||
protected function saveInfoDatei(Array $arr){
|
protected function saveInfoDatei(Array $arr){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $arr
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
protected function saveData(Array $arr){
|
protected function saveData(Array $arr){
|
||||||
#dump($arr);
|
#dump($arr);
|
||||||
$stock = new Stock();
|
$stock = new Stock();
|
||||||
|
|
||||||
|
|
||||||
#menge;
|
#menge;
|
||||||
$stock->setStock((int)$arr[2]);
|
$stock->setStock((int)$arr[2]);
|
||||||
|
|
||||||
#filiale;
|
#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;
|
#gtin;
|
||||||
$stock->setGtin($arr[1]);
|
$stock->setGtin($arr[1]);
|
||||||
|
|
||||||
|
|
||||||
//ump($stock);
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$this->stockRepository->upsert($stock);
|
$this->stockRepository->upsert($stock);
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
|
$this->logger->error($e->getMessage());
|
||||||
dump($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;
|
namespace App\Helper;
|
||||||
|
|
||||||
|
use App\Entity\Products;
|
||||||
|
use App\Repository\ProductsRepository;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Vin\ShopwareSdk\Client\AdminAuthenticator;
|
use Vin\ShopwareSdk\Client\AdminAuthenticator;
|
||||||
use Vin\ShopwareSdk\Client\GrantType\ClientCredentialsGrantType;
|
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());
|
$context = new Context($_ENV['SHOPWARE_API_URL'], $this->shopwareAuth());
|
||||||
|
|
||||||
$productRepository = RepositoryFactory::create(ProductDefinition::ENTITY_NAME);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
use App\Entity\Stock;
|
use App\Entity\Stock;
|
||||||
|
use App\Entity\Warehouse;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ class StockRepository extends ServiceEntityRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
$stock->setStock($entity->getStock());
|
$stock->setStock($entity->getStock());
|
||||||
|
$stock->setUpdateTime(new \DateTime('now'));
|
||||||
|
|
||||||
$this->getEntityManager()->flush();
|
$this->getEntityManager()->flush();
|
||||||
}
|
}
|
||||||
@ -55,16 +57,28 @@ class StockRepository extends ServiceEntityRepository
|
|||||||
* @param Stock $entity
|
* @param Stock $entity
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function upsert(Stock $entity): void
|
public function upsert(Stock $stock): void
|
||||||
{
|
{
|
||||||
$stock = $this->findByGtin($entity->getGtin());
|
//$stock = $this->findByGtin($entity->getGtin());
|
||||||
|
|
||||||
if ($stock) {
|
// $warehouse = $this->getEntityManager()->find(Warehouse::class, $stock->getWarehouseId());
|
||||||
|
// $stock->setWarehouse($warehouse);
|
||||||
|
//
|
||||||
|
// $this->getEntityManager()->persist($stock);
|
||||||
|
//
|
||||||
|
// $this->getEntityManager()->flush();
|
||||||
|
|
||||||
|
$s = $this->findOneBy([
|
||||||
|
'gtin' => $stock->getGtin(),
|
||||||
|
//'warehouse_id' => $stock->getWarehouseId()
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($s) {
|
||||||
// $stock->setStock($entity->getStock());
|
// $stock->setStock($entity->getStock());
|
||||||
// $this->getEntityManager()->flush();
|
// $this->getEntityManager()->flush();
|
||||||
$this->update($entity,$stock[0]->getId());
|
$this->update($stock,$s->getId());
|
||||||
}else{
|
}else{
|
||||||
$this->add($entity,true);
|
$this->add($stock,true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,13 +21,15 @@ class WarehouseRepository extends ServiceEntityRepository
|
|||||||
parent::__construct($registry, Warehouse::class);
|
parent::__construct($registry, Warehouse::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add(Warehouse $entity, bool $flush = false): void
|
public function add(Warehouse $entity, bool $flush = false): ?int
|
||||||
{
|
{
|
||||||
$this->getEntityManager()->persist($entity);
|
$this->getEntityManager()->persist($entity);
|
||||||
|
|
||||||
if ($flush) {
|
if ($flush) {
|
||||||
$this->getEntityManager()->flush();
|
$this->getEntityManager()->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $entity->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remove(Warehouse $entity, bool $flush = false): void
|
public function remove(Warehouse $entity, bool $flush = false): void
|
||||||
|
Loading…
Reference in New Issue
Block a user