This commit is contained in:
@@ -58,13 +58,21 @@ class HiltesImportCommand extends Command
|
||||
* @var HiltesImport
|
||||
*/
|
||||
$hiltesImport = new HiltesImport($this->productRepository,$this->logger);
|
||||
$hiltesImport->startImport();
|
||||
|
||||
|
||||
$r = $hiltesImport->startImport();
|
||||
|
||||
if($r['error']){
|
||||
$io->error($r['text']);
|
||||
$this->logger->error($r['text']);
|
||||
return Command::FAILURE;
|
||||
}else{
|
||||
|
||||
$io->success('Done.');
|
||||
$pushStock = new SwPushStockCommand($this->stockRepository,$this->warehouseRepository,$this->logger);
|
||||
$pushStock->execute($input,$output);
|
||||
|
||||
return Command::SUCCESS;
|
||||
$io->success('Done.');
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,11 @@
|
||||
namespace App\Command;
|
||||
|
||||
use App\Helper\Shopware;
|
||||
use App\Repository\StockRepository;
|
||||
use App\Repository\ProductRepository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
@@ -20,15 +18,15 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
class SwPushStockCommand extends Command
|
||||
{
|
||||
|
||||
private $stockRepository;
|
||||
private $productRepository;
|
||||
private $logger;
|
||||
|
||||
// public function __construct(StockRepository $stockRepository, LoggerInterface $logger)
|
||||
// {
|
||||
// $this->stockRepository = $stockRepository;
|
||||
// $this->logger = $logger;
|
||||
// parent::__construct();
|
||||
// }
|
||||
public function __construct(ProductRepository $productRepository, LoggerInterface $logger)
|
||||
{
|
||||
$this->productRepository = $productRepository;
|
||||
$this->logger = $logger;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
protected function configure(): void
|
||||
@@ -48,15 +46,66 @@ class SwPushStockCommand extends Command
|
||||
// // ...
|
||||
// }
|
||||
|
||||
$shopware = new Shopware();
|
||||
$shopware = new Shopware($this->logger);
|
||||
|
||||
$shopware->pushStock();
|
||||
|
||||
$products = $this->getProducts();
|
||||
|
||||
if (count($products) > 0) {
|
||||
|
||||
foreach ($products as $product) {
|
||||
|
||||
//prüfen ob Shopware ID vorhanden
|
||||
if($product->getShopwareId() == null) {
|
||||
|
||||
$swID = $this->getShopwareId($product);
|
||||
|
||||
if($swID != null) {
|
||||
$product->setShopwareId($swID->id);
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$shopware->setProduct($product);
|
||||
}
|
||||
}
|
||||
|
||||
$io->success('Done.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
protected function getProducts()
|
||||
{
|
||||
$products = $this->productRepository->findAll();
|
||||
$arrProducts = array();
|
||||
foreach ($products as $product) {
|
||||
$arrProducts[$product->getGtin()] = $product;
|
||||
}
|
||||
|
||||
return $arrProducts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @return int|null
|
||||
*/
|
||||
protected function getShopwareId($product)
|
||||
{
|
||||
$shopware = new Shopware($this->logger);
|
||||
$shopwareProduct = $shopware->getShopwareIdbyGtin($product->getGtin());
|
||||
if($shopwareProduct != null) {
|
||||
dump($shopwareProduct);
|
||||
$product->setShopwareId($shopwareProduct->id);
|
||||
$this->productRepository->save($product, true);
|
||||
}
|
||||
|
||||
return $shopwareProduct;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user