This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user