This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Command;
|
||||
|
||||
use App\Helper\HiltesImport;
|
||||
use App\Repository\StockRepository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
@@ -19,6 +21,14 @@ use Symfony\Component\Finder\Finder;
|
||||
)]
|
||||
class HiltesImportCommand extends Command
|
||||
{
|
||||
private $stockRepository;
|
||||
private $logger;
|
||||
public function __construct(StockRepository $stockRepository, LoggerInterface $logger)
|
||||
{
|
||||
$this->stockRepository = $stockRepository;
|
||||
$this->logger = $logger;
|
||||
parent::__construct();
|
||||
}
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
@@ -38,12 +48,12 @@ class HiltesImportCommand extends Command
|
||||
/**
|
||||
* @var HiltesImport
|
||||
*/
|
||||
$hiltesImport = new HiltesImport();
|
||||
$hiltesImport = new HiltesImport($this->stockRepository,$this->logger);
|
||||
|
||||
$hiltesImport->startImport();
|
||||
|
||||
|
||||
$io->success('You have a new command! Now make it your own! Pass --help to see your options.');
|
||||
$io->success('Done.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Command;
|
||||
|
||||
use App\Controller\ShopwareController;
|
||||
use App\Entity\Orders;
|
||||
use App\Helper\Shopware;
|
||||
use App\Repository\OrdersRepository;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@@ -33,6 +34,7 @@ class SwGetOrdersCommand extends Command
|
||||
{
|
||||
private $ordersRepository;
|
||||
private $logger;
|
||||
private $sw;
|
||||
private $orderData;
|
||||
|
||||
|
||||
@@ -40,6 +42,7 @@ class SwGetOrdersCommand extends Command
|
||||
{
|
||||
$this->ordersRepository = $ordersRepository;
|
||||
$this->logger = $logger;
|
||||
$this->sw = new Shopware();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -88,6 +91,7 @@ class SwGetOrdersCommand extends Command
|
||||
public function getOrderDetails(): void
|
||||
{
|
||||
//Bestelldetails aus SW holen
|
||||
|
||||
$this->getOrdersDataFromSW();
|
||||
|
||||
foreach ($this->orderData as $order) {
|
||||
@@ -95,47 +99,16 @@ class SwGetOrdersCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Vin\ShopwareSdk\Data\AccessToken|void
|
||||
*/
|
||||
private 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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* holt alle fehlende Bestelldetails aus SW
|
||||
*/
|
||||
private function getOrdersDataFromSW(): void
|
||||
{
|
||||
|
||||
foreach ($this->orderData as $value) {
|
||||
// Bei Shopware API anmelden
|
||||
$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', $value->getOrderId()));
|
||||
|
||||
//Beziehungen zu Produkten holen
|
||||
$criteria->addAssociation('lineItems');
|
||||
|
||||
try {
|
||||
$orders = $orderRepository->search($criteria, $context);
|
||||
|
||||
$value->setData((array)$orders->getEntities());
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
$value->setData((array)$this->sw->getOrders($value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
69
src/Command/SwPushStockCommand.php
Normal file
69
src/Command/SwPushStockCommand.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Repository\StockRepository;
|
||||
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;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'sw:push-stock',
|
||||
description: 'Übermittelt den Bestand an Shopware',
|
||||
)]
|
||||
class SwPushStockCommand extends Command
|
||||
{
|
||||
|
||||
private $stockRepository;
|
||||
private $logger;
|
||||
|
||||
public function __construct(StockRepository $stockRepository, LoggerInterface $logger)
|
||||
{
|
||||
$this->stockRepository = $stockRepository;
|
||||
$this->logger = $logger;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
// $arg1 = $input->getArgument('arg1');
|
||||
|
||||
// if ($arg1) {
|
||||
// $io->note(sprintf('You passed an argument: %s', $arg1));
|
||||
// }
|
||||
//
|
||||
// if ($input->getOption('option1')) {
|
||||
// // ...
|
||||
// }
|
||||
|
||||
$stock = $this->getStock();
|
||||
|
||||
if($stock){
|
||||
|
||||
}
|
||||
|
||||
dump($stock);
|
||||
|
||||
$io->success('Done.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
public function getStock(){
|
||||
return $this->stockRepository->findAll();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user