src/Flexy/ShopBundle/Entity/Order/OrderItem.php line 27

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Order;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Customer\PackEngagement;
  5. use App\Flexy\ShopBundle\Entity\Product\Product;
  6. use App\Flexy\ShopBundle\Entity\Shipping\Shipment;
  7. use App\Flexy\ShopBundle\Entity\Shipping\ShipmentItem;
  8. use App\Flexy\ShopBundle\Repository\Order\OrderItemRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Doctrine\ORM\Mapping\Entity;
  13. use Doctrine\ORM\Mapping\InheritanceType;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. #[ORM\Entity(repositoryClassOrderItemRepository::class)]
  17. #[InheritanceType('JOINED')]
  18. #[ApiResource(
  19.     normalizationContext: ['groups' => ['read','readPackEngagements']],
  20.     denormalizationContext: ['groups' => ['write']],
  21. )]
  22. class OrderItem implements \Stringable
  23. {
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column(type'integer')]
  27.     private $id;
  28.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  29.     private ?\DateTimeImmutable $createdAt null;
  30.     #[ORM\Column(type'text'nullabletrue)]
  31.     #[Groups(['read''readDeep'])]
  32.     private ?string $description null;
  33.     #[ORM\ManyToOne(targetEntityProduct::class, inversedBy'orderItems'cascade: ['persist'])]
  34.     #[Groups(['read''readDeep'])]
  35.     private ?\App\Flexy\ShopBundle\Entity\Product\Product $product null;
  36.     #[ORM\Column(type'integer')]
  37.     #[Groups(['read''readDeep'])]
  38.     private ?int $quantity null;
  39.     #[ORM\Column(type'float')]
  40.     #[Groups(['read''readDeep'])]
  41.     private ?float $price null;
  42.     
  43.     
  44.     #[ORM\ManyToOne(targetEntityOrder::class, inversedBy'orderItems'cascade: ['persist'])]
  45.     private ?\App\Flexy\ShopBundle\Entity\Order\Order $parentOrder null;
  46.     #[ORM\Column(type'float'nullabletrue)]
  47.     private int|float|null $reduction 0;
  48.     #[ORM\OneToMany(targetEntityOrderItemNote::class, mappedBy'orderItem'cascade: ['persist''remove'])]
  49.     private \Doctrine\Common\Collections\Collection|array $orderItemNotes;
  50.     #[ORM\OneToOne(targetEntityPackEngagement::class, inversedBy'orderItem'cascade: ['persist''remove'])]
  51.     private ?\App\Flexy\ShopBundle\Entity\Customer\PackEngagement $packEngagement null;
  52.     #[ORM\OneToOne(targetEntityShipmentItem::class, inversedBy'orderItem',  cascade: ['persist''remove'] )]
  53.     private $shipmentItem;
  54.     #[ORM\Column(length255nullabletrue)]
  55.     private ?string $image null;
  56.  
  57.     public function __construct()
  58.     {
  59.         
  60.         
  61.     }
  62.     public function __toString(): string
  63.     {
  64.         //return $this->getDescription()."(". $this->getPrice() ."DH x".$this->getQuantity().")";
  65.         $product $this->getProduct();
  66.         return $product $product->getName() : 'Produit non disponible';
  67.     }
  68.     public function getName()
  69.     {
  70.         $name "Undefined Name";
  71.         if($this->packEngagement){
  72.             $name $this->packEngagement->getPack()->getTitle();
  73.         }elseif($this->product){
  74.             $name $this->product->getName();
  75.         }
  76.         return $name;
  77.     }
  78.     public function getId(): ?int
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function getCreatedAt(): ?\DateTimeImmutable
  83.     {
  84.         return $this->createdAt;
  85.     }
  86.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  87.     {
  88.         $this->createdAt $createdAt;
  89.         return $this;
  90.     }
  91.     public function getDescription(): ?string
  92.     {
  93.         return $this->description;
  94.     }
  95.     public function setDescription(?string $description): self
  96.     {
  97.         $this->description $description;
  98.         return $this;
  99.     }
  100.     public function getProduct(): ?Product
  101.     {
  102.         return $this->product;
  103.     }
  104.     public function setProduct(?Product $product): self
  105.     {
  106.         $this->product $product;
  107.         return $this;
  108.     }
  109.     public function getQuantity(): ?int
  110.     {
  111.         return $this->quantity;
  112.     }
  113.     public function setQuantity(int $quantity): self
  114.     {
  115.         $this->quantity $quantity;
  116.         return $this;
  117.     }
  118.     public function getPrice(): ?float
  119.     {
  120.         return $this->price;
  121.     }
  122.     public function setPrice(float $price): self
  123.     {
  124.         $this->price $price;
  125.         return $this;
  126.     }
  127.     public function getParentOrder(): ?Order
  128.     {
  129.         return $this->parentOrder;
  130.     }
  131.     public function setParentOrder(?Order $parentOrder): self
  132.     {
  133.         $this->parentOrder $parentOrder;
  134.         return $this;
  135.     }
  136.     public function getFormattedPrice(): ?float
  137.     {
  138.         return $this->price/100;
  139.     }
  140.     public function getTotalAmount(): ?float
  141.     {
  142.         return (($this->price) * $this->quantity);
  143.     }
  144.     public function getReduction(): ?float
  145.     {
  146.         return (float)$this->reduction;
  147.     }
  148.     public function setReduction(?float $reduction): self
  149.     {
  150.         $this->reduction $reduction;
  151.         return $this;
  152.     }
  153.     /**
  154.      * @return Collection<int, OrderItemNote>
  155.      */
  156.     public function getOrderItemNotes(): Collection
  157.     {
  158.         return $this->orderItemNotes;
  159.     }
  160.     public function addOrderItemNote(OrderItemNote $orderItemNote): self
  161.     {
  162.         if (!$this->orderItemNotes->contains($orderItemNote)) {
  163.             $this->orderItemNotes[] = $orderItemNote;
  164.             $orderItemNote->setOrderItem($this);
  165.         }
  166.         return $this;
  167.     }
  168.     public function removeOrderItemNote(OrderItemNote $orderItemNote): self
  169.     {
  170.         if ($this->orderItemNotes->removeElement($orderItemNote)) {
  171.             // set the owning side to null (unless already changed)
  172.             if ($orderItemNote->getOrderItem() === $this) {
  173.                 $orderItemNote->setOrderItem(null);
  174.             }
  175.         }
  176.         return $this;
  177.     }
  178.     public function getPackEngagement(): ?PackEngagement
  179.     {
  180.         return $this->packEngagement;
  181.     }
  182.     public function setPackEngagement(?PackEngagement $packEngagement): self
  183.     {
  184.         $this->packEngagement $packEngagement;
  185.         return $this;
  186.     }
  187.     /**
  188.      * Get the value of shipmentItem
  189.      */ 
  190.     public function getShipmentItem()
  191.     {
  192.         return $this->shipmentItem;
  193.     }
  194.     /**
  195.      * Set the value of shipmentItem
  196.      *
  197.      * @return  self
  198.      */ 
  199.     public function setShipmentItem($shipmentItem)
  200.     {
  201.         $this->shipmentItem $shipmentItem;
  202.         return $this;
  203.     }
  204.     public function getImage(): ?string
  205.     {
  206.         if($this->getProduct()){
  207.             return $this->getProduct()->getImage();
  208.         }
  209.         return $this->image;
  210.     }
  211.     public function setImage(?string $image): self
  212.     {
  213.         $this->image $image;
  214.         return $this;
  215.     }
  216.     #[Groups(['readPackEngagements'])]
  217.     public function getOrderNumber(){
  218.         return $this->getParentOrder()->getOrderNumber();
  219.     }
  220. }