src/Entity/Order.php line 17

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\Events;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Blameable\Traits\BlameableEntity;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. #[ORM\Entity(repositoryClassOrderRepository::class)]
  13. #[ORM\Table(name'`order`')]
  14. class Order
  15. {
  16.     use BlameableEntity//Hook blameable behaviour. Updates createdBy, updatedBy fields
  17.     use TimestampableEntity//Hook timestampable behaviour. Updates createdAt, updatedAt fields 
  18.     
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue(strategy"SEQUENCE")]
  21.     #[ORM\SequenceGenerator(sequenceName"order_id_seq"initialValue10000000)]
  22.     #[ORM\Column]
  23.     private ?int $id null;
  24.     #[ORM\ManyToOne(inversedBy'orders')]
  25.     #[ORM\JoinColumn(nullablefalse)]
  26.     private ?User $buyer null;
  27.     #[ORM\ManyToOne(inversedBy'orders')]
  28.     #[ORM\JoinColumn(nullablefalse)]
  29.     private ?OrderStatus $status null;
  30.     #[ORM\OneToMany(mappedBy'header'targetEntityOrderDetail::class, cascade: ['persist''remove'])]
  31.     private Collection $orderDetails;
  32.     #[ORM\ManyToOne(inversedBy'orders')]
  33.     private ?Card $card null;
  34.     #[ORM\Column(nullabletrue)]
  35.     private ?bool $saveCard false;
  36.     #[ORM\Column(nullable:true)]
  37.     #[Assert\NotNull()]
  38.     #[Assert\PositiveOrZero()]
  39.     protected ?float $shippingCost null;
  40.     #[ORM\Column(nullable:true)]
  41.     #[Assert\NotNull()]
  42.     #[Assert\PositiveOrZero()]
  43.     protected ?float $finalShippingCost null;
  44.     #[ORM\Column(length511nullable:true)]
  45.     #[Assert\NotNull()]
  46.     #[Assert\Length(max511)]
  47.     protected ?string $shippingAddress null;
  48.     #[ORM\Column(type'integer'nullable:true)]
  49.     private ?int $sharedAddressOrderId null;
  50.     #[ORM\Column(length10nullable:true)]
  51.     #[Assert\NotNull()]
  52.     #[Assert\Length(max10)]
  53.     protected ?string $shippingPostalCode null;
  54.     #[ORM\Column(length50nullable:true)]
  55.     #[Assert\NotNull()]
  56.     #[Assert\Length(max50)]
  57.     protected ?string $shippingCity null;
  58.     #[ORM\Column(length100nullable:true)]
  59.     #[Assert\NotNull()]
  60.     #[Assert\Length(max100)]
  61.     protected ?string $shippingCountry null;
  62.     #[ORM\Column(length511nullable:true)]
  63.     #[Assert\NotNull()]
  64.     #[Assert\Length(max511)]
  65.     protected ?string $billingAddress null;
  66.     #[ORM\Column(length10nullable:true)]
  67.     #[Assert\NotNull()]
  68.     #[Assert\Length(max10)]
  69.     protected ?string $billingPostalCode null;
  70.     #[ORM\Column(length50nullable:true)]
  71.     #[Assert\NotNull()]
  72.     #[Assert\Length(max50)]
  73.     protected ?string $billingCity null;
  74.     #[ORM\Column(length100nullable:true)]
  75.     #[Assert\NotNull()]
  76.     #[Assert\Length(max100)]
  77.     protected ?string $billingCountry null;
  78.     #[ORM\Column(length2nullable:true)]
  79.     #[Assert\NotNull()]
  80.     #[Assert\Length(max2)]
  81.     protected ?string $billingCountryIsoCode2 null;
  82.     #[ORM\OneToOne(mappedBy'spentOrder'cascade: ['persist''remove'])]
  83.     private ?Wallet $walletSpent null;
  84.     #[ORM\Column]
  85.     #[Assert\NotNull()]
  86.     #[Assert\PositiveOrZero()]
  87.     protected ?float $totalAmount null;
  88.     #[ORM\Column(length500nullabletrue)]
  89.     private ?string $holdedId null;
  90.     #[ORM\Column(length100nullabletrue)]
  91.     #[Assert\NotNull()]
  92.     #[Assert\Length(max100)]
  93.     private ?string $phone null;
  94.     #[ORM\Column(nullabletrue)]
  95.     private ?bool $needBill false;
  96.     #[ORM\Column(length100nullabletrue)]
  97.     #[Assert\Length(max100)]
  98.     private ?string $cif null;
  99.     #[ORM\OneToOne(mappedBy'spentOrderRefund'cascade: ['persist''remove'])]
  100.     private ?Wallet $walletSpentRefund null;
  101.     #[ORM\Column(nullabletrue)]
  102.     private ?string $shipping_province null;
  103.     #[ORM\Column(length4nullabletrue)]
  104.     private ?string $shipping_country_iso null;
  105.     #[ORM\Column(length50nullabletrue)]
  106.     #[Assert\Length(max50)]
  107.     private ?string $deliveryMethod null;
  108.     #[ORM\ManyToOne(inversedBy'orders')]
  109.     private ?BuyingGroup $buyingGroup null;
  110.     public function __construct()
  111.     {
  112.         $this->orderDetails = new ArrayCollection();
  113.     }
  114.     public function __toString()
  115.     {
  116.         return $this->getId();
  117.     }
  118.     public function getId(): ?int
  119.     {
  120.         return $this->id;
  121.     }
  122.     public function getBuyer(): ?User
  123.     {
  124.         return $this->buyer;
  125.     }
  126.     public function setBuyer(?User $buyer): self
  127.     {
  128.         $this->buyer $buyer;
  129.         return $this;
  130.     }
  131.     public function getStatus(): ?OrderStatus
  132.     {
  133.         return $this->status;
  134.     }
  135.     public function setStatus(?OrderStatus $status): self
  136.     {
  137.         $this->status $status;
  138.         return $this;
  139.     }
  140.     /**
  141.      * @return Collection<int, OrderDetail>
  142.      */
  143.     public function getOrderDetails(): Collection
  144.     {
  145.         return $this->orderDetails;
  146.     }
  147.     public function getFirstOrderDetail(): ?OrderDetail
  148.     {
  149.         $firstOrderDetail null;
  150.         for ($i 0$i <= count($this->orderDetails); $i++) {
  151.             if($i == 0) {
  152.                 $firstOrderDetail $this->orderDetails[$i];
  153.                 break;
  154.             }
  155.         }
  156.         return $firstOrderDetail;
  157.     }
  158.     public function addOrderDetail(OrderDetail $orderDetail): self
  159.     {
  160.         if (!$this->orderDetails->contains($orderDetail)) {
  161.             $this->orderDetails->add($orderDetail);
  162.             $orderDetail->setHeader($this);
  163.         }
  164.         return $this;
  165.     }
  166.     public function removeOrderDetail(OrderDetail $orderDetail): self
  167.     {
  168.         if ($this->orderDetails->removeElement($orderDetail)) {
  169.             // set the owning side to null (unless already changed)
  170.             if ($orderDetail->getHeader() === $this) {
  171.                 $orderDetail->setHeader(null);
  172.             }
  173.         }
  174.         return $this;
  175.     }
  176.     public function removeAllOrderDetail(): self
  177.     {
  178.         foreach($this->orderDetails as $orderDetail) {
  179.             // set the owning side to null (unless already changed)
  180.             if ($orderDetail->getHeader() === $this) {
  181.                 $orderDetail->setHeader(null);
  182.             }
  183.         }
  184.         $this->orderDetails->clear();
  185.         return $this;
  186.     }
  187.     public function getCard(): ?Card
  188.     {
  189.         return $this->card;
  190.     }
  191.     public function setCard(?Card $card): self
  192.     {
  193.         $this->card $card;
  194.         return $this;
  195.     }
  196.     public function getSaveCard(): ?bool
  197.     {
  198.         return $this->saveCard;
  199.     }
  200.     public function setSaveCard(?bool $saveCard): self
  201.     {
  202.         $this->saveCard $saveCard;
  203.         return $this;
  204.     }
  205.     public function getShippingCost(): ?float
  206.     {
  207.         return $this->shippingCost;
  208.     }
  209.     public function setShippingCost(float $shippingCost): self
  210.     {
  211.         $this->shippingCost $shippingCost;
  212.         return $this;
  213.     }
  214.     public function getFinalShippingCost(): ?float
  215.     {
  216.         return $this->finalShippingCost;
  217.     }
  218.     public function setFinalShippingCost(float $finalShippingCost): self
  219.     {
  220.         $this->finalShippingCost $finalShippingCost;
  221.         return $this;
  222.     }
  223.     public function setShippingData(Address $shippingAddress): self
  224.     {
  225.         $this->shippingAddress $shippingAddress->getAddress();
  226.         $this->shippingPostalCode $shippingAddress->getPostalCode();
  227.         $this->shippingCity $shippingAddress->getCity();
  228.         if ($shippingAddress->getCountry()) {
  229.             $this->shippingCountry $shippingAddress->getCountry()->getName();
  230.             $this->shipping_country_iso $shippingAddress->getCountry()->getIsoCode2();
  231.         }
  232.         if ($shippingAddress->getProvince()) {
  233.             $this->shipping_province $shippingAddress->getProvince()->getName();
  234.         }
  235.         return $this;
  236.     }
  237.     public function getShippingAddress(): ?string
  238.     {
  239.         return $this->shippingAddress;
  240.     }
  241.     public function setShippingAddress(?string $shippingAddress): self
  242.     {
  243.         $this->shippingAddress $shippingAddress;
  244.         return $this;
  245.     }
  246.     public function getSharedAddressOrderId(): ?int
  247.     {
  248.         return $this->sharedAddressOrderId;
  249.     } 
  250.     public function setSharedAddressOrderId(?int $sharedAddressOrderId): void
  251.     {
  252.         $this->sharedAddressOrderId $sharedAddressOrderId;
  253.     }
  254.     public function getShippingPostalCode(): ?string
  255.     {
  256.         return $this->shippingPostalCode;
  257.     }
  258.     public function setShippingPostalCode(?string $shippingPostalCode): self
  259.     {
  260.         $this->shippingPostalCode $shippingPostalCode;
  261.         return $this;
  262.     }
  263.     public function getShippingCity(): ?string
  264.     {
  265.         return $this->shippingCity;
  266.     }
  267.     public function setShippingCity(?string $shippingCity): self
  268.     {
  269.         $this->shippingCity $shippingCity;
  270.         return $this;
  271.     }
  272.     public function getShippingCountry(): ?string
  273.     {
  274.         return $this->shippingCountry;
  275.     }
  276.     public function setShippingCountry(?string $shippingCountry): self
  277.     {
  278.         $this->shippingCountry $shippingCountry;
  279.         return $this;
  280.     }
  281.     public function setBillingData(Address $billingAddress): self
  282.     {
  283.         $this->billingAddress $billingAddress->getAddress();
  284.         $this->billingPostalCode $billingAddress->getPostalCode();
  285.         $this->billingCity $billingAddress->getCity();
  286.         $this->billingCountry $billingAddress->getCountry()->getName();
  287.         $this->billingCountryIsoCode2 $billingAddress->getCountry()->getIsoCode2();
  288.         return $this;
  289.     }
  290.     
  291.     public function getHoldedBillingData(): array
  292.     {
  293.         $billAddress = [
  294.             'address' => $this->getBillingAddress(),
  295.             'city' => $this->getBillingCity(),
  296.             'postalCode' => $this->getBillingPostalCode(),
  297.             'country' => $this->getBillingCountryIsoCode2(),
  298.         ];
  299.         return $billAddress;
  300.     }
  301.     public function getBillingAddress(): ?string
  302.     {
  303.         return $this->billingAddress;
  304.     }
  305.     public function setBillingAddress(?string $billingAddress): self
  306.     {
  307.         $this->billingAddress $billingAddress;
  308.         return $this;
  309.     }
  310.     public function getBillingPostalCode(): ?string
  311.     {
  312.         return $this->billingPostalCode;
  313.     }
  314.     public function setBillingPostalCode(?string $billingPostalCode): self
  315.     {
  316.         $this->billingPostalCode $billingPostalCode;
  317.         return $this;
  318.     }
  319.     public function getBillingCity(): ?string
  320.     {
  321.         return $this->billingCity;
  322.     }
  323.     public function setBillingCity(?string $billingCity): self
  324.     {
  325.         $this->billingCity $billingCity;
  326.         return $this;
  327.     }
  328.     public function getBillingCountry(): ?string
  329.     {
  330.         return $this->billingCountry;
  331.     }
  332.     public function setBillingCountry(?string $billingCountry): self
  333.     {
  334.         $this->billingCountry $billingCountry;
  335.         return $this;
  336.     }
  337.     public function getBillingCountryIsoCode2(): ?string
  338.     {
  339.         return $this->billingCountryIsoCode2;
  340.     }
  341.     public function setBillingCountryIsoCode2(string $billingCountryIsoCode2): self
  342.     {
  343.         $this->billingCountryIsoCode2 $billingCountryIsoCode2;
  344.         return $this;
  345.     }
  346.     public function getWalletSpent(): ?Wallet
  347.     {
  348.         return $this->walletSpent;
  349.     }
  350.     public function setWalletSpent(?Wallet $walletSpent): self
  351.     {
  352.         // unset the owning side of the relation if necessary
  353.         if ($walletSpent === null && $this->walletSpent !== null) {
  354.             $this->walletSpent->setSpentOrder(null);
  355.         }
  356.         // set the owning side of the relation if necessary
  357.         if ($walletSpent !== null && $walletSpent->getSpentOrder() !== $this) {
  358.             $walletSpent->setSpentOrder($this);
  359.         }
  360.         $this->walletSpent $walletSpent;
  361.         return $this;
  362.     }
  363.     public function getTotalAmount(): ?float
  364.     {
  365.         return $this->totalAmount;
  366.     }
  367.     public function setTotalAmount(float $totalAmount): self
  368.     {
  369.         $this->totalAmount $totalAmount;
  370.         return $this;
  371.     }
  372.     public function getHoldedId(): ?string
  373.     {
  374.         return $this->holdedId;
  375.     }
  376.     public function setHoldedId(?string $holdedId): self
  377.     {
  378.         $this->holdedId $holdedId;
  379.         return $this;
  380.     }
  381.     public function getPhone(): ?string
  382.     {
  383.         return $this->phone;
  384.     }
  385.     public function setPhone(?string $phone): self
  386.     {
  387.         $this->phone $phone;
  388.         return $this;
  389.     }
  390.     public function getFullShippingAddress(): ?string
  391.     {
  392.         return $this->shippingAddress ' ' $this->shippingPostalCode ', ' $this->shippingCity ' ' $this->shippingCountry;
  393.     }
  394.     public function getFullBillingAddress(): ?string
  395.     {
  396.         return $this->billingAddress ' ' $this->billingPostalCode ', ' $this->billingCity ' ' $this->billingCountry;
  397.     }
  398.     public function getNeedBill(): ?bool
  399.     {
  400.         return $this->needBill;
  401.     }
  402.     public function setNeedBill(?bool $needBill): self
  403.     {
  404.         $this->needBill $needBill;
  405.         return $this;
  406.     }
  407.     public function getCif(): ?string
  408.     {
  409.         return $this->cif;
  410.     }
  411.     public function setCif(?string $cif): self
  412.     {
  413.         $this->cif $cif;
  414.         return $this;
  415.     }
  416.     public function getWalletSpentRefund(): ?Wallet
  417.     {
  418.         return $this->walletSpentRefund;
  419.     }
  420.     public function setWalletSpentRefund(?Wallet $walletSpentRefund): self
  421.     {
  422.         // unset the owning side of the relation if necessary
  423.         if ($walletSpentRefund === null && $this->walletSpentRefund !== null) {
  424.             $this->walletSpentRefund->setSpentOrderRefund(null);
  425.         }
  426.         // set the owning side of the relation if necessary
  427.         if ($walletSpentRefund !== null && $walletSpentRefund->getSpentOrderRefund() !== $this) {
  428.             $walletSpentRefund->setSpentOrderRefund($this);
  429.         }
  430.         $this->walletSpentRefund $walletSpentRefund;
  431.         return $this;
  432.     }
  433.     public function getShippingProvince(): ?string
  434.     {
  435.         return $this->shipping_province;
  436.     }
  437.     public function setShippingProvince(?string $shipping_province): self
  438.     {
  439.         $this->shipping_province $shipping_province;
  440.         return $this;
  441.     }
  442.     public function getShippingCountryIso(): ?string
  443.     {
  444.         return $this->shipping_country_iso;
  445.     }
  446.     public function setShippingCountryIso(?string $shipping_country_iso): self
  447.     {
  448.         $this->shipping_country_iso $shipping_country_iso;
  449.         return $this;
  450.     }
  451.     public function getDeliveryMethod(): ?string
  452.     {
  453.         return $this->deliveryMethod;
  454.     }
  455.     public function setDeliveryMethod(?string $deliveryMethod): self
  456.     {
  457.         $this->deliveryMethod $deliveryMethod;
  458.         return $this;
  459.     }
  460.     public function getExportExcelType():?string{
  461.         if (empty($this->orderDetails)) {
  462.             return "STANDARD";
  463.         }
  464.         return $this->orderDetails[0]->isIndividualPurchase() ? "INDIVIDUAL" "STANDARD";
  465.     }
  466.     public function getExportExcelSource():?string{
  467.         return "";
  468.     }
  469.     public function getExportExcelComments():?string{
  470.         return "";
  471.     }
  472.     public function getBuyingGroup(): ?BuyingGroup
  473.     {
  474.         return $this->buyingGroup;
  475.     }
  476.     public function setBuyingGroup(?BuyingGroup $buyingGroup): self
  477.     {
  478.         $this->buyingGroup $buyingGroup;
  479.         return $this;
  480.     }
  481. }