Add Stock & Warehouse

This commit is contained in:
Marko
2022-07-01 15:31:34 +02:00
parent 460411ab43
commit a2ef85c188
9 changed files with 486 additions and 23 deletions

View File

@@ -69,22 +69,7 @@ class SwGetOrdersCommand extends Command
//offene Bestellungen aus Datenbank holen
$this->orderData = $this->getOrders();
//Bestelldetails aus SW holen
$this->getOrdersDataFromSW();
foreach ($this->orderData as $order) {
$io->info('Bestellung ID: '.$order->getId());
$io->info('Bestellung Order-ID: '.$order->getOrderId());
$io->info('Bestellung Data: '.var_export($order->getData(),1));
$this->saveOrdersData($order);
}
$this->getOrderDetails();
$io->success('Done!');
return Command::SUCCESS;
@@ -98,6 +83,19 @@ class SwGetOrdersCommand extends Command
return $this->ordersRepository->findAll();
}
/**
* @return void
*/
public function getOrderDetails(): void
{
//Bestelldetails aus SW holen
$this->getOrdersDataFromSW();
foreach ($this->orderData as $order) {
$this->saveOrdersData($order);
}
}
/**
* @return \Vin\ShopwareSdk\Data\AccessToken|void
*/

80
src/Entity/Stock.php Normal file
View File

@@ -0,0 +1,80 @@
<?php
namespace App\Entity;
use App\Repository\StockRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: StockRepository::class)]
class Stock
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $product_id;
#[ORM\Column(type: 'integer')]
private $stock;
#[ORM\Column(type: 'datetime', nullable: true)]
private $update_time;
#[ORM\ManyToOne(targetEntity: Warehouse::class, inversedBy: 'warehouse_id')]
private $warehouse_id;
public function getId(): ?int
{
return $this->id;
}
public function getProductId(): ?string
{
return $this->product_id;
}
public function setProductId(string $product_id): self
{
$this->product_id = $product_id;
return $this;
}
public function getStock(): ?int
{
return $this->stock;
}
public function setStock(int $stock): self
{
$this->stock = $stock;
return $this;
}
public function getUpdateTime(): ?\DateTimeInterface
{
return $this->update_time;
}
public function setUpdateTime(?\DateTimeInterface $update_time): self
{
$this->update_time = $update_time;
return $this;
}
public function getWarehouseId(): ?Warehouse
{
return $this->warehouse_id;
}
public function setWarehouseId(?Warehouse $warehouse_id): self
{
$this->warehouse_id = $warehouse_id;
return $this;
}
}

75
src/Entity/Warehouse.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
namespace App\Entity;
use App\Repository\WarehouseRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: WarehouseRepository::class)]
class Warehouse
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\OneToMany(mappedBy: 'warehouse_id', targetEntity: Stock::class)]
private $warehouse_id;
#[ORM\Column(type: 'integer')]
private $priority;
public function __construct()
{
$this->warehouse_id = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection<int, Stock>
*/
public function getWarehouseId(): Collection
{
return $this->warehouse_id;
}
public function addWarehouseId(Stock $warehouseId): self
{
if (!$this->warehouse_id->contains($warehouseId)) {
$this->warehouse_id[] = $warehouseId;
$warehouseId->setWarehouseId($this);
}
return $this;
}
public function removeWarehouseId(Stock $warehouseId): self
{
if ($this->warehouse_id->removeElement($warehouseId)) {
// set the owning side to null (unless already changed)
if ($warehouseId->getWarehouseId() === $this) {
$warehouseId->setWarehouseId(null);
}
}
return $this;
}
public function getPriority(): ?int
{
return $this->priority;
}
public function setPriority(int $priority): self
{
$this->priority = $priority;
return $this;
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace App\EventSubscriber;
use ApiPlatform\Core\EventListener\EventPriorities;
use App\Command\SwGetOrdersCommand;
use App\Entity\Orders;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\KernelEvents;
final class OrdersSubscriber implements EventSubscriberInterface
{
private LoggerInterface $logger;
public function __construct( LoggerInterface $logger )
{
$this->logger = $logger;
}
/**
* @return array[]
*/
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();
$this->logger->info('hier');
}
}

View File

@@ -48,8 +48,6 @@ class OrdersRepository extends ServiceEntityRepository
throw $this->createNotFoundException('Order not found: '.$entity->getId());
}
}
public function remove(Orders $entity, bool $flush = false): void

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\Stock;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Stock>
*
* @method Stock|null find($id, $lockMode = null, $lockVersion = null)
* @method Stock|null findOneBy(array $criteria, array $orderBy = null)
* @method Stock[] findAll()
* @method Stock[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class StockRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Stock::class);
}
public function add(Stock $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Stock $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Stock[] Returns an array of Stock objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('s.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Stock
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\Warehouse;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Warehouse>
*
* @method Warehouse|null find($id, $lockMode = null, $lockVersion = null)
* @method Warehouse|null findOneBy(array $criteria, array $orderBy = null)
* @method Warehouse[] findAll()
* @method Warehouse[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class WarehouseRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Warehouse::class);
}
public function add(Warehouse $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Warehouse $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Warehouse[] Returns an array of Warehouse objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('w')
// ->andWhere('w.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('w.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Warehouse
// {
// return $this->createQueryBuilder('w')
// ->andWhere('w.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}