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

76
src/Helper/Shopware.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
namespace App\Helper;
use Psr\Log\LoggerInterface;
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\Order\OrderDefinition;
use Vin\ShopwareSdk\Data\Filter\EqualsFilter;
use Vin\ShopwareSdk\Factory\RepositoryFactory;
class Shopware
{
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
//parent::__construct();
}
/**
* Anmeldung bei der Shopwar API
* @return \Vin\ShopwareSdk\Data\AccessToken|void
*/
public 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());
}
}
/**
* @param string $orderId
* @return OrderDefinition
*/
public function getOrders(string $orderId):OrderDefinition{
$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', $orderId));
//Beziehungen zu Produkten holen
$criteria->addAssociation('lineItems');
try {
$orders = $orderRepository->search($criteria, $context);
return $orders->getEntities();
//$value->setData((array)$orders->getEntities());
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
}
}
public function setProduct(){
$context = new Context($_ENV['SHOPWARE_API_URL'], $this->shopwareAuth());
$productRepository = RepositoryFactory::create(ProductDefinition::ENTITY_NAME);
$productRepository->update();
}
}