This commit is contained in:
76
src/Helper/Shopware.php
Normal file
76
src/Helper/Shopware.php
Normal 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();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user