<?php
namespace App\Entity;
use App\Repository\DeliveryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use JsonSerializable;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=DeliveryRepository::class)
*/
class Delivery implements JsonSerializable
{
// Minimum de commande pour avoir une livraison gratuite
private const amountFreeDelivery = 200;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="float")
*/
private $price;
/**
* @ORM\Column(type="float")
*/
private $totalPrice;
/**
* @ORM\OneToMany(targetEntity=Document::class, mappedBy="delivery")
*/
private $documents;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $position;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isSelected;
public function __construct()
{
$this->documents = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function getTotalPrice(): ?float
{
return $this->totalPrice;
}
public function setTotalPrice(float $totalPrice): self
{
$this->totalPrice = $totalPrice;
return $this;
}
/**
* @return Collection|Document[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
$document->setDelivery($this);
}
return $this;
}
public function removeDocument(Document $document): self
{
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getDelivery() === $this) {
$document->setDelivery(null);
}
}
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(?int $position): self
{
$this->position = $position;
return $this;
}
public function getIsSelected(): ?bool
{
return $this->isSelected;
}
public function setIsSelected(?bool $isSelected): self
{
$this->isSelected = $isSelected;
return $this;
}
public function jsonSerialize()
{
return array(
'id' => $this->getId(),
'name' => $this->getName(),
'price' => $this->getPrice(),
'amountFreeDelivery' => self::amountFreeDelivery,
);
}
}