src/Entity/Order/OrderItem.php line 26

  1. <?php
  2. /*
  3.  * This file is part of the Pellipop project.
  4.  *
  5.  * (c) Mobizel
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App\Entity\Order;
  12. use App\Entity\IdentifiableTrait;
  13. use App\Entity\Product\Product;
  14. use App\OrderItemOptions;
  15. use App\Repository\Order\OrderItemRepository;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\ORM\Mapping as ORM;
  19. #[ORM\Entity(repositoryClassOrderItemRepository::class)]
  20. #[ORM\Table(name'app_order_item')]
  21. class OrderItem
  22. {
  23.     use IdentifiableTrait;
  24.     #[ORM\ManyToOne(inversedBy'orderItems')]
  25.     #[ORM\JoinColumn(nullablefalse)]
  26.     private ?Order $order null;
  27.     #[ORM\Column(type'integer')]
  28.     private int $quantity 0;
  29.     #[ORM\Column(type'integer')]
  30.     private int $unitPrice 0;
  31.     #[ORM\ManyToOne]
  32.     #[ORM\JoinColumn(nullablefalse)]
  33.     private ?Product $product null;
  34.     #[ORM\Column(type'string'length255)]
  35.     private ?string $productName null;
  36.     #[ORM\Column(type'json')]
  37.     private array $options = [];
  38.     #[ORM\OneToMany(mappedBy'orderItem'targetEntityOrderItemPhoto::class, orphanRemovaltrue)]
  39.     private Collection $photos;
  40.     public function __construct()
  41.     {
  42.         $this->photos = new ArrayCollection();
  43.     }
  44.     public function getOrder(): ?Order
  45.     {
  46.         return $this->order;
  47.     }
  48.     public function setOrder(?Order $order): self
  49.     {
  50.         $this->order $order;
  51.         return $this;
  52.     }
  53.     public function getQuantity(): int
  54.     {
  55.         return $this->quantity;
  56.     }
  57.     public function setQuantity(int $quantity): self
  58.     {
  59.         $this->quantity $quantity;
  60.         return $this;
  61.     }
  62.     public function getUnitPrice(): int
  63.     {
  64.         return $this->unitPrice;
  65.     }
  66.     public function setUnitPrice(int $unitPrice): self
  67.     {
  68.         $this->unitPrice $unitPrice;
  69.         return $this;
  70.     }
  71.     public function getProduct(): ?Product
  72.     {
  73.         return $this->product;
  74.     }
  75.     public function setProduct(?Product $product): self
  76.     {
  77.         $this->product $product;
  78.         return $this;
  79.     }
  80.     public function getTotalPrice(): int
  81.     {
  82.         return $this->unitPrice $this->quantity;
  83.     }
  84.     public function getProductName(): ?string
  85.     {
  86.         return $this->productName;
  87.     }
  88.     public function setProductName(string $productName): self
  89.     {
  90.         $this->productName $productName;
  91.         return $this;
  92.     }
  93.     public function getOptions(): array
  94.     {
  95.         return $this->options;
  96.     }
  97.     public function setOptions(array $options): self
  98.     {
  99.         $this->options $options;
  100.         return $this;
  101.     }
  102.     public function getOption(string $key): mixed
  103.     {
  104.         return $this->options[$key] ?? null;
  105.     }
  106.     /**
  107.      * @return Collection<int, OrderItemPhoto>
  108.      */
  109.     public function getPhotos(): Collection
  110.     {
  111.         return $this->photos;
  112.     }
  113.     public function addPhoto(OrderItemPhoto $photo): self
  114.     {
  115.         if (!$this->photos->contains($photo)) {
  116.             $this->photos->add($photo);
  117.             $photo->setOrderItem($this);
  118.         }
  119.         return $this;
  120.     }
  121.     public function removePhoto(OrderItemPhoto $photo): self
  122.     {
  123.         if ($this->photos->removeElement($photo)) {
  124.             // set the owning side to null (unless already changed)
  125.             if ($photo->getOrderItem() === $this) {
  126.                 $photo->setOrderItem(null);
  127.             }
  128.         }
  129.         return $this;
  130.     }
  131.     public function hasPhoto(OrderItemPhoto $photo): bool
  132.     {
  133.         return $this->photos->contains($photo);
  134.     }
  135.     /**
  136.      * @return Collection<int, OrderItemPhoto>
  137.      */
  138.     public function getPhotosByState(string $state): Collection
  139.     {
  140.         return $this->photos->filter(function (OrderItemPhoto $element) use ($state) {
  141.             return $element->getState() === $state;
  142.         });
  143.     }
  144.     public function getPhotosCount(): int
  145.     {
  146.         return $this->getOption(OrderItemOptions::PHOTOS_COUNT) ?? 0;
  147.     }
  148.     public function getMattePaper(): bool
  149.     {
  150.         return $this->getOption(OrderItemOptions::MATTE_PAPER) ?? false;
  151.     }
  152.     public function getWithFrame(): ?bool
  153.     {
  154.         return $this->getOption(OrderItemOptions::WITH_FRAME) ?? false;
  155.     }
  156.     public function getAlbumName(): ?string
  157.     {
  158.         return $this->getOption(OrderItemOptions::ALBUM_NAME) ?? null;
  159.     }
  160.     public function getisFromCode(): ?bool
  161.     {
  162.         return $this->getOption(OrderItemOptions::FROM_CODE) ?? null;
  163.     }
  164. }