<?php
namespace MLDev\CatalogBundle\Entity;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;
use MLDev\BaseBundle\Contract\SeoSite\SeoSiteInfoInterface;
use MLDev\BaseBundle\Entity\Page;
use MLDev\BaseBundle\Entity\Traits\Timestampable;
use MLDev\CatalogBundle\Repository\ProductRepository;
/**
* @ORM\Table(name="MLDev_Product")
* @ORM\Entity(repositoryClass=ProductRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class Product
{
use Timestampable;
const ORDER_BY_NAME = 'name';
const ORDER_BY_PRICE = 'price';
const ORDER_BY_PRIORITY = 'priority';
/**
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(name="external_id", type="string", nullable=true)
*/
private $externalId;
/**
* @ORM\Column(name="name", type="string", nullable=false)
*/
private $name;
/**
* @ORM\Column(name="alter_name", type="string", nullable=true)
*/
private $alterName;
/**
* @Gedmo\Slug(fields={"name"}, updatable=false, unique=true, separator="-")
* @ORM\Column(name="alias", type="string", length=255, nullable=false)
*/
private $alias;
/**
* @ORM\Column(name="unit", type="string", nullable=true)
*/
private $unit;
/**
* @ORM\Column(name="annotation", type="text", nullable=true)
*/
private $annotation;
/**
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="integer", name="priority", nullable=true)
*/
private $priority = 100;
/**
* @ORM\ManyToMany(targetEntity="MLDev\BaseBundle\Entity\Page", fetch="EXTRA_LAZY")
* @ORM\JoinTable(name="MLDev_Product_Page",
* joinColumns={
* @ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="CASCADE")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="page_id", referencedColumnName="id", onDelete="CASCADE")
* }
* )
*/
private $pages;
/**
* @ORM\ManyToMany(targetEntity="MLDev\CatalogBundle\Entity\Product")
* @ORM\JoinTable(name="MLDev_Product_Related",
* joinColumns={
* @ORM\JoinColumn(name="main_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="linked_id", referencedColumnName="id")}
* )
*/
private $related;
/**
* @ORM\ManyToOne(targetEntity="MLDev\CatalogBundle\Entity\Brand", inversedBy="products")
* @ORM\JoinColumn(name="brand_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $brand;
/**
* @ORM\Column(name="is_active", type="boolean", nullable=false)
*/
private $isActive = true;
/**
* @ORM\OneToMany(targetEntity="MLDev\CatalogBundle\Entity\ProductItem", mappedBy="product", cascade={"persist", "remove"}, fetch="EXTRA_LAZY", orphanRemoval=true)
*/
private $items;
/**
* @ORM\OneToMany(targetEntity="MLDev\CatalogBundle\Entity\ProductImage", mappedBy="product", cascade={"persist", "remove"}, fetch="EXTRA_LAZY", orphanRemoval=true)
*/
private $images;
/**
* @ORM\OneToMany(targetEntity="MLDev\CatalogBundle\Entity\ProductDocument", mappedBy="product", cascade={"persist", "remove"}, fetch="EXTRA_LAZY", orphanRemoval=true)
*/
private $documents;
/**
* @ORM\ManyToMany(targetEntity=SeoSiteInfoInterface::class, cascade={"persist"})
* @ORM\JoinTable(
* name="MLDev_Product_SeoInfo",
* joinColumns={
* @ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="CASCADE")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="seo_info_id", referencedColumnName="id", onDelete="CASCADE")
* }
* )
*/
private $seoInfo;
/**
* @ORM\Column(name="extra_fields", type="array", nullable=true)
*/
private $extraFields = [];
public function __construct($page = null)
{
$this->pages = new ArrayCollection();
$this->items = new ArrayCollection();
$this->images = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->related = new ArrayCollection();
$this->seoInfo = new ArrayCollection();
if ($page instanceof Page) {
$this->addPage($page);
}
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getExternalId(): ?string
{
return $this->externalId;
}
public function setExternalId(?string $externalId): void
{
$this->externalId = $externalId;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name)
{
$this->name = $name;
}
public function getAlterName(): ?string
{
return $this->alterName;
}
public function setAlterName(?string $alterName): void
{
$this->alterName = $alterName;
}
public function getAlias(): ?string
{
return $this->alias;
}
public function setAlias(?string $alias): void
{
$this->alias = $alias;
}
public function getUnit(): ?string
{
return $this->unit;
}
public function setUnit(?string $unit)
{
$this->unit = $unit;
}
public function getAnnotation(): ?string
{
return $this->annotation;
}
public function setAnnotation(?string $annotation)
{
$this->annotation = $annotation;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description)
{
$this->description = $description;
}
public function getPriority(): ?int
{
return $this->priority;
}
public function setPriority(?int $priority): void
{
$this->priority = $priority;
}
public function addPage(Page $page): self
{
$this->pages->add($page);
return $this;
}
public function removePage(Page $page)
{
$this->pages->removeElement($page);
}
public function getPages(): iterable
{
return $this->pages;
}
public function setPages(iterable $pages)
{
$this->pages = $pages;
}
public function addPages(iterable $pages)
{
foreach ($pages as $page) {
if (!$this->pages->contains($page)) {
$this->pages->add($page);
}
}
}
public function removePages(iterable $pages)
{
foreach ($pages as $page) {
$this->pages->removeElement($page);
}
}
public function getBrand(): ?Brand
{
return $this->brand;
}
public function setBrand(?Brand $brand): void
{
$this->brand = $brand;
}
public function getIsActive(): bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): void
{
$this->isActive = $isActive;
}
public function getItems(): iterable
{
return $this->items;
}
public function addItem(ProductItem $item)
{
$item->setProduct($this);
if (!$this->items->contains($item)) {
$this->items->add($item);
}
}
public function removeItem(ProductItem $item)
{
if ($this->items->contains($item)) {
$this->items->removeElement($item);
}
}
public function addItems(iterable $items)
{
foreach ($items as $item) {
$this->addItem($item);
}
}
public function removeItems(iterable $items)
{
foreach ($items as $item) {
$this->removeItem($item);
}
}
public function addImage(ProductImage $image)
{
$image->setProduct($this);
if (!$this->images->contains($image)) {
$this->images->add($image);
}
}
public function removeImage(ProductImage $image)
{
if ($this->items->contains($image)) {
$this->images->removeElement($image);
}
}
public function removeImages(iterable $images)
{
foreach ($images as $image) {
$this->removeImage($image);
}
}
public function addImages(iterable $images)
{
foreach ($images as $image) {
$this->addImage($image);
}
}
public function getImages(): iterable
{
return $this->images;
}
public function addDocument(ProductDocument $document)
{
$document->setProduct($this);
if (!$this->documents->contains($document)) {
$this->documents->add($document);
}
}
public function removeDocument(ProductDocument $document)
{
if ($this->documents->contains($document)) {
$this->documents->removeElement($document);
}
}
public function removeDocuments(iterable $documents)
{
foreach ($documents as $document) {
$this->removeDocument($document);
}
}
public function addDocuments(iterable $documents)
{
foreach ($documents as $document) {
$this->addDocument($document);
}
}
public function getDocuments(): iterable
{
return $this->documents;
}
public function getRelated(): iterable
{
return $this->related;
}
public function setRelated(iterable $related): void
{
$this->related = $related;
}
public function addRelated($related)
{
if (!$this->related->contains($related)) {
$this->related->add($related);
}
}
public function removeRelated($related): void
{
if ($this->related->contains($related)) {
$this->related->removeElement($related);
}
}
public function getSeoInfo(): iterable
{
return $this->seoInfo;
}
public function setSeoInfo(iterable $seoInfo): void
{
$this->seoInfo = $seoInfo;
}
public function getExtraFields(): ?array
{
return $this->extraFields;
}
public function setExtraFields(?array $extraFields): void
{
$this->extraFields = $extraFields;
}
}