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']],
  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 1;
  39.     #[ORM\Column(type'float'nullabletrue)]
  40.     #[Groups(['read''readDeep'])]
  41.     private ?float $price=null;
  42.     #[ORM\ManyToOne(targetEntityOrder::class, inversedBy'orderItems'cascade: ['persist'])]
  43.     private ?\App\Flexy\ShopBundle\Entity\Order\Order $parentOrder null;
  44.     #[ORM\Column(type'float'nullabletrue)]
  45.     private int|float|null $reduction 0;
  46.     #[ORM\OneToMany(targetEntityOrderItemNote::class, mappedBy'orderItem'cascade: ['persist''remove'])]
  47.     private \Doctrine\Common\Collections\Collection|array $orderItemNotes;
  48.     #[ORM\OneToOne(targetEntityPackEngagement::class, inversedBy'orderItem'cascade: ['persist''remove'])]
  49.     private ?\App\Flexy\ShopBundle\Entity\Customer\PackEngagement $packEngagement null;
  50.     #[ORM\OneToOne(targetEntityShipmentItem::class, inversedBy'orderItem',  cascade: ['persist''remove'] )]
  51.     private $shipmentItem;
  52.  
  53.     public function __construct()
  54.     {
  55.         
  56.         
  57.     }
  58.     public function __toString(): string
  59.     {
  60.         $price $this->getPrice();
  61.         if($this->getProduct()->getProductType()=="subscription"){
  62.             $price $this->getProduct()->getSubscriptionYearlyPrice();
  63.         }
  64.         return $this->getDescription()."("$price ."DH x".$this->getQuantity().")";
  65.     }
  66.     public function getName()
  67.     {
  68.         $name "Undefined Name";
  69.         if($this->packEngagement){
  70.             $name $this->packEngagement->getPack()->getTitle();
  71.         }elseif($this->product){
  72.             $name $this->product->getName();
  73.         }
  74.         return $name;
  75.     }
  76.     public function getId(): ?int
  77.     {
  78.         return $this->id;
  79.     }
  80.     public function getCreatedAt(): ?\DateTimeImmutable
  81.     {
  82.         return $this->createdAt;
  83.     }
  84.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  85.     {
  86.         $this->createdAt $createdAt;
  87.         return $this;
  88.     }
  89.     public function getDescription(): ?string
  90.     {
  91.         return $this->description;
  92.     }
  93.     public function setDescription(?string $description): self
  94.     {
  95.         $this->description $description;
  96.         return $this;
  97.     }
  98.     public function getProduct(): ?Product
  99.     {
  100.         return $this->product;
  101.     }
  102.     public function setProduct(?Product $product): self
  103.     {
  104.         $this->product $product;
  105.         return $this;
  106.     }
  107.     public function getQuantity(): ?int
  108.     {
  109.         return $this->quantity;
  110.     }
  111.     public function setQuantity(int $quantity): self
  112.     {
  113.         $this->quantity $quantity;
  114.         return $this;
  115.     }
  116.     public function getPrice(): ?float
  117.     {
  118.         return $this->price;
  119.     }
  120.     public function setPrice($price): self
  121.     {
  122.         $this->price = (float)$price;
  123.         return $this;
  124.     }
  125.     public function getParentOrder(): ?Order
  126.     {
  127.         return $this->parentOrder;
  128.     }
  129.     public function setParentOrder(?Order $parentOrder): self
  130.     {
  131.         $this->parentOrder $parentOrder;
  132.         return $this;
  133.     }
  134.     public function getFormattedPrice(): ?float
  135.     {
  136.         return $this->price/100;
  137.     }
  138.     public function getTotalAmount(): ?float
  139.     {
  140.         return (($this->price) * $this->quantity);
  141.     }
  142.     public function getReduction(): ?float
  143.     {
  144.         return (float)$this->reduction;
  145.     }
  146.     public function setReduction(?float $reduction): self
  147.     {
  148.         $this->reduction $reduction;
  149.         return $this;
  150.     }
  151.     /**
  152.      * @return Collection<int, OrderItemNote>
  153.      */
  154.     public function getOrderItemNotes(): Collection
  155.     {
  156.         return $this->orderItemNotes;
  157.     }
  158.     public function addOrderItemNote(OrderItemNote $orderItemNote): self
  159.     {
  160.         if (!$this->orderItemNotes->contains($orderItemNote)) {
  161.             $this->orderItemNotes[] = $orderItemNote;
  162.             $orderItemNote->setOrderItem($this);
  163.         }
  164.         return $this;
  165.     }
  166.     public function removeOrderItemNote(OrderItemNote $orderItemNote): self
  167.     {
  168.         if ($this->orderItemNotes->removeElement($orderItemNote)) {
  169.             // set the owning side to null (unless already changed)
  170.             if ($orderItemNote->getOrderItem() === $this) {
  171.                 $orderItemNote->setOrderItem(null);
  172.             }
  173.         }
  174.         return $this;
  175.     }
  176.     public function getPackEngagement(): ?PackEngagement
  177.     {
  178.         return $this->packEngagement;
  179.     }
  180.     public function setPackEngagement(?PackEngagement $packEngagement): self
  181.     {
  182.         $this->packEngagement $packEngagement;
  183.         return $this;
  184.     }
  185.     /**
  186.      * Get the value of shipmentItem
  187.      */ 
  188.     public function getShipmentItem()
  189.     {
  190.         return $this->shipmentItem;
  191.     }
  192.     /**
  193.      * Set the value of shipmentItem
  194.      *
  195.      * @return  self
  196.      */ 
  197.     public function setShipmentItem($shipmentItem)
  198.     {
  199.         $this->shipmentItem $shipmentItem;
  200.         return $this;
  201.     }
  202. }