<?php
namespace App\Entity;
use App\Entity\Trait\BaseLocalizedWebspaceInterface;
use App\Entity\Trait\BaseLocalizedWebspaceTrait;
use App\Entity\Trait\BlocksTrait;
use App\Entity\Trait\ContentBlocksTrait;
use App\Entity\Trait\RoutableTrait;
use App\Entity\Trait\SeoTrait;
use App\Entity\Trait\SocialTrait;
use App\Repository\ProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Sulu\Bundle\MediaBundle\Entity\Media;
use Sulu\Bundle\MediaBundle\Entity\MediaInterface;
#[ORM\Entity(repositoryClass: ProductRepository::class)]
#[ORM\Table('app_products')]
class Product implements BaseLocalizedWebspaceInterface
{
use BaseLocalizedWebspaceTrait;
use RoutableTrait;
use BlocksTrait;
use ContentBlocksTrait;
use SeoTrait;
use SocialTrait;
public const RESOURCE_KEY = 'products';
public const SOCIAL_OG_IMAGES_TABLE = 'app_product_social_og_images';
public const SOCIAL_TWITTER_IMAGES_TABLE = 'app_product_social_twitter_images';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(type: Types::BOOLEAN)]
private ?bool $active = true;
#[ORM\Column(length: 50, unique: true, nullable: true)]
private ?string $slug = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $code = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $category = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $family = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: ProductIcon::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['position' => 'ASC'])]
private Collection $icons;
#[ORM\ManyToOne(fetch: 'EXTRA_LAZY')]
#[ORM\JoinColumn(referencedColumnName: 'id', onDelete: 'SET NULL')]
private ?Media $image = null;
#[ORM\ManyToOne(fetch: 'EXTRA_LAZY')]
#[ORM\JoinColumn(referencedColumnName: 'id', onDelete: 'SET NULL')]
private ?ProductFamily $productFamily = null;
#[ORM\ManyToOne(fetch: 'EXTRA_LAZY')]
#[ORM\JoinColumn(referencedColumnName: 'id', onDelete: 'SET NULL')]
private ?ProductCategory $productCategory = null;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: ProductVariant::class)]
private Collection $productVariants;
public function __construct()
{
$this->socialInit();
$this->icons = new ArrayCollection();
$this->productVariants = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getActive(): ?string
{
return $this->active;
}
public function setActive(?string $active): static
{
$this->active = $active;
return $this;
}
public function hasSlug(): bool
{
return $this->slug !== null;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): static
{
$this->slug = $slug;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): static
{
$this->code = $code;
return $this;
}
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory(?string $category): static
{
$this->category = $category;
return $this;
}
public function getFamily(): ?string
{
return $this->family;
}
public function setFamily(?string $family): static
{
$this->family = $family;
return $this;
}
public function getImage(): ?Media
{
return $this->image;
}
public function setImage(?Media $image): static
{
$this->image = $image;
return $this;
}
public function isImage(): bool
{
return isset($this->image);
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getProductFamily(): ?ProductFamily
{
return $this->productFamily;
}
public function setProductFamily(?ProductFamily $productFamily): static
{
$this->productFamily = $productFamily;
return $this;
}
public function isProductFamily(): bool
{
return isset($this->productFamily);
}
public function getProductCategory(): ?ProductCategory
{
return $this->productCategory;
}
public function setProductCategory(?ProductCategory $productCategory): static
{
$this->productCategory = $productCategory;
return $this;
}
public function isProductCategory(): bool
{
return isset($this->productCategory);
}
/**
* @return Collection<int, ProductIcon>
*/
public function getIcons(): Collection
{
return $this->icons;
}
public function addIcon(MediaInterface $media, ?int $position = null): static
{
if (!$this->icons->contains($media)) {
$productIcon = new ProductIcon();
$productIcon->setProduct($this);
$productIcon->setMedia($media);
$productIcon->setPosition($position);
$this->icons->add($productIcon);
}
return $this;
}
public function removeIcon(MediaInterface $media): static
{
$this->icons->removeElement($media);
return $this;
}
/**
* @return Collection<int, ProductVariant>
*/
public function getProductVariants(): Collection
{
return $this->productVariants;
}
public function addProductVariant(ProductVariant $productVariant): static
{
if (!$this->productVariants->contains($productVariant)) {
$this->productVariants->add($productVariant);
$productVariant->setProduct($this);
}
return $this;
}
public function removeProductVariant(ProductVariant $productVariant): static
{
if ($this->productVariants->removeElement($productVariant)) {
// set the owning side to null (unless already changed)
if ($productVariant->getProduct() === $this) {
$productVariant->setProduct(null);
}
}
return $this;
}
}