<?php
namespace App\Entity;
use App\Repository\OrderStatusRepository;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Blameable\Traits\BlameableEntity;
use Gedmo\Timestampable\Traits\TimestampableEntity;
#[ORM\Entity(repositoryClass: OrderStatusRepository::class)]
class OrderStatus extends BaseKeyValue
{
use BlameableEntity; //Hook blameable behaviour. Updates createdBy, updatedBy fields
use TimestampableEntity; //Hook timestampable behaviour. Updates createdAt, updatedAt fields
const PENDING_PAYMENT = 'PENDING_PAYMENT'; // User hasn't pre-authorized the purchase of the order
const MONEY_WITHHELD = 'MONEY_WITHHELD'; // User has pre-authorized the purchase of the order
const NOT_SOLD = 'NOT_SOLD'; // Incomplete order because we haven't reach the minimum qty in the ProductPriceScale. We cancelled the pre-authorization
const PAID = 'PAID'; // User has paid the order
const SENT = 'SENT'; // Product has been sent
const RECEIVED = 'RECEIVED'; // Product has been received
const CANCELED = 'CANCELED'; // Product has been cancelled by User
const BANK_TRANSFER = 'BANK_TRANSFER';
const PENDING_TRANSFER = 'PENDING_TRANSFER';
const CONFIRMED_TRANSFER = 'CONFIRMED_TRANSFER';
#[ORM\Id]
#[ORM\GeneratedValue(strategy: "IDENTITY")]
#[ORM\Column]
private ?int $id = null;
#[ORM\OneToMany(mappedBy: 'status', targetEntity: Order::class)]
private Collection $orders;
public function __construct()
{
$this->orders = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setStatus($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getStatus() === $this) {
$order->setStatus(null);
}
}
return $this;
}
}