src/Entity/Order/Order.php line 39
<?php/** This file is part of the Pellipop project.** (c) Mobizel** For the full copyright and license information, please view the LICENSE* file that was distributed with this source code.*/declare(strict_types=1);namespace App\Entity\Order;use App\Entity\Customer\Customer;use App\Entity\Geographical\Address;use App\Entity\IdentifiableTrait;use App\OrderProductionStates;use App\OrderStates;use App\Repository\Order\OrderRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Gedmo\Timestampable\Traits\TimestampableEntity;use Sylius\Component\Resource\Annotation\SyliusCrudRoutes;use Sylius\Component\Resource\Model\ResourceInterface;#[ORM\Entity(repositoryClass: OrderRepository::class)]#[ORM\Table(name: 'app_order')]#[SyliusCrudRoutes(alias: 'app.order', path: '/admin/orders', section: 'backend', templates: 'backend/order', grid: 'app_backend_order', only: ['index', 'show'], vars: ['all' => ['subheader' => 'app.ui.manage_your_orders',],'index' => ['icon' => 'cart',],])]class Order implements ResourceInterface{use IdentifiableTrait;use TimestampableEntity;#[ORM\ManyToOne(targetEntity: Customer::class, inversedBy: 'orders', cascade: ['persist'])]#[ORM\JoinColumn(name: "customer_id", referencedColumnName: "id", onDelete: "CASCADE")]private ?Customer $customer = null;#[ORM\ManyToOne(targetEntity: Address::class, cascade:['persist', 'remove'])]#[ORM\JoinColumn(name: "shipping_address_id", referencedColumnName: "id", onDelete: "CASCADE")]private ?Address $shippingAddress = null;#[ORM\Column(type: 'string')]private string $state;#[ORM\Column(type: 'datetime_immutable', nullable: true)]private ?\DateTimeImmutable $checkoutCompletedAt = null;#[ORM\Column(type: 'integer')]private int $shippementAmount = 0;#[ORM\Column(type: 'string', nullable: true)]private ?string $number = null;#[ORM\OneToMany(mappedBy: 'order', targetEntity: OrderItem::class, orphanRemoval: true, cascade:['persist', 'remove'])]private Collection $orderItems;#[ORM\Column(type: 'integer')]private int $total = 0;#[ORM\Column(length: 255)]private ?string $productionState = null;#[ORM\Column(nullable: true)]private ?int $fujiId = null;#[ORM\Column(type: 'json')]private array $fujiMessages = [];#[ORM\Column(type: 'boolean')]private bool $isFromCode = false;/** Total in cents (€) for direct payment. null when paid with credits. */#[ORM\Column(type: 'integer', nullable: true)]private ?int $totalAmountCents = null;/** credits | direct | complement */#[ORM\Column(type: 'string', length: 20, options: ['default' => 'credits'])]private string $paymentMode = 'credits';public function __construct(){$this->state = OrderStates::STATE_CART;$this->productionState = OrderProductionStates::STATE_AWAITING;$this->orderItems = new ArrayCollection();}/*** Get the value of customer** @return ?Customer*/public function getCustomer(): ?Customer{return $this->customer;}/*** Set the value of customer** @return self*/public function setCustomer(?Customer $customer): self{$this->customer = $customer;return $this;}/*** Get the value of shippingAddress** @return ?Address*/public function getShippingAddress(): ?Address{return $this->shippingAddress;}/*** Set the value of shippingAddress** @return self*/public function setShippingAddress(?Address $address): self{$this->shippingAddress = $address;return $this;}/*** Get the value of state** @return string*/public function getState(): string{return $this->state;}/*** Set the value of state** @return self*/public function setState(string $state): self{$this->state = $state;return $this;}/*** Get the value of checkoutCompletedAt** @return ?\DateTimeImmutable*/public function getCheckoutCompletedAt(): ?\DateTimeImmutable{return $this->checkoutCompletedAt;}/*** Set the value of checkoutCompletedAt** @return self*/public function setCheckoutCompletedAt(?\DateTimeImmutable $checkoutCompletedAt): self{$this->checkoutCompletedAt = $checkoutCompletedAt;return $this;}/*** Get the value of shippementAmount** @return int*/public function getShippementAmount(): int{return $this->shippementAmount;}/*** Set the value of shippementAmount** @return self*/public function setShippementAmount(int $shippementAmount): self{$this->shippementAmount = $shippementAmount;return $this;}/*** Get the value of number** @return ?string*/public function getNumber(): ?string{return $this->number;}/*** Set the value of number** @return self*/public function setNumber(?string $number): self{$this->number = $number;return $this;}/*** @return Collection<int, OrderItem>*/public function getOrderItems(): Collection{return $this->orderItems;}public function addOrderItem(OrderItem $orderItem): self{if (!$this->orderItems->contains($orderItem)) {$this->orderItems->add($orderItem);$orderItem->setOrder($this);}return $this;}public function removeOrderItem(OrderItem $orderItem): self{if ($this->orderItems->removeElement($orderItem)) {if ($orderItem->getOrder() === $this) {$orderItem->setOrder(null);}}return $this;}/*** Get the value of total** @return int*/public function getTotal(): int{return $this->total;}/*** Set the value of total** @return self*/public function setTotal(int $total): self{$this->total = $total;return $this;}public function getProductsCost(): int{$cost = 0;foreach ($this->getOrderItems() as $orderItem) {$cost += $orderItem->getTotalPrice();}return $cost;}public function getFirstItem(): ?OrderItem{$orderItem = $this->getOrderItems()->first();return ($orderItem instanceof OrderItem) ? $orderItem : null;}public function getFirstItemName(): ?string{return ($this->getFirstItem()) ? $this->getFirstItem()->getAlbumName() : null;}public function getFirstItemQuantity(): int{return ($this->getFirstItem()) ? $this->getFirstItem()->getQuantity() : 0;}public function getFirstItemPhotosCount(): int{return ($this->getFirstItem()) ? $this->getFirstItem()->getPhotosCount() : 0;}public function getFirstItemAlbumSize(): int{return ($this->getFirstItem()) ? $this->getFirstItem()->getProduct()->getAlbumSize() : 0;}public function getFirstItemMattePaper(): ?bool{return ($this->getFirstItem()) ? $this->getFirstItem()->getMattePaper() : null;}public function getFirstItemWithFrame(): ?bool{return ($this->getFirstItem()) ? $this->getFirstItem()->getWithFrame() : null;}public function getProductionState(): ?string{return $this->productionState;}public function setProductionState(string $productionState): self{$this->productionState = $productionState;return $this;}public function getFujiId(): ?int{return $this->fujiId;}public function setFujiId(?int $fujiId): self{$this->fujiId = $fujiId;return $this;}public function getFujiMessages(): array{return $this->fujiMessages;}public function addFujiMessage(string $fujiMessage): self{$this->fujiMessages [] = $fujiMessage;return $this;}public function isFromCode(): bool{return $this->isFromCode;}public function setIsFromCode(bool $isFromCode): self{$this->isFromCode = $isFromCode;return $this;}public function getTotalAmountCents(): ?int{return $this->totalAmountCents;}public function setTotalAmountCents(?int $totalAmountCents): self{$this->totalAmountCents = $totalAmountCents;return $this;}public function getPaymentMode(): string{return $this->paymentMode;}public function setPaymentMode(string $paymentMode): self{$this->paymentMode = $paymentMode;return $this;}public function isDirectPayment(): bool{return $this->paymentMode === 'direct' || $this->paymentMode === 'complement';}}