add Basic Shopware API
This commit is contained in:
parent
f2107b024e
commit
b5085fc848
6
.env
6
.env
@ -31,7 +31,7 @@ DATABASE_URL="mysql://root:root@mysql:3306/cds_connector?serverVersion=5.7&chars
|
|||||||
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
|
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
|
||||||
###< nelmio/cors-bundle ###
|
###< nelmio/cors-bundle ###
|
||||||
|
|
||||||
SHOPWARE_API_URL="http://development.dev.localhost"
|
SHOPWARE_API_URL="development.dev.localhost"
|
||||||
SHOPWARE_API_KEY="dkVsVndWV2M4dVJLZEhMbkdMNWlLSXJsTXVjMW5jdVNrNzlBOFE"
|
SHOPWARE_API_KEY="S2hySDNyZ214dGRVQmFBSURQbkRvajIyZldxOHB4RktZakxaYmo"
|
||||||
SHOPWARE_API_ID="SWIAVTJ1ZDLLY2TJT1D0ZEDBAQ"
|
SHOPWARE_API_ID="SWUAB1JGAFHTMME5DUGWDWN1EQ"
|
||||||
|
|
||||||
|
@ -93,6 +93,14 @@
|
|||||||
<path value="$PROJECT_DIR$/vendor/sensio/framework-extra-bundle" />
|
<path value="$PROJECT_DIR$/vendor/sensio/framework-extra-bundle" />
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/http-client" />
|
<path value="$PROJECT_DIR$/vendor/symfony/http-client" />
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/http-client-contracts" />
|
<path value="$PROJECT_DIR$/vendor/symfony/http-client-contracts" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/ralouphie/getallheaders" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/psr/http-factory" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/psr/http-client" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/psr/http-message" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/guzzlehttp/promises" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/guzzlehttp/guzzle" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/guzzlehttp/psr7" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/vin-sw/shopware-sdk" />
|
||||||
</include_path>
|
</include_path>
|
||||||
</component>
|
</component>
|
||||||
<component name="PhpProjectSharedConfiguration" php_language_level="8.1" />
|
<component name="PhpProjectSharedConfiguration" php_language_level="8.1" />
|
||||||
|
@ -32,7 +32,8 @@
|
|||||||
"symfony/serializer": "6.1.*",
|
"symfony/serializer": "6.1.*",
|
||||||
"symfony/twig-bundle": "6.1.*",
|
"symfony/twig-bundle": "6.1.*",
|
||||||
"symfony/validator": "6.1.*",
|
"symfony/validator": "6.1.*",
|
||||||
"symfony/yaml": "6.1.*"
|
"symfony/yaml": "6.1.*",
|
||||||
|
"vin-sw/shopware-sdk": "^1.4"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/debug-bundle": "6.1.*",
|
"symfony/debug-bundle": "6.1.*",
|
||||||
|
822
composer.lock
generated
822
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -19,6 +19,14 @@ use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
|||||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
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\Entity\Product\ProductDefinition;
|
||||||
|
use Vin\ShopwareSdk\Data\Filter\EqualsFilter;
|
||||||
|
use Vin\ShopwareSdk\Factory\RepositoryFactory;
|
||||||
|
|
||||||
|
|
||||||
#[AsCommand(
|
#[AsCommand(
|
||||||
@ -84,18 +92,15 @@ class SwGetOrdersCommand extends Command
|
|||||||
|
|
||||||
private function shopwareAuth(){
|
private function shopwareAuth(){
|
||||||
|
|
||||||
$this->client->withOptions([
|
try{
|
||||||
'headers' => [
|
$grantType = new ClientCredentialsGrantType($_ENV['SHOPWARE_API_ID'], $_ENV['SHOPWARE_API_KEY']);
|
||||||
'Content-Type' => 'application/json',
|
$adminClient = new AdminAuthenticator($grantType, $_ENV['SHOPWARE_API_URL']);
|
||||||
'sw-access-key' => 'SWSCY1NPSKHPSFNHWGDLTMM5NQ'
|
return $adminClient->fetchAccessToken();
|
||||||
],
|
}catch (\Exception $e){
|
||||||
]);
|
$this->logger->error($e->getMessage());
|
||||||
$response = $this->client->request('GET','http://localhost/store-api/context');
|
}
|
||||||
|
|
||||||
|
|
||||||
$body = $response->getContent();
|
|
||||||
|
|
||||||
var_dump($body);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,39 +111,29 @@ class SwGetOrdersCommand extends Command
|
|||||||
* @throws ClientExceptionInterface
|
* @throws ClientExceptionInterface
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private function getOrdersFromSW(array $orders):void
|
private function getOrdersFromSW(array $ordersArr):void
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$context = new Context($_ENV['SHOPWARE_API_URL'], $this->shopwareAuth());
|
||||||
|
|
||||||
try {
|
// Create the repository for the entity
|
||||||
$response = $this->client->request('POST', $_ENV['SHOPWARE_API_URL'].'/store-api/search', [
|
$orderRepository = RepositoryFactory::create(OrderDefinition::ENTITY_NAME);
|
||||||
'headers' => [
|
|
||||||
'Accept' => 'application/json',
|
|
||||||
'Content-Type' => 'application/json',
|
|
||||||
'sw-access-key' => $_ENV['SHOPWARE_API_KEY']
|
|
||||||
],
|
|
||||||
'body' => json_encode([
|
|
||||||
'limit' => 100,
|
|
||||||
'page' => 1,
|
|
||||||
'query' => [
|
|
||||||
'filter' => [
|
|
||||||
'type' => 'equals',
|
|
||||||
'field' => 'order.number',
|
|
||||||
'value' => '12345'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
])
|
|
||||||
]);
|
|
||||||
$body = $response->toArray();
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
// Create the criteria
|
||||||
$this->logger->error($e->getMessage());
|
$criteria = new Criteria();
|
||||||
throw new \Exception($e->getMessage());
|
$criteria->addFilter(new EqualsFilter('orderNumber', '9f002cc7de704a6ab31e1b410547cb97'));
|
||||||
}
|
|
||||||
|
$criteria->addAssociation('order.orderDetails.product');
|
||||||
|
|
||||||
|
// Using this criteria and the context object that you create from authentication step, you can retrieving the result
|
||||||
|
$orders = $orderRepository->search($criteria, $context);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var_dump($orders);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var_dump($body);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user