<?php
namespace Roothirsch\Tuer24Bundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Roothirsch\Tuer24Bundle\Repository\Tuer24OrderItemRepository;
#[ORM\Entity(repositoryClass: "Roothirsch\Tuer24Bundle\Repository\Tuer24OrderItemRepository")]
#[ORM\Table(name: 'roothirsch_tuer24_order_item')]
class Tuer24OrderItem
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'items')]
#[ORM\JoinColumn(nullable: false)]
private ?Tuer24Order $order = null;
#[ORM\Column]
private ?int $productId = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $productSku = null;
#[ORM\Column(length: 255)]
private ?string $productName = null;
#[ORM\Column]
private ?int $quantity = 0;
#[ORM\Column(type: 'decimal', precision: 15, scale: 2)]
private ?string $price = '0.00';
#[ORM\Column(type: 'decimal', precision: 15, scale: 2)]
private ?string $total = '0.00';
public function __construct()
{
$this->calculateTotal();
}
public function getId(): ?int
{
return $this->id;
}
public function getOrder(): ?Tuer24Order
{
return $this->order;
}
public function setOrder(?Tuer24Order $order): self
{
$this->order = $order;
return $this;
}
public function getProductId(): ?int
{
return $this->productId;
}
public function setProductId(int $productId): self
{
$this->productId = $productId;
return $this;
}
public function getProductSku(): ?string
{
return $this->productSku;
}
public function setProductSku(?string $productSku): self
{
$this->productSku = $productSku;
return $this;
}
public function getProductName(): ?string
{
return $this->productName;
}
public function setProductName(string $productName): self
{
$this->productName = $productName;
return $this;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(int $quantity): self
{
$this->quantity = $quantity;
$this->calculateTotal();
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function getPriceAsFloat(): ?float
{
return $this->price !== null ? (float)$this->price : null;
}
public function setPrice(string|float $price): self
{
$this->price = (string)$price;
$this->calculateTotal();
return $this;
}
public function getTotal(): ?string
{
return $this->total;
}
public function getTotalAsFloat(): ?float
{
return $this->total !== null ? (float)$this->total : null;
}
public function setTotal(string|float $total): self
{
$this->total = (string)$total;
return $this;
}
public function calculateTotal(): self
{
$this->total = (string)((float)$this->price * $this->quantity);
return $this;
}
}