src/Entity/Order.php line 13

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. #[ORM\Entity(repositoryClassOrderRepository::class)]
  8. #[ORM\Table(name'`order`')]
  9. #[ORM\HasLifecycleCallbacks]
  10. class Order
  11. {
  12.     public const STATUS_OPEN 'abierto';
  13.     public const STATUS_CLOSE 'finalizado';
  14.     public const STATUS_CANCELLED 'cancelado';
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column(type'integer')]
  18.     private ?int $id null;
  19.     #[ORM\Column(type'string'length255)]
  20.     private string $name;
  21.     #[ORM\Column(type'string'length255)]
  22.     private string $surename;
  23.     #[ORM\Column(type'string'length255)]
  24.     private string $email;
  25.     #[ORM\Column(type'string'length15)]
  26.     private string $phone;
  27.     #[ORM\Column(type'datetime'nullabletrue)]
  28.     private ?\DateTimeInterface $pickupTime null;
  29.     #[ORM\OneToMany(mappedBy'orderRelation'targetEntityOrderProduct::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  30.     private Collection $orderProducts;
  31.     #[ORM\Column(type'datetime')]
  32.     private \DateTimeInterface $createdAt;
  33.     #[ORM\Column(type'float')]
  34.     private float $total;
  35.     #[ORM\Column(type'float')]
  36.     private float $shipping_price 0;
  37.     #[ORM\Column(type'float')]
  38.     private float $final_total;
  39.     #[ORM\Column(type'string'length15)]
  40.     private string $status;
  41.     #[ORM\Column(type'string'length255)]
  42.     private string $address;
  43.     #[ORM\Column(type'string'length50)]
  44.     private string $number;
  45.     #[ORM\Column(type'string'length50nullabletrue)]
  46.     private ?string $door null;
  47.     #[ORM\Column(type'string'length20)]
  48.     private string $postalCode;
  49.     #[ORM\Column(type'string'length100)]
  50.     private string $city;
  51.     #[ORM\Column(type'string'length100)]
  52.     private string $province;
  53.     #[ORM\Column(type'string'length20uniquetruenullabletrue)]
  54.     private ?string $trackingId null;
  55.     #[ORM\OneToOne(mappedBy'order'targetEntityPayment::class, cascade: ['persist''remove'])]
  56.     private ?Payment $payment null;
  57.     #[ORM\OneToOne(mappedBy'order'targetEntityShipping::class, cascade: ['persist''remove'])]
  58.     private ?Shipping $shipping null;
  59.     #[ORM\OneToOne(mappedBy'order'targetEntityInvoice::class, cascade: ['persist''remove'])]
  60.     private ?Invoice $invoice null;
  61.     public function __construct()
  62.     {
  63.         $this->orderProducts = new ArrayCollection();
  64.     }
  65.     public function __toString(): string
  66.     {
  67.         return (string) $this->getId();
  68.     }
  69.     public function setCreatedAt(\DateTimeInterface $createdAt = new \DateTime()): void
  70.     {
  71.         $this->createdAt $createdAt;
  72.     }
  73.     public function getCreatedAt(): \DateTimeInterface
  74.     {
  75.         return $this->createdAt;
  76.     }
  77.     public function getId(): ?int { return $this->id; }
  78.     public function getName(): ?string { return $this->name; }
  79.     public function setName(string $name): self $this->name $name; return $this; }
  80.     public function getSurename(): ?string { return $this->surename; }
  81.     public function setSurename(string $surename): self $this->surename $surename; return $this; }
  82.     public function getEmail(): ?string { return $this->email; }
  83.     public function setEmail(string $email): self $this->email $email; return $this; }
  84.     public function getPhone(): ?string { return $this->phone; }
  85.     public function setPhone(string $phone): self $this->phone $phone; return $this; }
  86.     public function getPickupTime(): ?\DateTimeInterface { return $this->pickupTime; }
  87.     public function setPickupTime(\DateTimeInterface $pickupTime): self $this->pickupTime $pickupTime; return $this; }
  88.     public function getOrderProducts(): Collection { return $this->orderProducts; }
  89.     public function addOrderProduct(OrderProduct $orderProduct): self
  90.     {
  91.         if (!$this->orderProducts->contains($orderProduct)) {
  92.             $this->orderProducts[] = $orderProduct;
  93.             $orderProduct->setOrderRelation($this);
  94.         }
  95.         return $this;
  96.     }
  97.     public function removeOrderProduct(OrderProduct $orderProduct): self
  98.     {
  99.         if ($this->orderProducts->removeElement($orderProduct)) {
  100.             if ($orderProduct->getOrderRelation() === $this) {
  101.                 $orderProduct->setOrderRelation(null);
  102.             }
  103.         }
  104.         return $this;
  105.     }
  106.     public function removeOrderProducts(): self
  107.     {
  108.         foreach($this->getOrderProducts() as $orderProduct){
  109.             $this->removeOrderProduct($orderProduct);
  110.         }
  111.         return $this;
  112.     }
  113.     public function getTotal(): ?float { return $this->total; }
  114.     public function setTotal(float $total): self $this->total $total; return $this; }
  115.     public function getShippingPrice(): ?float { return $this->shipping_price; }
  116.     public function setShippingPrice(float $shipping_price): self $this->shipping_price $shipping_price; return $this; }
  117.     public function getFinalTotal(): ?float { return $this->final_total ?? $this->total $this->shipping_price ; }
  118.     public function setFinalTotal(float $final_total): self $this->final_total $final_total; return $this; }
  119.     public function getStatus(): ?string { return $this->status; }
  120.     public function setStatus(string $status): self $this->status $status; return $this; }
  121.     public function getAddress(): ?string { return $this->address; }
  122.     public function setAddress(string $address): self $this->address $address; return $this; }
  123.     public function getNumber(): ?string { return $this->number; }
  124.     public function setNumber(string $number): self $this->number $number; return $this; }
  125.     public function getDoor(): ?string { return $this->door; }
  126.     public function setDoor(?string $door): self $this->door $door; return $this; }
  127.     public function getPostalCode(): ?string { return $this->postalCode; }
  128.     public function setPostalCode(string $postalCode): self $this->postalCode $postalCode; return $this; }
  129.     public function getCity(): ?string { return $this->city; }
  130.     public function setCity(string $city): self $this->city $city; return $this; }
  131.     public function getProvince(): ?string { return $this->province; }
  132.     public function setProvince(string $province): self $this->province $province; return $this; }
  133.     public function getTrackingId(): ?string { return $this->trackingId; }
  134.     public function setTrackingId(string $trackingId): self $this->trackingId $trackingId; return $this; }
  135.     public function getPayment(): ?Payment { return $this->payment; }
  136.     public function setPayment(?Payment $payment): self $this->payment $payment; return $this; }
  137.     public function getShipping(): ?Shipping { return $this->shipping; }
  138.     public function setShipping(?Shipping $shipping): self $this->shipping $shipping; return $this; }
  139.     public function getInvoice(): ?Invoice { return $this->invoice; }
  140.     public function setInvoice(?Invoice $invoice): self $this->invoice $invoice; return $this; }
  141.     public function getPaymentStatus(): string
  142.     {
  143.         return $this->payment $this->payment->getStatus() : 'no hay pago';
  144.     }
  145.     public function getShippingStatus(): string
  146.     {
  147.         return $this->shipping $this->shipping->getStatus() : 'no hay envio';
  148.     }
  149. }