<?php
namespace App\Entity\Order;
use App\Entity\Product\Product;
use App\Entity\Product\ProductVariant;
use App\Entity\User\Wish;
use App\Repository\Order\SaleItemRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: SaleItemRepository::class)]
class SaleItem
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column]
private ?int $reference_id = null;
#[ORM\Column(length: 50)]
private ?string $type = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(length: 20)]
private string $stockStatus = 'in_stock'; // in_stock, out_of_stock, preorder
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $sku = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
private ?string $stock = '0';
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
private ?string $price_ht = '0';
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
private ?string $price_ttc = '0';
#[ORM\Column(type: Types::DECIMAL, precision: 5, scale: 2)]
private ?string $tax_rate = '20';
#[ORM\Column(length: 10)]
private ?string $currency = 'EUR';
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
private ?string $discount_amount = null;
#[ORM\Column(type: Types::DECIMAL, precision: 5, scale: 2, nullable: true)]
private ?string $discount_percent = null;
#[ORM\Column(nullable: true)]
private ?bool $is_active = true;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $created_at = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $updated_at = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $discountbegin_at = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $discountend_at = null;
#[ORM\OneToOne(inversedBy: 'saleItem', cascade: ['persist', 'remove'])]
private ?Product $product = null;
#[ORM\OneToOne(inversedBy: 'saleItem', cascade: ['persist', 'remove'])]
private ?ProductVariant $productVariant = null;
#[ORM\OneToMany(mappedBy: 'saleItem', targetEntity: CartItem::class)]
private Collection $cartItems;
#[ORM\OneToMany(mappedBy: 'saleItem', targetEntity: OrderItem::class)]
private Collection $orderItems;
#[ORM\OneToMany(mappedBy: 'saleItem', targetEntity: Wish::class)]
private Collection $wishes;
public function __construct()
{
$this->cartItems = new ArrayCollection();
$this->orderItems = new ArrayCollection();
$this->wishes = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getReferenceId(): ?int
{
return $this->reference_id;
}
public function setReferenceId(int $reference_id): static
{
$this->reference_id = $reference_id;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): static
{
$this->type = $type;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getStockStatus(): ?string
{
return $this->stockStatus;
}
public function setStockStatus(string $stockStatus): static
{
$this->stockStatus = $stockStatus;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getSku(): ?string
{
return $this->sku;
}
public function setSku(?string $sku): static
{
$this->sku = $sku;
return $this;
}
public function getStock(): ?int
{
return $this->stock;
}
public function setStock(?int $stock): static
{
$this->stock = $stock;
return $this;
}
public function getPriceHt(): ?string
{
return $this->price_ht;
}
public function setPriceHt(string $price_ht): static
{
$this->price_ht = $price_ht;
return $this;
}
public function getPriceTtc(): ?string
{
return $this->price_ttc;
}
public function setPriceTtc(string $price_ttc): static
{
$this->price_ttc = $price_ttc;
return $this;
}
public function getTaxRate(): ?string
{
return $this->tax_rate;
}
public function setTaxRate(string $tax_rate): static
{
$this->tax_rate = $tax_rate;
return $this;
}
public function getCurrency(): ?string
{
return $this->currency;
}
public function setCurrency(string $currency): static
{
$this->currency = $currency;
return $this;
}
public function getDiscountAmount(): ?string
{
return $this->discount_amount;
}
public function setDiscountAmount(?string $discount_amount): static
{
$this->discount_amount = $discount_amount;
return $this;
}
public function getDiscountPercent(): ?string
{
return $this->discount_percent;
}
public function setDiscountPercent(string $discount_percent): static
{
$this->discount_percent = $discount_percent;
return $this;
}
public function isIsActive(): ?bool
{
return $this->is_active;
}
public function setIsActive(?bool $is_active): static
{
$this->is_active = $is_active;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): static
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(\DateTimeInterface $updated_at): static
{
$this->updated_at = $updated_at;
return $this;
}
public function getDiscountbeginAt(): ?\DateTimeInterface
{
return $this->discountbegin_at;
}
public function setDiscountbeginAt(?\DateTimeInterface $discountbegin_at): static
{
$this->discountbegin_at = $discountbegin_at;
return $this;
}
public function getDiscountendAt(): ?\DateTimeInterface
{
return $this->discountend_at;
}
public function setDiscountendAt(?\DateTimeInterface $discountend_at): static
{
$this->discountend_at = $discountend_at;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): static
{
$this->product = $product;
return $this;
}
public function getProductVariant(): ?ProductVariant
{
return $this->productVariant;
}
public function setProductVariant(?ProductVariant $productVariant): static
{
$this->productVariant = $productVariant;
return $this;
}
/**
* @return Collection<int, CartItem>
*/
public function getCartItems(): Collection
{
return $this->cartItems;
}
public function addCartItem(CartItem $cartItem): static
{
if (!$this->cartItems->contains($cartItem)) {
$this->cartItems->add($cartItem);
$cartItem->setSaleItem($this);
}
return $this;
}
public function removeCartItem(CartItem $cartItem): static
{
if ($this->cartItems->removeElement($cartItem)) {
// set the owning side to null (unless already changed)
if ($cartItem->getSaleItem() === $this) {
$cartItem->setSaleItem(null);
}
}
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->setSaleItem($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->getSaleItem() === $this) {
$orderItem->setSaleItem(null);
}
}
return $this;
}
/**
* @return Collection<int, Wish>
*/
public function getWishes(): Collection
{
return $this->wishes;
}
public function addWish(Wish $wish): static
{
if (!$this->wishes->contains($wish)) {
$this->wishes->add($wish);
$wish->setSaleItem($this);
}
return $this;
}
public function removeWish(Wish $wish): static
{
if ($this->wishes->removeElement($wish)) {
// set the owning side to null (unless already changed)
if ($wish->getSaleItem() === $this) {
$wish->setSaleItem(null);
}
}
return $this;
}
}