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

@@ -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));
}
}