src/Order/Doctrine/Entity/Line.php line 25

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Order\Doctrine\Entity;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use App\Program\Doctrine\Entity\Profile;
  6. use App\Shop\Doctrine\Entity\Price;
  7. use App\Shop\Doctrine\Entity\Product;
  8. use Doctrine\ORM\Mapping\Column;
  9. use Doctrine\ORM\Mapping\Entity;
  10. use Doctrine\ORM\Mapping\GeneratedValue;
  11. use Doctrine\ORM\Mapping\Id;
  12. use Doctrine\ORM\Mapping\JoinColumn;
  13. use Doctrine\ORM\Mapping\ManyToOne;
  14. use Doctrine\ORM\Mapping\Table;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Validator\Constraints\GreaterThan;
  17. use Symfony\Component\Validator\Constraints\NotBlank;
  18. use Symfony\Component\Validator\Constraints\NotNull;
  19. #[Entity]
  20. #[Table(name'order_line')]
  21. class Line
  22. {
  23.     #[Id]
  24.     #[Column(type'integer')]
  25.     #[GeneratedValue]
  26.     private ?int $id null;
  27.     #[Column(type'integer')]
  28.     #[Groups(['read''write'])]
  29.     #[NotBlank]
  30.     #[GreaterThan(0)]
  31.     private int $quantity;
  32.     #[Column(type'integer')]
  33.     #[Groups(['read''write'])]
  34.     #[NotBlank]
  35.     #[GreaterThan(0)]
  36.     private int $points;
  37.     #[ManyToOne(targetEntityOrder::class, inversedBy'lines')]
  38.     #[JoinColumn(nullablefalseonDelete'CASCADE')]
  39.     private Order $order;
  40.     #[ManyToOne(targetEntityProduct::class)]
  41.     #[JoinColumn(nullablefalse)]
  42.     #[ApiProperty(readableLinktruewritableLinkfalse)]
  43.     #[Groups(['read''write'])]
  44.     #[NotNull]
  45.     private Product $product;
  46.     #[ManyToOne(targetEntityPrice::class)]
  47.     #[JoinColumn(nullablefalse)]
  48.     private Price $price;
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getQuantity(): int
  54.     {
  55.         return $this->quantity;
  56.     }
  57.     public function setQuantity(int $quantity): void
  58.     {
  59.         $this->quantity $quantity;
  60.     }
  61.     public function getPoints(): int
  62.     {
  63.         return $this->points;
  64.     }
  65.     public function setPoints(int $points): void
  66.     {
  67.         $this->points $points;
  68.     }
  69.     public function getOrder(): Order
  70.     {
  71.         return $this->order;
  72.     }
  73.     public function setOrder(Order $order): void
  74.     {
  75.         $this->order $order;
  76.     }
  77.     public function getProduct(): Product
  78.     {
  79.         return $this->product;
  80.     }
  81.     public function setProduct(Product $product): void
  82.     {
  83.         $this->product $product;
  84.     }
  85.     public function getPrice(): Price
  86.     {
  87.         return $this->price;
  88.     }
  89.     public function setPrice(Price $price): void
  90.     {
  91.         $this->price $price;
  92.     }
  93.     public function getUnitPrice(): int
  94.     {
  95.         return $this->order->getShop()->getPriceValuation()->evaluate($this->product$this->price);
  96.     }
  97.     public function getTotalPrice(): int
  98.     {
  99.         return $this->order->getShop()->getPriceValuation()->evaluate($this->product$this->price) * $this->quantity;
  100.     }
  101.     public function getTotalPoints(): int
  102.     {
  103.         return $this->quantity $this->points;
  104.     }
  105. }