add FTP Upload

This commit is contained in:
Marko
2023-09-27 15:07:34 +02:00
parent a1a2eb84b3
commit a97fec167c
29 changed files with 175 additions and 25090 deletions

View File

@@ -1,124 +0,0 @@
<?php
namespace App\Command;
use App\Controller\ShopwareController;
use App\Entity\Order;
use App\Helper\Shopware;
use App\Repository\OrdersRepository;
use Doctrine\ORM\Mapping as ORM;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
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\EntityCollection;
use Vin\ShopwareSdk\Data\Entity\Order\OrderDefinition;
use Vin\ShopwareSdk\Data\Filter\EqualsAnyFilter;
use Vin\ShopwareSdk\Data\Filter\EqualsFilter;
use Vin\ShopwareSdk\Factory\RepositoryFactory;
#[AsCommand(
name: 'sw:get-orders',
description: 'Holt alle offenen Bestellungen von Shopware ab',
)]
class SwGetOrdersCommand extends Command
{
private $orderRepository;
private $logger;
private $sw;
private $orderData;
public function __construct(OrdersRepository $orderRepository, LoggerInterface $logger)
{
$this->orderRepository = $orderRepository;
$this->logger = $logger;
$this->sw = new Shopware($logger);
parent::__construct();
}
protected function configure(): void
{
// $this
// ->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
// ->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
// ;
}
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')) {
// // ...
// }
//offene Bestellungen aus Datenbank holen
$this->orderData = $this->getOrders();
$this->getOrderDetails();
$io->success('Done!');
return Command::SUCCESS;
}
/**
* @return array
*/
private function getOrders():array
{
return $this->orderRepository->findAll();
}
/**
* @return void
*/
public function getOrderDetails(): void
{
//Bestelldetails aus SW holen
$this->getOrdersDataFromSW();
foreach ($this->orderData as $order) {
$this->saveOrdersData($order);
}
}
/**
* holt alle fehlende Bestelldetails aus SW
*/
private function getOrdersDataFromSW(): void
{
foreach ($this->orderData as $value) {
// Bei Shopware API anmelden
$value->setData((array)$this->sw->getOrders($value));
}
}
/**
* @param $orderData
* @return void
*/
private function saveOrdersData($orderData): void
{
$orderData->setStatus = 1;
$this->ordersRepository->add($orderData, true);
}
}

View File

@@ -1,111 +0,0 @@
<?php
namespace App\Command;
use App\Helper\Shopware;
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\InputInterface;
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 $productRepository;
private $logger;
public function __construct(ProductRepository $productRepository, LoggerInterface $logger)
{
$this->productRepository = $productRepository;
$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')) {
// // ...
// }
$shopware = new Shopware($this->logger);
$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;
}
}