<?php
namespace App\Entity\Shop\Order;
use App\Entity\BaseEntity;
use App\Entity\Shop\Product\Product;
use App\Entity\Shop\Product\ProductPrice;
use App\Repository\Shop\Order\OrderItemRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Faker\Provider\Base;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: OrderItemRepository::class)]
class OrderItem extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\ManyToOne(inversedBy: 'orderItems')]
#[ORM\JoinColumn(nullable: false)]
private ?Order $mainOrder = null;
#[ORM\ManyToOne(inversedBy: 'orderItems')]
#[ORM\JoinColumn(nullable: false)]
private ?Product $product = null;
#[ORM\Column]
private ?int $quantity = null;
#[ORM\Column(type: Types::BIGINT)]
private ?string $price = null;
#[ORM\OneToMany(mappedBy: 'orderItem', targetEntity: OrderItemAttribute::class)]
private Collection $orderItemAttributes;
#[ORM\ManyToOne(inversedBy: 'orderItems')]
private ?ProductPrice $productPrice = null;
public function __construct()
{
parent::__construct();
$this->orderItemAttributes = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getMainOrder(): ?Order
{
return $this->mainOrder;
}
public function setMainOrder(?Order $mainOrder): static
{
$this->mainOrder = $mainOrder;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): static
{
$this->product = $product;
return $this;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(int $quantity): static
{
$this->quantity = $quantity;
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(string $price): static
{
$this->price = $price;
return $this;
}
/**
* @return Collection<int, OrderItemAttribute>
*/
public function getOrderItemAttributes(): Collection
{
return $this->orderItemAttributes;
}
public function addOrderItemAttribute(OrderItemAttribute $orderItemAttribute): static
{
if (!$this->orderItemAttributes->contains($orderItemAttribute)) {
$this->orderItemAttributes->add($orderItemAttribute);
$orderItemAttribute->setOrderItem($this);
}
return $this;
}
public function removeOrderItemAttribute(OrderItemAttribute $orderItemAttribute): static
{
if ($this->orderItemAttributes->removeElement($orderItemAttribute)) {
// set the owning side to null (unless already changed)
if ($orderItemAttribute->getOrderItem() === $this) {
$orderItemAttribute->setOrderItem(null);
}
}
return $this;
}
public function getProductPrice(): ?ProductPrice
{
return $this->productPrice;
}
public function setProductPrice(?ProductPrice $productPrice): static
{
$this->productPrice = $productPrice;
return $this;
}
}