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

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Shop\Order;
  3. use App\Entity\BaseEntity;
  4. use App\Entity\Generic\Customer\Address;
  5. use App\Entity\Generic\Customer\Customer;
  6. use App\Entity\Shop\Accounting\Transaction;
  7. use App\Entity\Shop\Shop\Shop;
  8. use App\Repository\Shop\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 ?Shop $shop 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.     public function setPaymentGateway(?string $gateway): self
  56.     {
  57.         $this->paymentGateway $gateway;
  58.         return $this;
  59.     }
  60.     public function getPaymentGateway(): ?string
  61.     {
  62.         return $this->paymentGateway;
  63.     }
  64.     public function __construct()
  65.     {
  66.         parent::__construct();
  67.         $this->setTaxAmount(0);
  68.         $this->setShippingCost(0);
  69.         $this->setTrackingCode(uniqid('TRK-' false));
  70.         $this->orderItems = new ArrayCollection();
  71.         $this->transactions = new ArrayCollection();
  72.     }
  73.     public function getId(): ?string
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function calculateTax(float $rate): void
  78.     {
  79.         $this->taxAmount = ($this->totalPrice $this->shippingCost) * $rate 100;
  80.     }
  81.     public function getCustomer(): ?Customer
  82.     {
  83.         return $this->customer;
  84.     }
  85.     public function setCustomer(?Customer $customer): static
  86.     {
  87.         $this->customer $customer;
  88.         return $this;
  89.     }
  90.     public function getShippingCost(): ?string
  91.     {
  92.         return $this->shippingCost;
  93.     }
  94.     public function setShippingCost(string $shippingCost): static
  95.     {
  96.         $this->shippingCost $shippingCost;
  97.         return $this;
  98.     }
  99.     public function getTaxAmount(): ?string
  100.     {
  101.         return $this->taxAmount;
  102.     }
  103.     public function setTaxAmount(string $taxAmount): static
  104.     {
  105.         $this->taxAmount $taxAmount;
  106.         return $this;
  107.     }
  108.     public function getTotalPrice(): ?string
  109.     {
  110.         return $this->totalPrice;
  111.     }
  112.     public function setTotalPrice(string $totalPrice): static
  113.     {
  114.         $this->totalPrice $totalPrice;
  115.         return $this;
  116.     }
  117.     public function getStatus(): ?OrderStatus
  118.     {
  119.         return $this->status;
  120.     }
  121.     public function setStatus(?OrderStatus $status): static
  122.     {
  123.         $this->status $status;
  124.         return $this;
  125.     }
  126.     public function getShippingMethod(): ?ShippingMethod
  127.     {
  128.         return $this->shippingMethod;
  129.     }
  130.     public function setShippingMethod(?ShippingMethod $shippingMethod): static
  131.     {
  132.         $this->shippingMethod $shippingMethod;
  133.         return $this;
  134.     }
  135.     /**
  136.      * @return Collection<int, OrderItem>
  137.      */
  138.     public function getOrderItems(): Collection
  139.     {
  140.         return $this->orderItems;
  141.     }
  142.     public function addOrderItem(OrderItem $orderItem): static
  143.     {
  144.         if (!$this->orderItems->contains($orderItem)) {
  145.             $this->orderItems->add($orderItem);
  146.             $orderItem->setMainOrder($this);
  147.         }
  148.         return $this;
  149.     }
  150.     public function removeOrderItem(OrderItem $orderItem): static
  151.     {
  152.         if ($this->orderItems->removeElement($orderItem)) {
  153.             // set the owning side to null (unless already changed)
  154.             if ($orderItem->getMainOrder() === $this) {
  155.                 $orderItem->setMainOrder(null);
  156.             }
  157.         }
  158.         return $this;
  159.     }
  160.     public function getTrackingCode(): ?string
  161.     {
  162.         return $this->trackingCode;
  163.     }
  164.     public function setTrackingCode(?string $trackingCode): void
  165.     {
  166.         $this->trackingCode $trackingCode;
  167.     }
  168.     public function getShop(): ?Shop
  169.     {
  170.         return $this->shop;
  171.     }
  172.     public function setShop(?Shop $shop): static
  173.     {
  174.         $this->shop $shop;
  175.         return $this;
  176.     }
  177.     public function getCoupon(): ?Coupon
  178.     {
  179.         return $this->coupon;
  180.     }
  181.     public function setCoupon(?Coupon $coupon): static
  182.     {
  183.         $this->coupon $coupon;
  184.         return $this;
  185.     }
  186.     public function getAddress(): ?Address
  187.     {
  188.         return $this->address;
  189.     }
  190.     public function setAddress(?Address $address): static
  191.     {
  192.         $this->address $address;
  193.         return $this;
  194.     }
  195.     public function getNote(): ?string
  196.     {
  197.         return $this->note;
  198.     }
  199.     public function setNote(?string $note): static
  200.     {
  201.         $this->note $note;
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return Collection<int, Transaction>
  206.      */
  207.     public function getTransactions(): Collection
  208.     {
  209.         return $this->transactions;
  210.     }
  211.     public function addTransaction(Transaction $transaction): static
  212.     {
  213.         if (!$this->transactions->contains($transaction)) {
  214.             $this->transactions->add($transaction);
  215.             $transaction->setPaidOrder($this);
  216.         }
  217.         return $this;
  218.     }
  219.     public function removeTransaction(Transaction $transaction): static
  220.     {
  221.         if ($this->transactions->removeElement($transaction)) {
  222.             // set the owning side to null (unless already changed)
  223.             if ($transaction->getPaidOrder() === $this) {
  224.                 $transaction->setPaidOrder(null);
  225.             }
  226.         }
  227.         return $this;
  228.     }
  229. }