vendor/fri0z/mldev-catalog-bundle/src/Entity/Product.php line 20

Open in your IDE?
  1. <?php
  2. namespace MLDev\CatalogBundle\Entity;
  3. use Doctrine\Common\Collections\Collection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use MLDev\BaseBundle\Contract\SeoSite\SeoSiteInfoInterface;
  8. use MLDev\BaseBundle\Entity\Page;
  9. use MLDev\BaseBundle\Entity\Traits\Timestampable;
  10. use MLDev\CatalogBundle\Repository\ProductRepository;
  11. /**
  12.  * @ORM\Table(name="MLDev_Product")
  13.  * @ORM\Entity(repositoryClass=ProductRepository::class)
  14.  * @ORM\HasLifecycleCallbacks()
  15.  */
  16. class Product
  17. {
  18.     use Timestampable;
  19.     const ORDER_BY_NAME 'name';
  20.     const ORDER_BY_PRICE 'price';
  21.     const ORDER_BY_PRIORITY 'priority';
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\Column(name="id", type="integer")
  25.      * @ORM\GeneratedValue(strategy="AUTO")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(name="external_id", type="string", nullable=true)
  30.      */
  31.     private $externalId;
  32.     /**
  33.      * @ORM\Column(name="name", type="string", nullable=false)
  34.      */
  35.     private $name;
  36.     /**
  37.      * @ORM\Column(name="alter_name", type="string", nullable=true)
  38.      */
  39.     private $alterName;
  40.     /**
  41.      * @Gedmo\Slug(fields={"name"}, updatable=false, unique=true, separator="-")
  42.      * @ORM\Column(name="alias", type="string", length=255, nullable=false)
  43.      */
  44.     private $alias;
  45.     /**
  46.      * @ORM\Column(name="unit", type="string", nullable=true)
  47.      */
  48.     private $unit;
  49.     /**
  50.      * @ORM\Column(name="annotation", type="text", nullable=true)
  51.      */
  52.     private $annotation;
  53.     /**
  54.      * @ORM\Column(name="description", type="text", nullable=true)
  55.      */
  56.     private $description;
  57.     /**
  58.      * @ORM\Column(type="integer", name="priority", nullable=true)
  59.      */
  60.     private $priority 100;
  61.     /**
  62.      * @ORM\ManyToMany(targetEntity="MLDev\BaseBundle\Entity\Page", fetch="EXTRA_LAZY")
  63.      * @ORM\JoinTable(name="MLDev_Product_Page",
  64.      *      joinColumns={
  65.      *          @ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="CASCADE")
  66.      *      },
  67.      *      inverseJoinColumns={
  68.      *          @ORM\JoinColumn(name="page_id", referencedColumnName="id", onDelete="CASCADE")
  69.      *      }
  70.      *  )
  71.      */
  72.     private $pages;
  73.     /**
  74.      * @ORM\ManyToMany(targetEntity="MLDev\CatalogBundle\Entity\Product")
  75.      * @ORM\JoinTable(name="MLDev_Product_Related",
  76.      *      joinColumns={
  77.      *          @ORM\JoinColumn(name="main_id", referencedColumnName="id")
  78.      *      },
  79.      *      inverseJoinColumns={
  80.      *          @ORM\JoinColumn(name="linked_id", referencedColumnName="id")}
  81.      *      )
  82.      */
  83.     private $related;
  84.     /**
  85.      * @ORM\ManyToOne(targetEntity="MLDev\CatalogBundle\Entity\Brand", inversedBy="products")
  86.      * @ORM\JoinColumn(name="brand_id", referencedColumnName="id", onDelete="SET NULL")
  87.      */
  88.     private $brand;
  89.     /**
  90.      * @ORM\Column(name="is_active", type="boolean", nullable=false)
  91.      */
  92.     private $isActive true;
  93.     /**
  94.      * @ORM\OneToMany(targetEntity="MLDev\CatalogBundle\Entity\ProductItem", mappedBy="product", cascade={"persist", "remove"}, fetch="EXTRA_LAZY", orphanRemoval=true)
  95.      */
  96.     private $items;
  97.     /**
  98.      * @ORM\OneToMany(targetEntity="MLDev\CatalogBundle\Entity\ProductImage", mappedBy="product",  cascade={"persist", "remove"}, fetch="EXTRA_LAZY", orphanRemoval=true)
  99.      */
  100.     private $images;
  101.     /**
  102.      * @ORM\OneToMany(targetEntity="MLDev\CatalogBundle\Entity\ProductDocument", mappedBy="product",  cascade={"persist", "remove"}, fetch="EXTRA_LAZY", orphanRemoval=true)
  103.      */
  104.     private $documents;
  105.     /**
  106.      * @ORM\ManyToMany(targetEntity=SeoSiteInfoInterface::class, cascade={"persist"})
  107.      * @ORM\JoinTable(
  108.      *     name="MLDev_Product_SeoInfo",
  109.      *     joinColumns={
  110.      *          @ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="CASCADE")
  111.      *     },
  112.      *     inverseJoinColumns={
  113.      *          @ORM\JoinColumn(name="seo_info_id", referencedColumnName="id", onDelete="CASCADE")
  114.      *     }
  115.      * )
  116.      */
  117.     private $seoInfo;
  118.     /**
  119.      * @ORM\Column(name="extra_fields", type="array", nullable=true)
  120.      */
  121.     private $extraFields = [];
  122.     public function __construct($page null)
  123.     {
  124.         $this->pages = new ArrayCollection();
  125.         $this->items = new ArrayCollection();
  126.         $this->images = new ArrayCollection();
  127.         $this->documents = new ArrayCollection();
  128.         $this->related = new ArrayCollection();
  129.         $this->seoInfo = new ArrayCollection();
  130.         if ($page instanceof Page) {
  131.             $this->addPage($page);
  132.         }
  133.         $this->createdAt = new \DateTime();
  134.     }
  135.     public function getId(): ?int
  136.     {
  137.         return $this->id;
  138.     }
  139.     public function getExternalId(): ?string
  140.     {
  141.         return $this->externalId;
  142.     }
  143.     public function setExternalId(?string $externalId): void
  144.     {
  145.         $this->externalId $externalId;
  146.     }
  147.     public function getName(): ?string
  148.     {
  149.         return $this->name;
  150.     }
  151.     public function setName(?string $name)
  152.     {
  153.         $this->name $name;
  154.     }
  155.     public function getAlterName(): ?string
  156.     {
  157.         return $this->alterName;
  158.     }
  159.     public function setAlterName(?string $alterName): void
  160.     {
  161.         $this->alterName $alterName;
  162.     }
  163.     public function getAlias(): ?string
  164.     {
  165.         return $this->alias;
  166.     }
  167.     public function setAlias(?string $alias): void
  168.     {
  169.         $this->alias $alias;
  170.     }
  171.     public function getUnit(): ?string
  172.     {
  173.         return $this->unit;
  174.     }
  175.     public function setUnit(?string $unit)
  176.     {
  177.         $this->unit $unit;
  178.     }
  179.     public function getAnnotation(): ?string
  180.     {
  181.         return $this->annotation;
  182.     }
  183.     public function setAnnotation(?string $annotation)
  184.     {
  185.         $this->annotation $annotation;
  186.     }
  187.     public function getDescription(): ?string
  188.     {
  189.         return $this->description;
  190.     }
  191.     public function setDescription(?string $description)
  192.     {
  193.         $this->description $description;
  194.     }
  195.     public function getPriority(): ?int
  196.     {
  197.         return $this->priority;
  198.     }
  199.     public function setPriority(?int $priority): void
  200.     {
  201.         $this->priority $priority;
  202.     }
  203.     public function addPage(Page $page): self
  204.     {
  205.         $this->pages->add($page);
  206.         return $this;
  207.     }
  208.     public function removePage(Page $page)
  209.     {
  210.         $this->pages->removeElement($page);
  211.     }
  212.     public function getPages(): iterable
  213.     {
  214.         return $this->pages;
  215.     }
  216.     public function setPages(iterable $pages)
  217.     {
  218.         $this->pages $pages;
  219.     }
  220.     public function addPages(iterable $pages)
  221.     {
  222.         foreach ($pages as $page) {
  223.             if (!$this->pages->contains($page)) {
  224.                 $this->pages->add($page);
  225.             }
  226.         }
  227.     }
  228.     public function removePages(iterable $pages)
  229.     {
  230.         foreach ($pages as $page) {
  231.             $this->pages->removeElement($page);
  232.         }
  233.     }
  234.     public function getBrand(): ?Brand
  235.     {
  236.         return $this->brand;
  237.     }
  238.     public function setBrand(?Brand $brand): void
  239.     {
  240.         $this->brand $brand;
  241.     }
  242.     public function getIsActive(): bool
  243.     {
  244.         return $this->isActive;
  245.     }
  246.     public function setIsActive(bool $isActive): void
  247.     {
  248.         $this->isActive $isActive;
  249.     }
  250.     public function getItems(): iterable
  251.     {
  252.         return $this->items;
  253.     }
  254.     public function addItem(ProductItem $item)
  255.     {
  256.         $item->setProduct($this);
  257.         if (!$this->items->contains($item)) {
  258.             $this->items->add($item);
  259.         }
  260.     }
  261.     public function removeItem(ProductItem $item)
  262.     {
  263.         if ($this->items->contains($item)) {
  264.             $this->items->removeElement($item);
  265.         }
  266.     }
  267.     public function addItems(iterable $items)
  268.     {
  269.         foreach ($items as $item) {
  270.             $this->addItem($item);
  271.         }
  272.     }
  273.     public function removeItems(iterable $items)
  274.     {
  275.         foreach ($items as $item) {
  276.             $this->removeItem($item);
  277.         }
  278.     }
  279.     public function addImage(ProductImage $image)
  280.     {
  281.         $image->setProduct($this);
  282.         if (!$this->images->contains($image)) {
  283.             $this->images->add($image);
  284.         }
  285.     }
  286.     public function removeImage(ProductImage $image)
  287.     {
  288.         if ($this->items->contains($image)) {
  289.             $this->images->removeElement($image);
  290.         }
  291.     }
  292.     public function removeImages(iterable $images)
  293.     {
  294.         foreach ($images as $image) {
  295.             $this->removeImage($image);
  296.         }
  297.     }
  298.     public function addImages(iterable $images)
  299.     {
  300.         foreach ($images as $image) {
  301.             $this->addImage($image);
  302.         }
  303.     }
  304.     public function getImages(): iterable
  305.     {
  306.         return $this->images;
  307.     }
  308.     public function addDocument(ProductDocument $document)
  309.     {
  310.         $document->setProduct($this);
  311.         if (!$this->documents->contains($document)) {
  312.             $this->documents->add($document);
  313.         }
  314.     }
  315.     public function removeDocument(ProductDocument $document)
  316.     {
  317.         if ($this->documents->contains($document)) {
  318.             $this->documents->removeElement($document);
  319.         }
  320.     }
  321.     public function removeDocuments(iterable $documents)
  322.     {
  323.         foreach ($documents as $document) {
  324.             $this->removeDocument($document);
  325.         }
  326.     }
  327.     public function addDocuments(iterable $documents)
  328.     {
  329.         foreach ($documents as $document) {
  330.             $this->addDocument($document);
  331.         }
  332.     }
  333.     public function getDocuments(): iterable
  334.     {
  335.         return $this->documents;
  336.     }
  337.     public function getRelated(): iterable
  338.     {
  339.         return $this->related;
  340.     }
  341.     public function setRelated(iterable $related): void
  342.     {
  343.         $this->related $related;
  344.     }
  345.     public function addRelated($related)
  346.     {
  347.         if (!$this->related->contains($related)) {
  348.             $this->related->add($related);
  349.         }
  350.     }
  351.     public function removeRelated($related): void
  352.     {
  353.         if ($this->related->contains($related)) {
  354.             $this->related->removeElement($related);
  355.         }
  356.     }
  357.     public function getSeoInfo(): iterable
  358.     {
  359.         return $this->seoInfo;
  360.     }
  361.     public function setSeoInfo(iterable $seoInfo): void
  362.     {
  363.         $this->seoInfo $seoInfo;
  364.     }
  365.     public function getExtraFields(): ?array
  366.     {
  367.         return $this->extraFields;
  368.     }
  369.     public function setExtraFields(?array $extraFields): void
  370.     {
  371.         $this->extraFields $extraFields;
  372.     }
  373. }