src/Entity/Order/Order.php line 39

  1. <?php
  2. /*
  3.  * This file is part of the Pellipop project.
  4.  *
  5.  * (c) Mobizel
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App\Entity\Order;
  12. use App\Entity\Customer\Customer;
  13. use App\Entity\Geographical\Address;
  14. use App\Entity\IdentifiableTrait;
  15. use App\OrderProductionStates;
  16. use App\OrderStates;
  17. use App\Repository\Order\OrderRepository;
  18. use Doctrine\Common\Collections\ArrayCollection;
  19. use Doctrine\Common\Collections\Collection;
  20. use Doctrine\ORM\Mapping as ORM;
  21. use Gedmo\Timestampable\Traits\TimestampableEntity;
  22. use Sylius\Component\Resource\Annotation\SyliusCrudRoutes;
  23. use Sylius\Component\Resource\Model\ResourceInterface;
  24. #[ORM\Entity(repositoryClassOrderRepository::class)]
  25. #[ORM\Table(name'app_order')]
  26. #[SyliusCrudRoutes(alias'app.order'path'/admin/orders'section'backend'templates'backend/order'grid'app_backend_order'only: ['index''show'], vars: [
  27.     'all' => [
  28.         'subheader' => 'app.ui.manage_your_orders',
  29.     ],
  30.     'index' => [
  31.         'icon' => 'cart',
  32.     ],
  33. ])]
  34. class Order implements ResourceInterface
  35. {
  36.     use IdentifiableTrait;
  37.     use TimestampableEntity;
  38.     #[ORM\ManyToOne(targetEntityCustomer::class, inversedBy'orders'cascade: ['persist'])]
  39.     #[ORM\JoinColumn(name"customer_id"referencedColumnName"id"onDelete"CASCADE")]
  40.     private ?Customer $customer null;
  41.     #[ORM\ManyToOne(targetEntityAddress::class, cascade:['persist''remove'])]
  42.     #[ORM\JoinColumn(name"shipping_address_id"referencedColumnName"id"onDelete"CASCADE")]
  43.     private ?Address $shippingAddress null;
  44.     #[ORM\Column(type'string')]
  45.     private string $state;
  46.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  47.     private ?\DateTimeImmutable $checkoutCompletedAt null;
  48.     #[ORM\Column(type'integer')]
  49.     private int $shippementAmount 0;
  50.     #[ORM\Column(type'string'nullabletrue)]
  51.     private ?string $number null;
  52.     #[ORM\OneToMany(mappedBy'order'targetEntityOrderItem::class, orphanRemovaltruecascade:['persist''remove'])]
  53.     private Collection $orderItems;
  54.     #[ORM\Column(type'integer')]
  55.     private int $total 0;
  56.     #[ORM\Column(length255)]
  57.     private ?string $productionState null;
  58.     #[ORM\Column(nullabletrue)]
  59.     private ?int $fujiId null;
  60.     #[ORM\Column(type'json')]
  61.     private array $fujiMessages = [];
  62.     #[ORM\Column(type'boolean')]
  63.     private bool $isFromCode false;
  64.     /** Total in cents (€) for direct payment. null when paid with credits. */
  65.     #[ORM\Column(type'integer'nullabletrue)]
  66.     private ?int $totalAmountCents null;
  67.     /** credits | direct | complement */
  68.     #[ORM\Column(type'string'length20options: ['default' => 'credits'])]
  69.     private string $paymentMode 'credits';
  70.     public function __construct()
  71.     {
  72.         $this->state OrderStates::STATE_CART;
  73.         $this->productionState OrderProductionStates::STATE_AWAITING;
  74.         $this->orderItems = new ArrayCollection();
  75.     }
  76.     /**
  77.      * Get the value of customer
  78.      *
  79.      * @return ?Customer
  80.      */
  81.     public function getCustomer(): ?Customer
  82.     {
  83.         return $this->customer;
  84.     }
  85.     /**
  86.      * Set the value of customer
  87.      *
  88.      * @return self
  89.      */
  90.     public function setCustomer(?Customer $customer): self
  91.     {
  92.         $this->customer $customer;
  93.         return $this;
  94.     }
  95.     /**
  96.      * Get the value of shippingAddress
  97.      *
  98.      * @return ?Address
  99.      */
  100.     public function getShippingAddress(): ?Address
  101.     {
  102.         return $this->shippingAddress;
  103.     }
  104.     /**
  105.      * Set the value of shippingAddress
  106.      *
  107.      * @return self
  108.      */
  109.     public function setShippingAddress(?Address $address): self
  110.     {
  111.         $this->shippingAddress $address;
  112.         return $this;
  113.     }
  114.     /**
  115.      * Get the value of state
  116.      *
  117.      * @return string
  118.      */
  119.     public function getState(): string
  120.     {
  121.         return $this->state;
  122.     }
  123.     /**
  124.      * Set the value of state
  125.      *
  126.      * @return self
  127.      */
  128.     public function setState(string $state): self
  129.     {
  130.         $this->state $state;
  131.         return $this;
  132.     }
  133.     /**
  134.      * Get the value of checkoutCompletedAt
  135.      *
  136.      * @return ?\DateTimeImmutable
  137.      */
  138.     public function getCheckoutCompletedAt(): ?\DateTimeImmutable
  139.     {
  140.         return $this->checkoutCompletedAt;
  141.     }
  142.     /**
  143.      * Set the value of checkoutCompletedAt
  144.      *
  145.      * @return self
  146.      */
  147.     public function setCheckoutCompletedAt(?\DateTimeImmutable $checkoutCompletedAt): self
  148.     {
  149.         $this->checkoutCompletedAt $checkoutCompletedAt;
  150.         return $this;
  151.     }
  152.     /**
  153.      * Get the value of shippementAmount
  154.      *
  155.      * @return int
  156.      */
  157.     public function getShippementAmount(): int
  158.     {
  159.         return $this->shippementAmount;
  160.     }
  161.     /**
  162.      * Set the value of shippementAmount
  163.      *
  164.      * @return self
  165.      */
  166.     public function setShippementAmount(int $shippementAmount): self
  167.     {
  168.         $this->shippementAmount $shippementAmount;
  169.         return $this;
  170.     }
  171.     /**
  172.      * Get the value of number
  173.      *
  174.      * @return ?string
  175.      */
  176.     public function getNumber(): ?string
  177.     {
  178.         return $this->number;
  179.     }
  180.     /**
  181.      * Set the value of number
  182.      *
  183.      * @return self
  184.      */
  185.     public function setNumber(?string $number): self
  186.     {
  187.         $this->number $number;
  188.         return $this;
  189.     }
  190.     /**
  191.      * @return Collection<int, OrderItem>
  192.      */
  193.     public function getOrderItems(): Collection
  194.     {
  195.         return $this->orderItems;
  196.     }
  197.     public function addOrderItem(OrderItem $orderItem): self
  198.     {
  199.         if (!$this->orderItems->contains($orderItem)) {
  200.             $this->orderItems->add($orderItem);
  201.             $orderItem->setOrder($this);
  202.         }
  203.         return $this;
  204.     }
  205.     public function removeOrderItem(OrderItem $orderItem): self
  206.     {
  207.         if ($this->orderItems->removeElement($orderItem)) {
  208.             if ($orderItem->getOrder() === $this) {
  209.                 $orderItem->setOrder(null);
  210.             }
  211.         }
  212.         return $this;
  213.     }
  214.     /**
  215.      * Get the value of total
  216.      *
  217.      * @return int
  218.      */
  219.     public function getTotal(): int
  220.     {
  221.         return $this->total;
  222.     }
  223.     /**
  224.      * Set the value of total
  225.      *
  226.      * @return self
  227.      */
  228.     public function setTotal(int $total): self
  229.     {
  230.         $this->total $total;
  231.         return $this;
  232.     }
  233.     public function getProductsCost(): int
  234.     {
  235.         $cost 0;
  236.         foreach ($this->getOrderItems() as $orderItem) {
  237.             $cost += $orderItem->getTotalPrice();
  238.         }
  239.         return $cost;
  240.     }
  241.     public function getFirstItem(): ?OrderItem
  242.     {
  243.         $orderItem $this->getOrderItems()->first();
  244.         return ($orderItem instanceof OrderItem) ? $orderItem null;
  245.     }
  246.     public function getFirstItemName(): ?string
  247.     {
  248.         return ($this->getFirstItem()) ? $this->getFirstItem()->getAlbumName() : null;
  249.     }
  250.     public function getFirstItemQuantity(): int
  251.     {
  252.         return ($this->getFirstItem()) ? $this->getFirstItem()->getQuantity() : 0;
  253.     }
  254.     public function getFirstItemPhotosCount(): int
  255.     {
  256.         return ($this->getFirstItem()) ? $this->getFirstItem()->getPhotosCount() : 0;
  257.     }
  258.     public function getFirstItemAlbumSize(): int
  259.     {
  260.         return ($this->getFirstItem()) ? $this->getFirstItem()->getProduct()->getAlbumSize() : 0;
  261.     }
  262.     public function getFirstItemMattePaper(): ?bool
  263.     {
  264.         return ($this->getFirstItem()) ? $this->getFirstItem()->getMattePaper() : null;
  265.     }
  266.     public function getFirstItemWithFrame(): ?bool
  267.     {
  268.         return ($this->getFirstItem()) ? $this->getFirstItem()->getWithFrame() : null;
  269.     }
  270.     public function getProductionState(): ?string
  271.     {
  272.         return $this->productionState;
  273.     }
  274.     public function setProductionState(string $productionState): self
  275.     {
  276.         $this->productionState $productionState;
  277.         return $this;
  278.     }
  279.     public function getFujiId(): ?int
  280.     {
  281.         return $this->fujiId;
  282.     }
  283.     public function setFujiId(?int $fujiId): self
  284.     {
  285.         $this->fujiId $fujiId;
  286.         return $this;
  287.     }
  288.     public function getFujiMessages(): array
  289.     {
  290.         return $this->fujiMessages;
  291.     }
  292.     public function addFujiMessage(string $fujiMessage): self
  293.     {
  294.         $this->fujiMessages [] = $fujiMessage;
  295.         return $this;
  296.     }
  297.     public function isFromCode(): bool
  298.     {
  299.         return $this->isFromCode;
  300.     }
  301.     public function setIsFromCode(bool $isFromCode): self
  302.     {
  303.         $this->isFromCode $isFromCode;
  304.         return $this;
  305.     }
  306.     public function getTotalAmountCents(): ?int
  307.     {
  308.         return $this->totalAmountCents;
  309.     }
  310.     public function setTotalAmountCents(?int $totalAmountCents): self
  311.     {
  312.         $this->totalAmountCents $totalAmountCents;
  313.         return $this;
  314.     }
  315.     public function getPaymentMode(): string
  316.     {
  317.         return $this->paymentMode;
  318.     }
  319.     public function setPaymentMode(string $paymentMode): self
  320.     {
  321.         $this->paymentMode $paymentMode;
  322.         return $this;
  323.     }
  324.     public function isDirectPayment(): bool
  325.     {
  326.         return $this->paymentMode === 'direct' || $this->paymentMode === 'complement';
  327.     }
  328. }