<?php
namespace App\Entity\Shop\Order;
use App\Entity\BaseEntity;
use App\Entity\Shop\Shop\Shop;
use App\Repository\Shop\Order\ShippingMethodRepository;
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: ShippingMethodRepository::class)]
class ShippingMethod extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(type: Types::BIGINT)]
private ?string $cost = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[ORM\OneToMany(mappedBy: 'shippingMethod', targetEntity: Order::class)]
private Collection $orders;
#[ORM\ManyToOne(inversedBy: 'shippingMethods')]
#[ORM\JoinColumn(nullable: false)]
private ?Shop $shop = null;
public function __toString()
{
return $this->getName().' ('.number_format($this->getCost()).' تومان '.')';
}
public function __construct()
{
parent::__construct();
$this->orders = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getCost(): ?string
{
return $this->cost;
}
public function setCost(string $cost): static
{
$this->cost = $cost;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): static
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setShippingMethod($this);
}
return $this;
}
public function removeOrder(Order $order): static
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getShippingMethod() === $this) {
$order->setShippingMethod(null);
}
}
return $this;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): static
{
$this->shop = $shop;
return $this;
}
}