<?php
namespace App\Entity;
use App\Entity\SuperClass\BaseEntity;
use App\Repository\ProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=ProductRepository::class)
*/
class Product extends BaseEntity
{
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="text")
*/
private $metadata;
/**
* @ORM\Column(type="json")
*/
private $description = [];
/**
* @ORM\ManyToOne(targetEntity=Category::class, inversedBy="products")
* @ORM\JoinColumn(nullable=true)
*/
private $category;
/**
* @ORM\Column(type="integer")
*/
private $price;
/**
* @ORM\Column(type="integer")
*/
private $discount;
/**
* @ORM\Column(type="boolean")
*/
private $active;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="products")
*/
private $created_by;
/**
* @ORM\ManyToOne(targetEntity=Product::class, inversedBy="related_services")
*/
private $product;
/**
* @ORM\OneToMany(targetEntity=Product::class, mappedBy="product")
*/
private $related_services;
/**
* @ORM\Column(type="boolean")
*/
private $can_ship;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\OneToMany(targetEntity=OrderItem::class, mappedBy="products")
*/
private $orderItems;
/**
* @ORM\OneToMany(targetEntity=Installment::class, mappedBy="item")
*/
private $installments;
public function __construct()
{
$this->related_services = new ArrayCollection();
$this->orderItems = new ArrayCollection();
$this->installments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?array
{
return $this->description;
}
public function setDescription(array $description): self
{
$this->description = $description;
return $this;
}
public function getPrice(): ?int
{
return $this->price;
}
public function setPrice(int $price): self
{
$this->price = $price;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->created_by;
}
public function setCreatedBy(?User $created_by): self
{
$this->created_by = $created_by;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getMetadata(): ?string
{
return $this->metadata;
}
public function setMetadata(string $metadata): self
{
$this->metadata = $metadata;
return $this;
}
public function getDiscount(): ?float
{
return $this->discount;
}
public function setDiscount(float $discount): self
{
$this->discount = $discount;
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): self
{
$this->category = $category;
return $this;
}
public function getProduct(): ?self
{
return $this->product;
}
public function setProduct(?self $product): self
{
$this->product = $product;
return $this;
}
/**
* @return Collection|self[]
*/
public function getRelatedServices(): Collection
{
return $this->related_services;
}
public function addRelatedService(self $relatedService): self
{
if (!$this->related_services->contains($relatedService)) {
$this->related_services[] = $relatedService;
$relatedService->setProduct($this);
}
return $this;
}
public function removeRelatedService(self $relatedService): self
{
if ($this->related_services->removeElement($relatedService)) {
// set the owning side to null (unless already changed)
if ($relatedService->getProduct() === $this) {
$relatedService->setProduct(null);
}
}
return $this;
}
public function getCanShip(): ?bool
{
return $this->can_ship;
}
public function setCanShip(bool $can_ship): self
{
$this->can_ship = $can_ship;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
/**
* @return Collection<int, OrderItem>
*/
public function getOrderItems(): Collection
{
return $this->orderItems;
}
public function addOrderItem(OrderItem $orderItem): self
{
if (!$this->orderItems->contains($orderItem)) {
$this->orderItems[] = $orderItem;
$orderItem->setProducts($this);
}
return $this;
}
public function removeOrderItem(OrderItem $orderItem): self
{
if ($this->orderItems->removeElement($orderItem)) {
// set the owning side to null (unless already changed)
if ($orderItem->getProducts() === $this) {
$orderItem->setProducts(null);
}
}
return $this;
}
public function __toString()
{
return $this->getName();
}
/**
* @return Collection<int, Installment>
*/
public function getInstallments(): Collection
{
return $this->installments;
}
public function addInstallment(Installment $installment): self
{
if (!$this->installments->contains($installment)) {
$this->installments[] = $installment;
$installment->setItem($this);
}
return $this;
}
public function removeInstallment(Installment $installment): self
{
if ($this->installments->removeElement($installment)) {
// set the owning side to null (unless already changed)
if ($installment->getItem() === $this) {
$installment->setItem(null);
}
}
return $this;
}
}