src/Flexy/ShopBundle/Entity/Order/OrderItem.php line 27
<?php
namespace App\Flexy\ShopBundle\Entity\Order;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Flexy\ShopBundle\Entity\Customer\PackEngagement;
use App\Flexy\ShopBundle\Entity\Product\Product;
use App\Flexy\ShopBundle\Entity\Shipping\Shipment;
use App\Flexy\ShopBundle\Entity\Shipping\ShipmentItem;
use App\Flexy\ShopBundle\Repository\Order\OrderItemRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\InheritanceType;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: OrderItemRepository::class)]
#[InheritanceType('JOINED')]
#[ApiResource(
normalizationContext: ['groups' => ['read']],
denormalizationContext: ['groups' => ['write']],
)]
class OrderItem implements \Stringable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['read', 'readDeep'])]
private ?string $description = null;
#[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'orderItems', cascade: ['persist'])]
#[Groups(['read', 'readDeep'])]
private ?\App\Flexy\ShopBundle\Entity\Product\Product $product = null;
#[ORM\Column(type: 'integer')]
#[Groups(['read', 'readDeep'])]
private ?int $quantity = 1;
#[ORM\Column(type: 'float', nullable: true)]
#[Groups(['read', 'readDeep'])]
private ?float $price=null;
#[ORM\ManyToOne(targetEntity: Order::class, inversedBy: 'orderItems', cascade: ['persist'])]
private ?\App\Flexy\ShopBundle\Entity\Order\Order $parentOrder = null;
#[ORM\Column(type: 'float', nullable: true)]
private int|float|null $reduction = 0;
#[ORM\OneToMany(targetEntity: OrderItemNote::class, mappedBy: 'orderItem', cascade: ['persist', 'remove'])]
private \Doctrine\Common\Collections\Collection|array $orderItemNotes;
#[ORM\OneToOne(targetEntity: PackEngagement::class, inversedBy: 'orderItem', cascade: ['persist', 'remove'])]
private ?\App\Flexy\ShopBundle\Entity\Customer\PackEngagement $packEngagement = null;
#[ORM\OneToOne(targetEntity: ShipmentItem::class, inversedBy: 'orderItem', cascade: ['persist', 'remove'] )]
private $shipmentItem;
public function __construct()
{
}
public function __toString(): string
{
$price = $this->getPrice();
if($this->getProduct()->getProductType()=="subscription"){
$price = $this->getProduct()->getSubscriptionYearlyPrice();
}
return $this->getDescription()."(". $price ."DH x".$this->getQuantity().")";
}
public function getName()
{
$name = "Undefined Name";
if($this->packEngagement){
$name = $this->packEngagement->getPack()->getTitle();
}elseif($this->product){
$name = $this->product->getName();
}
return $name;
}
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice($price): self
{
$this->price = (float)$price;
return $this;
}
public function getParentOrder(): ?Order
{
return $this->parentOrder;
}
public function setParentOrder(?Order $parentOrder): self
{
$this->parentOrder = $parentOrder;
return $this;
}
public function getFormattedPrice(): ?float
{
return $this->price/100;
}
public function getTotalAmount(): ?float
{
return (($this->price) * $this->quantity);
}
public function getReduction(): ?float
{
return (float)$this->reduction;
}
public function setReduction(?float $reduction): self
{
$this->reduction = $reduction;
return $this;
}
/**
* @return Collection<int, OrderItemNote>
*/
public function getOrderItemNotes(): Collection
{
return $this->orderItemNotes;
}
public function addOrderItemNote(OrderItemNote $orderItemNote): self
{
if (!$this->orderItemNotes->contains($orderItemNote)) {
$this->orderItemNotes[] = $orderItemNote;
$orderItemNote->setOrderItem($this);
}
return $this;
}
public function removeOrderItemNote(OrderItemNote $orderItemNote): self
{
if ($this->orderItemNotes->removeElement($orderItemNote)) {
// set the owning side to null (unless already changed)
if ($orderItemNote->getOrderItem() === $this) {
$orderItemNote->setOrderItem(null);
}
}
return $this;
}
public function getPackEngagement(): ?PackEngagement
{
return $this->packEngagement;
}
public function setPackEngagement(?PackEngagement $packEngagement): self
{
$this->packEngagement = $packEngagement;
return $this;
}
/**
* Get the value of shipmentItem
*/
public function getShipmentItem()
{
return $this->shipmentItem;
}
/**
* Set the value of shipmentItem
*
* @return self
*/
public function setShipmentItem($shipmentItem)
{
$this->shipmentItem = $shipmentItem;
return $this;
}
}