src/Entity/Delivery.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DeliveryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use JsonSerializable;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=DeliveryRepository::class)
  10.  */
  11. class Delivery implements JsonSerializable
  12. {
  13.     // Minimum de commande pour avoir une livraison gratuite
  14.     private const amountFreeDelivery 200;
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     private $name;
  25.     /**
  26.      * @ORM\Column(type="float")
  27.      */
  28.     private $price;
  29.     /**
  30.      * @ORM\Column(type="float")
  31.      */
  32.     private $totalPrice;
  33.     /**
  34.      * @ORM\OneToMany(targetEntity=Document::class, mappedBy="delivery")
  35.      */
  36.     private $documents;
  37.     /**
  38.      * @ORM\Column(type="integer", nullable=true)
  39.      */
  40.     private $position;
  41.     /**
  42.      * @ORM\Column(type="boolean", nullable=true)
  43.      */
  44.     private $isSelected;
  45.     public function __construct()
  46.     {
  47.         $this->documents = new ArrayCollection();
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getName(): ?string
  54.     {
  55.         return $this->name;
  56.     }
  57.     public function setName(string $name): self
  58.     {
  59.         $this->name $name;
  60.         return $this;
  61.     }
  62.     public function getPrice(): ?float
  63.     {
  64.         return $this->price;
  65.     }
  66.     public function setPrice(float $price): self
  67.     {
  68.         $this->price $price;
  69.         return $this;
  70.     }
  71.     public function getTotalPrice(): ?float
  72.     {
  73.         return $this->totalPrice;
  74.     }
  75.     public function setTotalPrice(float $totalPrice): self
  76.     {
  77.         $this->totalPrice $totalPrice;
  78.         return $this;
  79.     }
  80.     /**
  81.      * @return Collection|Document[]
  82.      */
  83.     public function getDocuments(): Collection
  84.     {
  85.         return $this->documents;
  86.     }
  87.     public function addDocument(Document $document): self
  88.     {
  89.         if (!$this->documents->contains($document)) {
  90.             $this->documents[] = $document;
  91.             $document->setDelivery($this);
  92.         }
  93.         return $this;
  94.     }
  95.     public function removeDocument(Document $document): self
  96.     {
  97.         if ($this->documents->removeElement($document)) {
  98.             // set the owning side to null (unless already changed)
  99.             if ($document->getDelivery() === $this) {
  100.                 $document->setDelivery(null);
  101.             }
  102.         }
  103.         return $this;
  104.     }
  105.     public function getPosition(): ?int
  106.     {
  107.         return $this->position;
  108.     }
  109.     public function setPosition(?int $position): self
  110.     {
  111.         $this->position $position;
  112.         return $this;
  113.     }
  114.     public function getIsSelected(): ?bool
  115.     {
  116.         return $this->isSelected;
  117.     }
  118.     public function setIsSelected(?bool $isSelected): self
  119.     {
  120.         $this->isSelected $isSelected;
  121.         return $this;
  122.     }
  123.     public function jsonSerialize()
  124.     {
  125.         return array(
  126.             'id' => $this->getId(),
  127.             'name' => $this->getName(),
  128.             'price' => $this->getPrice(),
  129.             'amountFreeDelivery' => self::amountFreeDelivery,
  130.         );
  131.     }
  132. }