src/Entity/Website/Order/Order.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Website\Order;
  3. use App\Entity\BaseEntity;
  4. use App\Entity\Generic\Customer\Address;
  5. use App\Entity\Generic\Customer\Customer;
  6. use App\Entity\Website\Accounting\Transaction;
  7. use App\Entity\Website\Website\Website;
  8. use App\Repository\Website\OrderRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\DBAL\Types\Types;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  14. #[ORM\Entity(repositoryClassOrderRepository::class)]
  15. #[ORM\Table(name'`order`')]
  16. class Order extends BaseEntity
  17. {
  18.     #[ORM\Id]
  19.     #[ORM\Column(type'guid'uniquetrue)]
  20.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  21.     #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
  22.     private ?string $id;
  23.     #[ORM\ManyToOne(inversedBy'orders')]
  24.     #[ORM\JoinColumn(nullablefalse)]
  25.     private ?Customer $customer null;
  26.     #[ORM\Column(typeTypes::BIGINT)]
  27.     private ?string $shippingCost null;
  28.     #[ORM\Column(typeTypes::BIGINT,nullablefalse)]
  29.     private ?string $taxAmount null;
  30.     #[ORM\Column(typeTypes::BIGINT)]
  31.     private ?string $totalPrice null;
  32.     #[ORM\ManyToOne(inversedBy'orders')]
  33.     #[ORM\JoinColumn(nullablefalse)]
  34.     private ?OrderStatus $status null;
  35.     #[ORM\ManyToOne(inversedBy'orders')]
  36.     #[ORM\JoinColumn(nullabletrue)]
  37.     private ?ShippingMethod $shippingMethod null;
  38.     #[ORM\Column(length255,nullabletrue)]
  39.     private ?string $trackingCode null;
  40.     #[ORM\OneToMany(mappedBy'mainOrder'targetEntityOrderItem::class, cascade: ['persist'], orphanRemovaltrue)]
  41.     private Collection $orderItems;
  42.     #[ORM\ManyToOne(inversedBy'orders')]
  43.     #[ORM\JoinColumn(nullablefalse)]
  44.     private ?Website $website null;
  45.     #[ORM\ManyToOne(inversedBy'orders')]
  46.     private ?Coupon $coupon null;
  47.     #[ORM\ManyToOne(inversedBy'orders')]
  48.     private ?Address $address null;
  49.     #[ORM\Column(nullabletrue)]
  50.     private ?string $paymentGateway null;
  51.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  52.     private ?string $note null;
  53.     #[ORM\OneToMany(mappedBy'paidOrder'targetEntityTransaction::class)]
  54.     private Collection $transactions;
  55.     #[ORM\Column(type'datetime'nullabletrue)]
  56.     private ?\DateTimeImmutable $paidAt;
  57.     #[ORM\Column]
  58.     private ?bool $isPaid null;
  59.     public function setPaymentGateway(?string $gateway): self
  60.     {
  61.         $this->paymentGateway $gateway;
  62.         return $this;
  63.     }
  64.     public function getPaymentGateway(): ?string
  65.     {
  66.         return $this->paymentGateway;
  67.     }
  68.     public function __construct()
  69.     {
  70.         parent::__construct();
  71.         $this->setIsPaid(0);
  72.         $this->setTaxAmount(0);
  73.         $this->setShippingCost(0);
  74.         $this->setTrackingCode(uniqid('TRK-' false));
  75.         $this->orderItems = new ArrayCollection();
  76.         $this->transactions = new ArrayCollection();
  77.     }
  78.     public function getId(): ?string
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function calculateTax(float $rate): void
  83.     {
  84.         $this->taxAmount = ($this->totalPrice $this->shippingCost) * $rate 100;
  85.     }
  86.     public function getCustomer(): ?Customer
  87.     {
  88.         return $this->customer;
  89.     }
  90.     public function setCustomer(?Customer $customer): static
  91.     {
  92.         $this->customer $customer;
  93.         return $this;
  94.     }
  95.     public function getShippingCost(): ?string
  96.     {
  97.         return $this->shippingCost;
  98.     }
  99.     public function setShippingCost(string $shippingCost): static
  100.     {
  101.         $this->shippingCost $shippingCost;
  102.         return $this;
  103.     }
  104.     public function getTaxAmount(): ?string
  105.     {
  106.         return $this->taxAmount;
  107.     }
  108.     public function setTaxAmount(string $taxAmount): static
  109.     {
  110.         $this->taxAmount $taxAmount;
  111.         return $this;
  112.     }
  113.     public function getTotalPrice(): ?string
  114.     {
  115.         return $this->totalPrice;
  116.     }
  117.     public function setTotalPrice(string $totalPrice): static
  118.     {
  119.         $this->totalPrice $totalPrice;
  120.         return $this;
  121.     }
  122.     public function getStatus(): ?OrderStatus
  123.     {
  124.         return $this->status;
  125.     }
  126.     public function setStatus(?OrderStatus $status): static
  127.     {
  128.         if ($status->getCode() == 'paid'){
  129.             $this->setIsPaid(1);
  130.         }
  131.         $this->status $status;
  132.         return $this;
  133.     }
  134.     public function getShippingMethod(): ?ShippingMethod
  135.     {
  136.         return $this->shippingMethod;
  137.     }
  138.     public function setShippingMethod(?ShippingMethod $shippingMethod): static
  139.     {
  140.         $this->shippingMethod $shippingMethod;
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return Collection<int, OrderItem>
  145.      */
  146.     public function getOrderItems(): Collection
  147.     {
  148.         return $this->orderItems;
  149.     }
  150.     public function addOrderItem(OrderItem $orderItem): static
  151.     {
  152.         if (!$this->orderItems->contains($orderItem)) {
  153.             $this->orderItems->add($orderItem);
  154.             $orderItem->setMainOrder($this);
  155.         }
  156.         return $this;
  157.     }
  158.     public function removeOrderItem(OrderItem $orderItem): static
  159.     {
  160.         if ($this->orderItems->removeElement($orderItem)) {
  161.             // set the owning side to null (unless already changed)
  162.             if ($orderItem->getMainOrder() === $this) {
  163.                 $orderItem->setMainOrder(null);
  164.             }
  165.         }
  166.         return $this;
  167.     }
  168.     public function getTrackingCode(): ?string
  169.     {
  170.         return $this->trackingCode;
  171.     }
  172.     public function setTrackingCode(?string $trackingCode): void
  173.     {
  174.         $this->trackingCode $trackingCode;
  175.     }
  176.     public function getWebsite(): ?Website
  177.     {
  178.         return $this->website;
  179.     }
  180.     public function setWebsite(?Website $shop): static
  181.     {
  182.         $this->website $shop;
  183.         return $this;
  184.     }
  185.     public function getCoupon(): ?Coupon
  186.     {
  187.         return $this->coupon;
  188.     }
  189.     public function setCoupon(?Coupon $coupon): static
  190.     {
  191.         $this->coupon $coupon;
  192.         return $this;
  193.     }
  194.     public function getAddress(): ?Address
  195.     {
  196.         return $this->address;
  197.     }
  198.     public function setAddress(?Address $address): static
  199.     {
  200.         $this->address $address;
  201.         return $this;
  202.     }
  203.     public function getNote(): ?string
  204.     {
  205.         return $this->note;
  206.     }
  207.     public function setNote(?string $note): static
  208.     {
  209.         $this->note $note;
  210.         return $this;
  211.     }
  212.     /**
  213.      * @return Collection<int, Transaction>
  214.      */
  215.     public function getTransactions(): Collection
  216.     {
  217.         return $this->transactions;
  218.     }
  219.     public function addTransaction(Transaction $transaction): static
  220.     {
  221.         if (!$this->transactions->contains($transaction)) {
  222.             $this->transactions->add($transaction);
  223.             $transaction->setPaidOrder($this);
  224.         }
  225.         return $this;
  226.     }
  227.     public function removeTransaction(Transaction $transaction): static
  228.     {
  229.         if ($this->transactions->removeElement($transaction)) {
  230.             // set the owning side to null (unless already changed)
  231.             if ($transaction->getPaidOrder() === $this) {
  232.                 $transaction->setPaidOrder(null);
  233.             }
  234.         }
  235.         return $this;
  236.     }
  237.     public function getPaidAt(): ?\DateTimeImmutable
  238.     {
  239.         return $this->paidAt;
  240.     }
  241.     public function setPaidAt(\DateTimeImmutable $paidAt): static
  242.     {
  243.         $this->paidAt $paidAt;
  244.         return $this;
  245.     }
  246.     public function isIsPaid(): ?bool
  247.     {
  248.         return $this->isPaid;
  249.     }
  250.     public function setIsPaid(bool $isPaid): static
  251.     {
  252.         $this->isPaid $isPaid;
  253.         return $this;
  254.     }
  255. }