2
This commit is contained in:
parent
3d8cca58dd
commit
52fae1a695
@ -17,7 +17,8 @@ exports.FetchStream = FetchStream;
|
||||
exports.CookieJar = CookieJar;
|
||||
exports.fetchUrl = fetchUrl;
|
||||
|
||||
function FetchStream(url, options) {
|
||||
function FetchStream(url, options)
|
||||
{
|
||||
Stream.call(this);
|
||||
|
||||
options = options || {};
|
||||
@ -172,7 +173,7 @@ FetchStream.prototype.parseUrl = function (url) {
|
||||
path: urlparts.pathname + (urlparts.search || '') || '/',
|
||||
method: this.options.method,
|
||||
rejectUnauthorized: this.options.rejectUnauthorized
|
||||
};
|
||||
};
|
||||
|
||||
switch (urlparts.protocol) {
|
||||
case 'https:':
|
||||
@ -185,17 +186,17 @@ FetchStream.prototype.parseUrl = function (url) {
|
||||
}
|
||||
|
||||
if (transport === https) {
|
||||
if('agentHttps' in this.options){
|
||||
if ('agentHttps' in this.options) {
|
||||
urloptions.agent = this.options.agentHttps;
|
||||
}
|
||||
if('agent' in this.options){
|
||||
if ('agent' in this.options) {
|
||||
urloptions.agent = this.options.agent;
|
||||
}
|
||||
} else {
|
||||
if('agentHttp' in this.options){
|
||||
if ('agentHttp' in this.options) {
|
||||
urloptions.agent = this.options.agentHttp;
|
||||
}
|
||||
if('agent' in this.options){
|
||||
if ('agent' in this.options) {
|
||||
urloptions.agent = this.options.agent;
|
||||
}
|
||||
}
|
||||
@ -382,7 +383,8 @@ FetchStream.prototype._runStream = function (url_data, url) {
|
||||
}
|
||||
};
|
||||
|
||||
function fetchUrl(url, options, callback) {
|
||||
function fetchUrl(url, options, callback)
|
||||
{
|
||||
if (!callback && typeof options === 'function') {
|
||||
callback = options;
|
||||
options = undefined;
|
||||
@ -453,7 +455,8 @@ function fetchUrl(url, options, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function _parseContentType(str) {
|
||||
function _parseContentType(str)
|
||||
{
|
||||
if (!str) {
|
||||
return {};
|
||||
}
|
||||
@ -476,7 +479,8 @@ function _parseContentType(str) {
|
||||
};
|
||||
}
|
||||
|
||||
function _findHTMLCharset(htmlbuffer) {
|
||||
function _findHTMLCharset(htmlbuffer)
|
||||
{
|
||||
|
||||
var body = htmlbuffer.toString('ascii'),
|
||||
input, meta, charset;
|
||||
|
@ -1,22 +1,26 @@
|
||||
var initParameters = {};
|
||||
var entrypoint = null;
|
||||
|
||||
function onEditQuery(newQuery) {
|
||||
function onEditQuery(newQuery)
|
||||
{
|
||||
initParameters.query = newQuery;
|
||||
updateURL();
|
||||
}
|
||||
|
||||
function onEditVariables(newVariables) {
|
||||
function onEditVariables(newVariables)
|
||||
{
|
||||
initParameters.variables = newVariables;
|
||||
updateURL();
|
||||
}
|
||||
|
||||
function onEditOperationName(newOperationName) {
|
||||
function onEditOperationName(newOperationName)
|
||||
{
|
||||
initParameters.operationName = newOperationName;
|
||||
updateURL();
|
||||
}
|
||||
|
||||
function updateURL() {
|
||||
function updateURL()
|
||||
{
|
||||
var newSearch = '?' + Object.keys(initParameters).filter(function (key) {
|
||||
return Boolean(initParameters[key]);
|
||||
}).map(function (key) {
|
||||
@ -25,7 +29,8 @@ function updateURL() {
|
||||
history.replaceState(null, null, newSearch);
|
||||
}
|
||||
|
||||
function graphQLFetcher(graphQLParams) {
|
||||
function graphQLFetcher(graphQLParams)
|
||||
{
|
||||
return fetch(entrypoint, {
|
||||
method: 'post',
|
||||
headers: {
|
||||
@ -45,7 +50,7 @@ function graphQLFetcher(graphQLParams) {
|
||||
});
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
window.onload = function () {
|
||||
var data = JSON.parse(document.getElementById('graphiql-data').innerText);
|
||||
entrypoint = data.entrypoint;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
window.addEventListener('load', function(event) {
|
||||
window.addEventListener('load', function (event) {
|
||||
var loadingWrapper = document.getElementById('loading-wrapper');
|
||||
loadingWrapper.classList.add('fadeOut');
|
||||
|
||||
|
@ -1,18 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
window.onload = function() {
|
||||
window.onload = function () {
|
||||
manageWebbyDisplay();
|
||||
|
||||
new MutationObserver(function (mutations, self) {
|
||||
const op = document.getElementById(`operations-${data.shortName}-${data.operationId}`);
|
||||
if (!op) return;
|
||||
if (!op) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.disconnect();
|
||||
|
||||
op.querySelector('.opblock-summary').click();
|
||||
const tryOutObserver = new MutationObserver(function (mutations, self) {
|
||||
const tryOut = op.querySelector('.try-out__btn');
|
||||
if (!tryOut) return;
|
||||
if (!tryOut) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.disconnect();
|
||||
|
||||
@ -31,7 +35,7 @@ window.onload = function() {
|
||||
}
|
||||
|
||||
// Wait input values to be populated before executing the query
|
||||
setTimeout(function(){
|
||||
setTimeout(function () {
|
||||
op.querySelector('.execute').click();
|
||||
op.scrollIntoView();
|
||||
}, 500);
|
||||
@ -71,10 +75,12 @@ window.onload = function() {
|
||||
// Adapted from https://github.com/vitalyq/react-trigger-change/blob/master/lib/change.js
|
||||
// Copyright (c) 2017 Vitaly Kuznetsov
|
||||
// MIT License
|
||||
function reactTriggerChange(node) {
|
||||
function reactTriggerChange(node)
|
||||
{
|
||||
// Do not try to delete non-configurable properties.
|
||||
// Value and checked properties on DOM elements are non-configurable in PhantomJS.
|
||||
function deletePropertySafe(elem, prop) {
|
||||
function deletePropertySafe(elem, prop)
|
||||
{
|
||||
const desc = Object.getOwnPropertyDescriptor(elem, prop);
|
||||
if (desc && desc.configurable) {
|
||||
delete elem[prop];
|
||||
@ -129,9 +135,12 @@ window.onload = function() {
|
||||
}
|
||||
}
|
||||
|
||||
function manageWebbyDisplay() {
|
||||
function manageWebbyDisplay()
|
||||
{
|
||||
const webby = document.getElementsByClassName('webby')[0];
|
||||
if (!webby) return;
|
||||
if (!webby) {
|
||||
return;
|
||||
}
|
||||
|
||||
const web = document.getElementsByClassName('web')[0];
|
||||
webby.classList.add('calm');
|
||||
|
@ -25,7 +25,6 @@ use Vin\ShopwareSdk\Data\Filter\EqualsAnyFilter;
|
||||
use Vin\ShopwareSdk\Data\Filter\EqualsFilter;
|
||||
use Vin\ShopwareSdk\Factory\RepositoryFactory;
|
||||
|
||||
|
||||
#[AsCommand(
|
||||
name: 'sw:get-orders',
|
||||
description: 'Holt alle offenen Bestellungen von SW ab',
|
||||
@ -37,7 +36,7 @@ class SwGetOrdersCommand extends Command
|
||||
private $orderData;
|
||||
|
||||
|
||||
public function __construct(OrdersRepository $ordersRepository, LoggerInterface $logger )
|
||||
public function __construct(OrdersRepository $ordersRepository, LoggerInterface $logger)
|
||||
{
|
||||
$this->ordersRepository = $ordersRepository;
|
||||
$this->logger = $logger;
|
||||
@ -80,7 +79,7 @@ class SwGetOrdersCommand extends Command
|
||||
*/
|
||||
private function getOrders():array
|
||||
{
|
||||
return $this->ordersRepository->findAll();
|
||||
return $this->ordersRepository->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,57 +88,55 @@ class SwGetOrdersCommand extends Command
|
||||
public function getOrderDetails(): void
|
||||
{
|
||||
//Bestelldetails aus SW holen
|
||||
$this->getOrdersDataFromSW();
|
||||
$this->getOrdersDataFromSW();
|
||||
|
||||
foreach ($this->orderData as $order) {
|
||||
$this->saveOrdersData($order);
|
||||
}
|
||||
foreach ($this->orderData as $order) {
|
||||
$this->saveOrdersData($order);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Vin\ShopwareSdk\Data\AccessToken|void
|
||||
*/
|
||||
private function shopwareAuth(){
|
||||
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());
|
||||
}
|
||||
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) {
|
||||
private function getOrdersDataFromSW(): void
|
||||
{
|
||||
foreach ($this->orderData as $value) {
|
||||
// Bei Shopware API anmelden
|
||||
$context = new Context($_ENV['SHOPWARE_API_URL'], $this->shopwareAuth());
|
||||
|
||||
// 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 repository for the entity
|
||||
$orderRepository = RepositoryFactory::create(OrderDefinition::ENTITY_NAME);
|
||||
// Create the criteria
|
||||
$criteria = new Criteria();
|
||||
$criteria->addFilter(new EqualsFilter('id', $value->getOrderId()));
|
||||
|
||||
// Create the criteria
|
||||
$criteria = new Criteria();
|
||||
$criteria->addFilter(new EqualsFilter('id', $value->getOrderId()));
|
||||
//Beziehungen zu Produkten holen
|
||||
$criteria->addAssociation('lineItems');
|
||||
|
||||
//Beziehungen zu Produkten holen
|
||||
$criteria->addAssociation('lineItems');
|
||||
try {
|
||||
$orders = $orderRepository->search($criteria, $context);
|
||||
|
||||
try {
|
||||
$orders = $orderRepository->search($criteria, $context);
|
||||
|
||||
$value->setData((array)$orders->getEntities());
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
$value->setData((array)$orders->getEntities());
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,9 +146,6 @@ class SwGetOrdersCommand extends Command
|
||||
private function saveOrdersData($orderData): void
|
||||
{
|
||||
$orderData->setStatus = 1;
|
||||
$this->ordersRepository->add($orderData,true);
|
||||
$this->ordersRepository->add($orderData, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,12 +7,11 @@ use App\Repository\OrdersRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use ApiPlatform\Core\Annotation\ApiResource;
|
||||
|
||||
|
||||
#[ORM\Entity(repositoryClass: OrdersRepository::class)]
|
||||
#[ApiResource(
|
||||
itemOperations: ["GET"],
|
||||
description: "Manage orders",
|
||||
normalizationContext: ["groups" => "read"]
|
||||
itemOperations: ["GET"],
|
||||
description: "Manage orders",
|
||||
normalizationContext: ["groups" => "read"]
|
||||
)]
|
||||
class Orders
|
||||
{
|
||||
|
@ -14,37 +14,35 @@ use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
final class OrdersSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private LoggerInterface $logger;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
public function __construct( LoggerInterface $logger )
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
public function __construct(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
KernelEvents::VIEW => ['getShopwareOrder', EventPriorities::POST_WRITE],
|
||||
];
|
||||
}
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
KernelEvents::VIEW => ['getShopwareOrder', EventPriorities::POST_WRITE],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ViewEvent $event
|
||||
* @return void
|
||||
*/
|
||||
public function getShopwareOrder(ViewEvent $event): void
|
||||
{
|
||||
$data = $event->getControllerResult();
|
||||
$method = $event->getRequest()->getMethod();
|
||||
public function getShopwareOrder(ViewEvent $event): void
|
||||
{
|
||||
$data = $event->getControllerResult();
|
||||
$method = $event->getRequest()->getMethod();
|
||||
|
||||
|
||||
|
||||
|
||||
$this->logger->info('hier');
|
||||
|
||||
|
||||
}
|
||||
$this->logger->info('hier');
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Orders>
|
||||
*
|
||||
@ -20,7 +19,7 @@ class OrdersRepository extends ServiceEntityRepository
|
||||
{
|
||||
private ValidatorInterface $validator;
|
||||
|
||||
public function __construct(ManagerRegistry $registry,ValidatorInterface $validator)
|
||||
public function __construct(ManagerRegistry $registry, ValidatorInterface $validator)
|
||||
{
|
||||
parent::__construct($registry, Orders::class);
|
||||
$this->validator = $validator;
|
||||
@ -30,7 +29,7 @@ class OrdersRepository extends ServiceEntityRepository
|
||||
|
||||
$errors = $this->validator->validate($entity);
|
||||
if (count($errors) > 0) {
|
||||
var_dump($errors);
|
||||
var_dump($errors);
|
||||
}
|
||||
|
||||
$this->getEntityManager()->persist($entity);
|
||||
@ -44,10 +43,9 @@ class OrdersRepository extends ServiceEntityRepository
|
||||
{
|
||||
$order = $this->getEntityManager()->find(Orders::class, $entity->getId());
|
||||
|
||||
if(!$order) {
|
||||
if (!$order) {
|
||||
throw $this->createNotFoundException('Order not found: '.$entity->getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function remove(Orders $entity, bool $flush = false): void
|
||||
|
Loading…
Reference in New Issue
Block a user