<?php
namespace App\Entity\Shop\Product;
use App\Entity\BaseEntity;
use App\Entity\Shop\Order\OrderItem;
use App\Repository\Shop\Product\ProductPriceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: ProductPriceRepository::class)]
class ProductPrice extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\Column(nullable: true)]
private ?int $inStock = null;
#[ORM\Column(type: Types::BIGINT)]
private ?string $price = null;
#[ORM\ManyToMany(targetEntity: ProductAttributeValue::class, inversedBy: 'productPrices')]
private Collection $selectedValues;
#[ORM\ManyToOne(inversedBy: 'productPrices')]
#[ORM\JoinColumn(nullable: false)]
private ?Product $product = null;
#[ORM\OneToMany(mappedBy: 'productPrice', targetEntity: OrderItem::class)]
private Collection $orderItems;
public function __construct()
{
parent::__construct();
$this->selectedValues = new ArrayCollection();
$this->orderItems = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getInStock(): ?int
{
return $this->inStock;
}
public function setInStock(?int $inStock): static
{
$this->inStock = $inStock;
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(string $price): static
{
$this->price = $price;
return $this;
}
/**
* @return Collection<int, ProductAttributeValue>
*/
public function getSelectedValues(): Collection
{
return $this->selectedValues;
}
public function addSelectedValue(ProductAttributeValue $selectedValue): static
{
if (!$this->selectedValues->contains($selectedValue)) {
$this->selectedValues->add($selectedValue);
}
return $this;
}
public function removeSelectedValue(ProductAttributeValue $selectedValue): static
{
$this->selectedValues->removeElement($selectedValue);
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): static
{
$this->product = $product;
return $this;
}
/**
* @return Collection<int, OrderItem>
*/
public function getOrderItems(): Collection
{
return $this->orderItems;
}
public function addOrderItem(OrderItem $orderItem): static
{
if (!$this->orderItems->contains($orderItem)) {
$this->orderItems->add($orderItem);
$orderItem->setProductPrice($this);
}
return $this;
}
public function removeOrderItem(OrderItem $orderItem): static
{
if ($this->orderItems->removeElement($orderItem)) {
// set the owning side to null (unless already changed)
if ($orderItem->getProductPrice() === $this) {
$orderItem->setProductPrice(null);
}
}
return $this;
}
}