src/Entity/Order/OrderItem.php line 26
<?php/** This file is part of the Pellipop project.** (c) Mobizel** For the full copyright and license information, please view the LICENSE* file that was distributed with this source code.*/declare(strict_types=1);namespace App\Entity\Order;use App\Entity\IdentifiableTrait;use App\Entity\Product\Product;use App\OrderItemOptions;use App\Repository\Order\OrderItemRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: OrderItemRepository::class)]#[ORM\Table(name: 'app_order_item')]class OrderItem{use IdentifiableTrait;#[ORM\ManyToOne(inversedBy: 'orderItems')]#[ORM\JoinColumn(nullable: false)]private ?Order $order = null;#[ORM\Column(type: 'integer')]private int $quantity = 0;#[ORM\Column(type: 'integer')]private int $unitPrice = 0;#[ORM\ManyToOne]#[ORM\JoinColumn(nullable: false)]private ?Product $product = null;#[ORM\Column(type: 'string', length: 255)]private ?string $productName = null;#[ORM\Column(type: 'json')]private array $options = [];#[ORM\OneToMany(mappedBy: 'orderItem', targetEntity: OrderItemPhoto::class, orphanRemoval: true)]private Collection $photos;public function __construct(){$this->photos = new ArrayCollection();}public function getOrder(): ?Order{return $this->order;}public function setOrder(?Order $order): self{$this->order = $order;return $this;}public function getQuantity(): int{return $this->quantity;}public function setQuantity(int $quantity): self{$this->quantity = $quantity;return $this;}public function getUnitPrice(): int{return $this->unitPrice;}public function setUnitPrice(int $unitPrice): self{$this->unitPrice = $unitPrice;return $this;}public function getProduct(): ?Product{return $this->product;}public function setProduct(?Product $product): self{$this->product = $product;return $this;}public function getTotalPrice(): int{return $this->unitPrice * $this->quantity;}public function getProductName(): ?string{return $this->productName;}public function setProductName(string $productName): self{$this->productName = $productName;return $this;}public function getOptions(): array{return $this->options;}public function setOptions(array $options): self{$this->options = $options;return $this;}public function getOption(string $key): mixed{return $this->options[$key] ?? null;}/*** @return Collection<int, OrderItemPhoto>*/public function getPhotos(): Collection{return $this->photos;}public function addPhoto(OrderItemPhoto $photo): self{if (!$this->photos->contains($photo)) {$this->photos->add($photo);$photo->setOrderItem($this);}return $this;}public function removePhoto(OrderItemPhoto $photo): self{if ($this->photos->removeElement($photo)) {// set the owning side to null (unless already changed)if ($photo->getOrderItem() === $this) {$photo->setOrderItem(null);}}return $this;}public function hasPhoto(OrderItemPhoto $photo): bool{return $this->photos->contains($photo);}/*** @return Collection<int, OrderItemPhoto>*/public function getPhotosByState(string $state): Collection{return $this->photos->filter(function (OrderItemPhoto $element) use ($state) {return $element->getState() === $state;});}public function getPhotosCount(): int{return $this->getOption(OrderItemOptions::PHOTOS_COUNT) ?? 0;}public function getMattePaper(): bool{return $this->getOption(OrderItemOptions::MATTE_PAPER) ?? false;}public function getWithFrame(): ?bool{return $this->getOption(OrderItemOptions::WITH_FRAME) ?? false;}public function getAlbumName(): ?string{return $this->getOption(OrderItemOptions::ALBUM_NAME) ?? null;}public function getisFromCode(): ?bool{return $this->getOption(OrderItemOptions::FROM_CODE) ?? null;}}