src/Entity/Order.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OrderRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=OrderRepository::class)
  9.  * @ORM\Table(name="`order`")
  10.  */
  11. class Order
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="orders")
  21.      * @ORM\JoinColumn(nullable=false)
  22.      */
  23.     private $user;
  24.     /**
  25.      * @ORM\Column(type="datetime_immutable")
  26.      */
  27.     private $created_at;
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      */
  31.     private $carrierName;
  32.     /**
  33.      * @ORM\Column(type="float")
  34.      */
  35.     private $carrierPrice;
  36.     /**
  37.      * @ORM\Column(type="text")
  38.      */
  39.     private $delivery;
  40.     /**
  41.      * @ORM\OneToMany(targetEntity=OrderDetails::class, mappedBy="myOrder")
  42.      */
  43.     private $orderDetails;
  44.     public function __construct()
  45.     {
  46.         $this->orderDetails = new ArrayCollection();
  47.     }
  48.     public function getTotal(){
  49.         $total null;
  50.         foreach($this->getOrderDetails()->getValues() as $product){
  51.             $total $total + ($product->getPrice() * $product->getQuantity());
  52.         }
  53.         return $total;
  54.     }
  55.      /**
  56.      * @ORM\Column(type="boolean")
  57.      */
  58.     private $paid;
  59.     /**
  60.      * @ORM\Column(type="string", length=255)
  61.      */
  62.     private $reference;
  63.     /**
  64.      * @ORM\Column(type="string", length=255)
  65.      */
  66.     private $stripeSessionId;
  67.     public function getPaid(): bool {
  68.         return $this->paid;
  69.     }
  70.     public function setPaid(bool $paid): void {
  71.         $this->paid $paid;
  72.     }
  73.     public function getId(): ?int
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function setId(int $id): self
  78.     {
  79.         $this->id $id;
  80.         return $this;
  81.     }
  82.     public function getUser(): ?user
  83.     {
  84.         return $this->user;
  85.     }
  86.     public function setUser(?user $user): self
  87.     {
  88.         $this->user $user;
  89.         return $this;
  90.     }
  91.     public function getCreatedAt(): ?\DateTimeImmutable
  92.     {
  93.         return $this->created_at;
  94.     }
  95.     public function setCreatedAt(\DateTime $created_at): self
  96.     {
  97.         $immutable_created_at \DateTimeImmutable::createFromMutable($created_at);
  98.     
  99.         $this->created_at $immutable_created_at;
  100.     
  101.         return $this;
  102.     }
  103.     
  104.     public function getCarrierName(): ?string
  105.     {
  106.         return $this->carrierName;
  107.     }
  108.     public function setCarrierName(string $carrierName): self
  109.     {
  110.         $this->carrierName $carrierName;
  111.         return $this;
  112.     }
  113.     public function getCarrierPrice(): ?float
  114.     {
  115.         return $this->carrierPrice;
  116.     }
  117.     public function setCarrierPrice(float $carrierPrice): self
  118.     {
  119.         $this->carrierPrice $carrierPrice;
  120.         return $this;
  121.     }
  122.     public function getDelivery(): ?string
  123.     {
  124.         return $this->delivery;
  125.     }
  126.     public function setDelivery(string $delivery): self
  127.     {
  128.         $this->delivery $delivery;
  129.         return $this;
  130.     }
  131.     /**
  132.      * @return Collection<int, OrderDetails>
  133.      */
  134.     public function getOrderDetails(): Collection
  135.     {
  136.         return $this->orderDetails;
  137.     }
  138.     public function addOrderDetail(OrderDetails $orderDetail): self
  139.     {
  140.         if (!$this->orderDetails->contains($orderDetail)) {
  141.             $this->orderDetails[] = $orderDetail;
  142.             $orderDetail->setMyOrder($this);
  143.         }
  144.         return $this;
  145.     }
  146.     public function removeOrderDetail(OrderDetails $orderDetail): self
  147.     {
  148.         if ($this->orderDetails->removeElement($orderDetail)) {
  149.             // set the owning side to null (unless already changed)
  150.             if ($orderDetail->getMyOrder() === $this) {
  151.                 $orderDetail->setMyOrder(null);
  152.             }
  153.         }
  154.         return $this;
  155.     }
  156.     public function getReference(): ?string
  157.     {
  158.         return $this->reference;
  159.     }
  160.     public function setReference(string $reference): self
  161.     {
  162.         $this->reference $reference;
  163.         return $this;
  164.     }
  165.     public function getStripeSessionId(): ?string
  166.     {
  167.         return $this->stripeSessionId;
  168.     }
  169.     public function setStripeSessionId(string $stripeSessionId): self
  170.     {
  171.         $this->stripeSessionId $stripeSessionId;
  172.         return $this;
  173.     }
  174. }