diff --git a/.env b/.env index 95595c9..77cfaae 100644 --- a/.env +++ b/.env @@ -23,10 +23,15 @@ APP_SECRET=e5a2fe31ff8ce325266d52632a0ba5df # IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml # # DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" -DATABASE_URL="mysql://root:root@127.0.0.1:3306/cds_connector?serverVersion=5.7&charset=utf8mb4" +DATABASE_URL="mysql://root:root@mysql:3306/cds_connector?serverVersion=5.7&charset=utf8mb4" #DATABASE_URL="postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8" ###< doctrine/doctrine-bundle ### ###> nelmio/cors-bundle ### CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$' ###< nelmio/cors-bundle ### + +SHOPWARE_API_URL="http://development.dev.localhost" +SHOPWARE_API_KEY="dkVsVndWV2M4dVJLZEhMbkdMNWlLSXJsTXVjMW5jdVNrNzlBOFE" +SHOPWARE_API_ID="SWIAVTJ1ZDLLY2TJT1D0ZEDBAQ" + diff --git a/.idea/php.xml b/.idea/php.xml index a16e981..6e98374 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -87,6 +87,12 @@ + + + + + + diff --git a/composer.json b/composer.json index 8c25e16..0384313 100644 --- a/composer.json +++ b/composer.json @@ -15,12 +15,15 @@ "nelmio/cors-bundle": "^2.2", "phpdocumentor/reflection-docblock": "^5.3", "phpstan/phpdoc-parser": "^1.6", + "sensio/framework-extra-bundle": "^6.2", "symfony/asset": "6.1.*", "symfony/console": "6.1.*", "symfony/dotenv": "6.1.*", "symfony/expression-language": "6.1.*", "symfony/flex": "^2", + "symfony/form": "6.1.*", "symfony/framework-bundle": "6.1.*", + "symfony/http-client": "6.1.*", "symfony/property-access": "6.1.*", "symfony/property-info": "6.1.*", "symfony/proxy-manager-bridge": "6.1.*", diff --git a/composer.lock b/composer.lock index 25a5320..9e7b15c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cafee5535c7c76eacf8537d04d85db76", + "content-hash": "c4650435b5c2bd25df4752ab2fd36270", "packages": [ { "name": "api-platform/core", @@ -2269,6 +2269,84 @@ }, "time": "2021-07-14T16:46:02+00:00" }, + { + "name": "sensio/framework-extra-bundle", + "version": "v6.2.6", + "source": { + "type": "git", + "url": "https://github.com/sensiolabs/SensioFrameworkExtraBundle.git", + "reference": "6bd976c99ef3f78e31c9490a10ba6dd8901076eb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sensiolabs/SensioFrameworkExtraBundle/zipball/6bd976c99ef3f78e31c9490a10ba6dd8901076eb", + "reference": "6bd976c99ef3f78e31c9490a10ba6dd8901076eb", + "shasum": "" + }, + "require": { + "doctrine/annotations": "^1.0", + "php": ">=7.2.5", + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0", + "symfony/framework-bundle": "^4.4|^5.0|^6.0", + "symfony/http-kernel": "^4.4|^5.0|^6.0" + }, + "conflict": { + "doctrine/doctrine-cache-bundle": "<1.3.1", + "doctrine/persistence": "<1.3" + }, + "require-dev": { + "doctrine/dbal": "^2.10|^3.0", + "doctrine/doctrine-bundle": "^1.11|^2.0", + "doctrine/orm": "^2.5", + "symfony/browser-kit": "^4.4|^5.0|^6.0", + "symfony/doctrine-bridge": "^4.4|^5.0|^6.0", + "symfony/dom-crawler": "^4.4|^5.0|^6.0", + "symfony/expression-language": "^4.4|^5.0|^6.0", + "symfony/finder": "^4.4|^5.0|^6.0", + "symfony/monolog-bridge": "^4.0|^5.0|^6.0", + "symfony/monolog-bundle": "^3.2", + "symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0", + "symfony/security-bundle": "^4.4|^5.0|^6.0", + "symfony/twig-bundle": "^4.4|^5.0|^6.0", + "symfony/yaml": "^4.4|^5.0|^6.0", + "twig/twig": "^1.34|^2.4|^3.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "6.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Sensio\\Bundle\\FrameworkExtraBundle\\": "src/" + }, + "exclude-from-classmap": [ + "/tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "This bundle provides a way to configure your controllers with annotations", + "keywords": [ + "annotations", + "controllers" + ], + "support": { + "issues": "https://github.com/sensiolabs/SensioFrameworkExtraBundle/issues", + "source": "https://github.com/sensiolabs/SensioFrameworkExtraBundle/tree/v6.2.6" + }, + "time": "2022-01-14T11:51:13+00:00" + }, { "name": "symfony/asset", "version": "v6.1.0", @@ -3519,6 +3597,108 @@ ], "time": "2022-06-15T06:51:57+00:00" }, + { + "name": "symfony/form", + "version": "v6.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/form.git", + "reference": "630eed7b1282f18a8399a0a2b3fb71c44266b73a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/form/zipball/630eed7b1282f18a8399a0a2b3fb71c44266b73a", + "reference": "630eed7b1282f18a8399a0a2b3fb71c44266b73a", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/event-dispatcher": "^5.4|^6.0", + "symfony/options-resolver": "^5.4|^6.0", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-intl-icu": "^1.21", + "symfony/polyfill-mbstring": "~1.0", + "symfony/property-access": "^5.4|^6.0", + "symfony/service-contracts": "^1.1|^2|^3" + }, + "conflict": { + "phpunit/phpunit": "<5.4.3", + "symfony/console": "<5.4", + "symfony/dependency-injection": "<5.4", + "symfony/doctrine-bridge": "<5.4", + "symfony/error-handler": "<5.4", + "symfony/framework-bundle": "<5.4", + "symfony/http-kernel": "<5.4", + "symfony/translation": "<5.4", + "symfony/translation-contracts": "<1.1.7", + "symfony/twig-bridge": "<5.4" + }, + "require-dev": { + "doctrine/collections": "~1.0", + "symfony/config": "^5.4|^6.0", + "symfony/console": "^5.4|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/expression-language": "^5.4|^6.0", + "symfony/html-sanitizer": "^6.1", + "symfony/http-foundation": "^5.4|^6.0", + "symfony/http-kernel": "^5.4|^6.0", + "symfony/intl": "^5.4|^6.0", + "symfony/security-csrf": "^5.4|^6.0", + "symfony/translation": "^5.4|^6.0", + "symfony/uid": "^5.4|^6.0", + "symfony/validator": "^5.4|^6.0", + "symfony/var-dumper": "^5.4|^6.0" + }, + "suggest": { + "symfony/security-csrf": "For protecting forms against CSRF attacks.", + "symfony/twig-bridge": "For templating with Twig.", + "symfony/validator": "For form validation." + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Form\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Allows to easily create, process and reuse HTML forms", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/form/tree/v6.1.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-06-09T12:51:38+00:00" + }, { "name": "symfony/framework-bundle", "version": "v6.1.1", @@ -3670,6 +3850,171 @@ ], "time": "2022-06-09T10:53:06+00:00" }, + { + "name": "symfony/http-client", + "version": "v6.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client.git", + "reference": "c5473d69640980367a6bdb0cdb449225dcaa991b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client/zipball/c5473d69640980367a6bdb0cdb449225dcaa991b", + "reference": "c5473d69640980367a6bdb0cdb449225dcaa991b", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "psr/log": "^1|^2|^3", + "symfony/http-client-contracts": "^3", + "symfony/service-contracts": "^1.0|^2|^3" + }, + "provide": { + "php-http/async-client-implementation": "*", + "php-http/client-implementation": "*", + "psr/http-client-implementation": "1.0", + "symfony/http-client-implementation": "3.0" + }, + "require-dev": { + "amphp/amp": "^2.5", + "amphp/http-client": "^4.2.1", + "amphp/http-tunnel": "^1.0", + "amphp/socket": "^1.1", + "guzzlehttp/promises": "^1.4", + "nyholm/psr7": "^1.0", + "php-http/httplug": "^1.0|^2.0", + "psr/http-client": "^1.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/http-kernel": "^5.4|^6.0", + "symfony/process": "^5.4|^6.0", + "symfony/stopwatch": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpClient\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/http-client/tree/v6.1.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-06-09T13:06:55+00:00" + }, + { + "name": "symfony/http-client-contracts", + "version": "v3.1.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client-contracts.git", + "reference": "fd038f08c623ab5d22b26e9ba35afe8c79071800" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/fd038f08c623ab5d22b26e9ba35afe8c79071800", + "reference": "fd038f08c623ab5d22b26e9ba35afe8c79071800", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "suggest": { + "symfony/http-client-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.1-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\HttpClient\\": "" + }, + "exclude-from-classmap": [ + "/Test/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to HTTP clients", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/http-client-contracts/tree/v3.1.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-04-22T07:30:54+00:00" + }, { "name": "symfony/http-foundation", "version": "v6.1.1", @@ -3852,6 +4197,73 @@ ], "time": "2022-06-09T17:31:33+00:00" }, + { + "name": "symfony/options-resolver", + "version": "v6.1.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/options-resolver.git", + "reference": "a3016f5442e28386ded73c43a32a5b68586dd1c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/a3016f5442e28386ded73c43a32a5b68586dd1c4", + "reference": "a3016f5442e28386ded73c43a32a5b68586dd1c4", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.1|^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\OptionsResolver\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an improved replacement for the array_replace PHP function", + "homepage": "https://symfony.com", + "keywords": [ + "config", + "configuration", + "options" + ], + "support": { + "source": "https://github.com/symfony/options-resolver/tree/v6.1.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-02-25T11:15:52+00:00" + }, { "name": "symfony/password-hasher", "version": "v6.1.0", @@ -4005,6 +4417,93 @@ ], "time": "2022-05-24T11:49:31+00:00" }, + { + "name": "symfony/polyfill-intl-icu", + "version": "v1.26.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-icu.git", + "reference": "e407643d610e5f2c8a4b14189150f68934bf5e48" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-icu/zipball/e407643d610e5f2c8a4b14189150f68934bf5e48", + "reference": "e407643d610e5f2c8a4b14189150f68934bf5e48", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance and support of other locales than \"en\"" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.26-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Icu\\": "" + }, + "classmap": [ + "Resources/stubs" + ], + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's ICU-related data and classes", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "icu", + "intl", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-icu/tree/v1.26.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-05-24T11:49:31+00:00" + }, { "name": "symfony/polyfill-intl-normalizer", "version": "v1.26.0", diff --git a/config/bundles.php b/config/bundles.php index 87181f4..8b5b3e2 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -12,4 +12,5 @@ return [ Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true], ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], + Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], ]; diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index 7853e9e..8a7223e 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -1,6 +1,9 @@ # see https://symfony.com/doc/current/reference/configuration/framework.html framework: secret: '%env(APP_SECRET)%' +# SHOPWARE_API_URL: '%env(string:SHOPWARE_API_URL)%' +# SHOPWARE_API_KEY: '%env(string:SHOPWARE_API_KEY)%' +# SHOPWARE_API_ID: '%env(string:SHOPWARE_API_ID)%' #csrf_protection: true http_method_override: false diff --git a/config/services.yaml b/config/services.yaml index 2d6a76f..f912e77 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -4,6 +4,15 @@ # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration parameters: + # the secret key used to generate tokens + # you should change it to a secret key that is not public + # see https://symfony.com/doc/current/security/token_storage.html#secrets-in-symfony-secrets-v3 + # the url of the shopware api + SHOPWARE_API_URL: '%env(SHOPWARE_API_URL)%' + # the api key of the shopware api + SHOPWARE_API_KEY: '%env(SHOPWARE_API_KEY)%' + # the api id of the shopware api + SHOPWARE_API_ID: '%env(SHOPWARE_API_ID)%' services: # default configuration for services in *this* file diff --git a/migrations/Version20220622115500.php b/migrations/Version20220622115500.php index bc75d18..5a512c5 100644 --- a/migrations/Version20220622115500.php +++ b/migrations/Version20220622115500.php @@ -20,7 +20,7 @@ final class Version20220622115500 extends AbstractMigration public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE TABLE orders (id INT AUTO_INCREMENT NOT NULL, order_id VARCHAR(255) NOT NULL, status INT NOT NULL, data JSON NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE orders (id INT AUTO_INCREMENT NOT NULL, order_id VARCHAR(255) NOT NULL, status INT NULL, data JSON NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); } public function down(Schema $schema): void diff --git a/src/Command/SwGetOrdersCommand.php b/src/Command/SwGetOrdersCommand.php new file mode 100644 index 0000000..d15b73a --- /dev/null +++ b/src/Command/SwGetOrdersCommand.php @@ -0,0 +1,144 @@ +ordersRepository = $ordersRepository; + $this->client = $client; + $this->logger = $logger; + parent::__construct(); + } + + protected function configure(): void + { + $this + ->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description') + ->addOption('option1', null, InputOption::VALUE_NONE, 'Option description') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + $arg1 = $input->getArgument('arg1'); + + if ($arg1) { + $io->note(sprintf('You passed an argument: %s', $arg1)); + } + + if ($input->getOption('option1')) { + // ... + } + + //offene Bestellungen aus Datenbank holen + $orders = $this->getOrders(); + + if(!$orders) { + $io->error('Keine Bestellungen gefunden'); + return Command::FAILURE; + } + + //Bestelldetails aus SW holen + $this->getOrdersFromSW($orders); + + + $io->success('Done!'); + return Command::SUCCESS; + } + + private function getOrders():array + { + return $this->ordersRepository->findAll(); + } + + private function shopwareAuth(){ + + $this->client->withOptions([ + 'headers' => [ + 'Content-Type' => 'application/json', + 'sw-access-key' => 'SWSCY1NPSKHPSFNHWGDLTMM5NQ' + ], + ]); + $response = $this->client->request('GET','http://localhost/store-api/context'); + + + $body = $response->getContent(); + + var_dump($body); + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws \Exception + */ + private function getOrdersFromSW(array $orders):void + { + + + try { + $response = $this->client->request('POST', $_ENV['SHOPWARE_API_URL'].'/store-api/search', [ + '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) { + $this->logger->error($e->getMessage()); + throw new \Exception($e->getMessage()); + } + + + + var_dump($body); + } + +} diff --git a/src/Entity/Orders.php b/src/Entity/Orders.php index 0d5c4d7..b364be1 100644 --- a/src/Entity/Orders.php +++ b/src/Entity/Orders.php @@ -2,13 +2,18 @@ namespace App\Entity; +use ApiPlatform\Core\Annotation\ApiProperty; use App\Repository\OrdersRepository; use Doctrine\ORM\Mapping as ORM; use ApiPlatform\Core\Annotation\ApiResource; #[ORM\Entity(repositoryClass: OrdersRepository::class)] -#[ApiResource(itemOperations: ["GET"])] +#[ApiResource( + itemOperations: ["GET"], + description: "Manage orders", + normalizationContext: ["groups" => "read"] +)] class Orders { #[ORM\Id] @@ -19,12 +24,16 @@ class Orders /** Shopware Order ID */ #[ORM\Column(type: 'string', length: 255)] #[Assert\NotBlank] + #[ApiProperty(example: "467e9804347c4071942c99b55b108142")] + #[Group("read")] private $order_id; #[ORM\Column(type: 'integer')] + #[ApiProperty(example: "1")] private $status; #[ORM\Column(type: 'json')] + #[ApiProperty(writable: false)] private $data = []; public function getId(): ?int diff --git a/src/Repository/OrdersRepository.php b/src/Repository/OrdersRepository.php index 90002e3..310929d 100644 --- a/src/Repository/OrdersRepository.php +++ b/src/Repository/OrdersRepository.php @@ -39,28 +39,33 @@ class OrdersRepository extends ServiceEntityRepository } } -// /** -// * @return Orders[] Returns an array of Orders objects -// */ -// public function findByExampleField($value): array -// { -// return $this->createQueryBuilder('o') -// ->andWhere('o.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('o.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } + /** + * @return Orders[] Returns an array of Orders objects + */ + public function findByStatus($status): array + { + return $this->createQueryBuilder('o') + ->andWhere('o.status = :val') + ->setParameter('val', $status) + ->orderBy('o.id', 'ASC') + ->setMaxResults(100) + ->getQuery() + ->getResult() + ; + } -// public function findOneBySomeField($value): ?Orders -// { -// return $this->createQueryBuilder('o') -// ->andWhere('o.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } + /** + * @param $orderId + * @return Orders|null + * @throws \Doctrine\ORM\NonUniqueResultException + */ + public function findOneByOrderId($orderId): ?Orders + { + return $this->createQueryBuilder('o') + ->andWhere('o.order_id = :val') + ->setParameter('val', $orderId) + ->getQuery() + ->getOneOrNullResult() + ; + } } diff --git a/symfony.lock b/symfony.lock index 37d3123..d527b65 100644 --- a/symfony.lock +++ b/symfony.lock @@ -61,6 +61,18 @@ "config/packages/nelmio_cors.yaml" ] }, + "sensio/framework-extra-bundle": { + "version": "6.2", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "5.2", + "ref": "fb7e19da7f013d0d422fa9bce16f5c510e27609b" + }, + "files": [ + "config/packages/sensio_framework_extra.yaml" + ] + }, "symfony/console": { "version": "6.1", "recipe": {