bundles/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\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\Common\Collections\Criteria;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use MLDev\BaseBundle\Contract\SeoSite\SeoSiteInfoInterface;
  9. use MLDev\BaseBundle\Entity\Page;
  10. use MLDev\BaseBundle\Entity\Traits\Timestampable;
  11. use MLDev\CatalogBundle\Repository\ProductRepository;
  12. /**
  13.  * @ORM\Table(name="MLDev_Product")
  14.  * @ORM\Entity(repositoryClass=ProductRepository::class)
  15.  * @ORM\HasLifecycleCallbacks()
  16.  */
  17. class Product
  18. {
  19.     use Timestampable;
  20.     const ORDER_BY_NAME 'name';
  21.     const ORDER_BY_PRICE 'price';
  22.     const ORDER_BY_PRIORITY 'priority';
  23.     /**
  24.      * @ORM\Id
  25.      * @ORM\Column(name="id", type="integer")
  26.      * @ORM\GeneratedValue(strategy="AUTO")
  27.      */
  28.     private $id;
  29.     /**
  30.      * @ORM\Column(name="external_id", type="string", nullable=true)
  31.      */
  32.     private $externalId;
  33.     /**
  34.      * @ORM\Column(name="name", type="string", nullable=false)
  35.      */
  36.     private $name;
  37.     /**
  38.      * @ORM\Column(name="alter_name", type="string", nullable=true)
  39.      */
  40.     private $alterName;
  41.     /**
  42.      * @ORM\Column(name="type_prefix", type="string", nullable=true)
  43.      */
  44.     private $typePrefix;
  45.     /**
  46.      * @Gedmo\Slug(fields={"name"}, updatable=false, unique=true, separator="-")
  47.      * @ORM\Column(name="alias", type="string", length=255, nullable=false)
  48.      */
  49.     private $alias;
  50.     /**
  51.      * @ORM\Column(name="unit", type="string", nullable=true)
  52.      */
  53.     private $unit;
  54.     /**
  55.      * @ORM\Column(name="annotation", type="text", nullable=true)
  56.      */
  57.     private $annotation;
  58.     /**
  59.      * @ORM\Column(name="description", type="text", nullable=true)
  60.      */
  61.     private $description;
  62.     /**
  63.      * @ORM\Column(type="integer", name="priority", nullable=true)
  64.      */
  65.     private $priority 100;
  66.     /**
  67.      * @ORM\ManyToMany(targetEntity="MLDev\BaseBundle\Entity\Page", fetch="EXTRA_LAZY")
  68.      * @ORM\JoinTable(name="MLDev_Product_Page",
  69.      *      joinColumns={
  70.      *          @ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="CASCADE")
  71.      *      },
  72.      *      inverseJoinColumns={
  73.      *          @ORM\JoinColumn(name="page_id", referencedColumnName="id", onDelete="CASCADE")
  74.      *      }
  75.      *  )
  76.      */
  77.     private $pages;
  78.     /**
  79.      * @ORM\ManyToMany(targetEntity="MLDev\CatalogBundle\Entity\Product")
  80.      * @ORM\JoinTable(name="MLDev_Product_Related",
  81.      *      joinColumns={
  82.      *          @ORM\JoinColumn(name="main_id", referencedColumnName="id")
  83.      *      },
  84.      *      inverseJoinColumns={
  85.      *          @ORM\JoinColumn(name="linked_id", referencedColumnName="id")}
  86.      *      )
  87.      */
  88.     private $related;
  89.     /**
  90.      * @ORM\ManyToOne(targetEntity="MLDev\CatalogBundle\Entity\Brand", inversedBy="products")
  91.      * @ORM\JoinColumn(name="brand_id", referencedColumnName="id", onDelete="SET NULL")
  92.      */
  93.     private $brand;
  94.     /**
  95.      * @ORM\ManyToMany(targetEntity="MLDev\CatalogBundle\Entity\Skin")
  96.      * @ORM\JoinTable(name="MLDev_Product_To_Skin",
  97.      *      joinColumns={
  98.      *          @ORM\JoinColumn(name="product_id", referencedColumnName="id")
  99.      *      },
  100.      *      inverseJoinColumns={
  101.      *          @ORM\JoinColumn(name="skin_id", referencedColumnName="id")}
  102.      *      )
  103.      */
  104.     private $skin;
  105.     /**
  106.      * @ORM\ManyToMany(targetEntity="MLDev\CatalogBundle\Entity\SkinCondition")
  107.      * @ORM\JoinTable(name="MLDev_Product_To_SkinCondition",
  108.      *      joinColumns={
  109.      *          @ORM\JoinColumn(name="product_id", referencedColumnName="id")
  110.      *      },
  111.      *      inverseJoinColumns={
  112.      *          @ORM\JoinColumn(name="skin_condition_id", referencedColumnName="id")}
  113.      *      )
  114.      */
  115.     private $skinCondition;
  116.     /**
  117.      * @ORM\ManyToMany(targetEntity="MLDev\CatalogBundle\Entity\Aroma")
  118.      * @ORM\JoinTable(name="MLDev_Product_To_Aroma",
  119.      *      joinColumns={
  120.      *          @ORM\JoinColumn(name="product_id", referencedColumnName="id")
  121.      *      },
  122.      *      inverseJoinColumns={
  123.      *          @ORM\JoinColumn(name="aroma_id", referencedColumnName="id")}
  124.      *      )
  125.      */
  126.     private $aroma;
  127.     /**
  128.      * @ORM\ManyToMany(targetEntity="MLDev\CatalogBundle\Entity\Effect")
  129.      * @ORM\JoinTable(name="MLDev_Product_To_Effect",
  130.      *      joinColumns={
  131.      *          @ORM\JoinColumn(name="product_id", referencedColumnName="id")
  132.      *      },
  133.      *      inverseJoinColumns={
  134.      *          @ORM\JoinColumn(name="aroma_id", referencedColumnName="id")}
  135.      *      )
  136.      */
  137.     private $effect;
  138.     /**
  139.      * @ORM\ManyToMany(targetEntity="MLDev\CatalogBundle\Entity\Composition")
  140.      * @ORM\JoinTable(name="MLDev_Product_To_Composition",
  141.      *      joinColumns={
  142.      *          @ORM\JoinColumn(name="product_id", referencedColumnName="id")
  143.      *      },
  144.      *      inverseJoinColumns={
  145.      *          @ORM\JoinColumn(name="composition_id", referencedColumnName="id")}
  146.      *      )
  147.      */
  148.     private $composition;
  149.     /**
  150.      * @ORM\ManyToMany(targetEntity="MLDev\CatalogBundle\Entity\HairState")
  151.      * @ORM\JoinTable(name="MLDev_Product_To_HairState",
  152.      *      joinColumns={
  153.      *          @ORM\JoinColumn(name="product_id", referencedColumnName="id")
  154.      *      },
  155.      *      inverseJoinColumns={
  156.      *          @ORM\JoinColumn(name="hair_state_id", referencedColumnName="id")}
  157.      *      )
  158.      */
  159.     private $hairState;
  160.     /**
  161.      * @ORM\ManyToMany(targetEntity="MLDev\CatalogBundle\Entity\HairType")
  162.      * @ORM\JoinTable(name="MLDev_Product_To_HairType",
  163.      *      joinColumns={
  164.      *          @ORM\JoinColumn(name="product_id", referencedColumnName="id")
  165.      *      },
  166.      *      inverseJoinColumns={
  167.      *          @ORM\JoinColumn(name="hair_type_id", referencedColumnName="id")}
  168.      *      )
  169.      */
  170.     private $hairType;
  171.     /**
  172.      * @ORM\Column(name="is_active", type="boolean", nullable=false)
  173.      */
  174.     private $isActive true;
  175.     /**
  176.      * @ORM\OneToMany(targetEntity="MLDev\CatalogBundle\Entity\ProductItem", mappedBy="product", cascade={"persist", "remove"}, fetch="EXTRA_LAZY", orphanRemoval=true)
  177.      */
  178.     private $items;
  179.     /**
  180.      * @ORM\OneToMany(targetEntity="MLDev\CatalogBundle\Entity\ProductImage", mappedBy="product",  cascade={"persist", "remove"}, fetch="EXTRA_LAZY", orphanRemoval=true)
  181.      * @ORM\OrderBy({"priority": "ASC"})
  182.      */
  183.     private $images;
  184.     /**
  185.      * @ORM\OneToMany(targetEntity="MLDev\CatalogBundle\Entity\ProductDocument", mappedBy="product",  cascade={"persist", "remove"}, fetch="EXTRA_LAZY", orphanRemoval=true)
  186.      */
  187.     private $documents;
  188.     /**
  189.      * @ORM\ManyToMany(targetEntity=SeoSiteInfoInterface::class, cascade={"persist"})
  190.      * @ORM\JoinTable(
  191.      *     name="MLDev_Product_SeoInfo",
  192.      *     joinColumns={
  193.      *          @ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="CASCADE")
  194.      *     },
  195.      *     inverseJoinColumns={
  196.      *          @ORM\JoinColumn(name="seo_info_id", referencedColumnName="id", onDelete="CASCADE")
  197.      *     }
  198.      * )
  199.      */
  200.     private $seoInfo;
  201.     /**
  202.      * @ORM\Column(name="extra_fields", type="array", nullable=true)
  203.      */
  204.     private $extraFields = [];
  205.     /**
  206.      * @ORM\Column(name="articles", type="json", nullable=true)
  207.      */
  208.     private $articles = [];
  209.     /**
  210.      * @ORM\OneToMany(targetEntity=ProductContent::class, mappedBy="product", cascade={"persist"}, fetch="EXTRA_LAZY", orphanRemoval=true)
  211.      * @ORM\OrderBy({"priority" = "ASC", "id" = "ASC"})
  212.      */
  213.     private $productContents;
  214.     /**
  215.      * @ORM\Column(name="rating_score", type="float", nullable=true)
  216.      */
  217.     private $ratingScore;
  218.     /**
  219.      * @ORM\Column(name="reviews_count", type="integer", nullable=true)
  220.      */
  221.     private $reviewsCount;
  222.     public function __construct($page null)
  223.     {
  224.         $this->pages = new ArrayCollection();
  225.         $this->items = new ArrayCollection();
  226.         $this->images = new ArrayCollection();
  227.         $this->documents = new ArrayCollection();
  228.         $this->related = new ArrayCollection();
  229.         $this->skin = new ArrayCollection();
  230.         $this->skinCondition = new ArrayCollection();
  231.         $this->aroma = new ArrayCollection();
  232.         $this->effect = new ArrayCollection();
  233.         $this->composition = new ArrayCollection();
  234.         $this->hairState = new ArrayCollection();
  235.         $this->hairType = new ArrayCollection();
  236.         $this->seoInfo = new ArrayCollection();
  237.         $this->productContents = new ArrayCollection();
  238.         if ($page instanceof Page) {
  239.             $this->addPage($page);
  240.         }
  241.         $this->createdAt = new \DateTime();
  242.     }
  243.     public function getId(): ?int
  244.     {
  245.         return $this->id;
  246.     }
  247.     public function getExternalId(): ?string
  248.     {
  249.         return $this->externalId;
  250.     }
  251.     public function setExternalId(?string $externalId): void
  252.     {
  253.         $this->externalId $externalId;
  254.     }
  255.     public function getName(): ?string
  256.     {
  257.         return $this->name;
  258.     }
  259.     public function setName(?string $name)
  260.     {
  261.         $this->name $name;
  262.     }
  263.     public function getAlterName(): ?string
  264.     {
  265.         return $this->alterName;
  266.     }
  267.     public function setAlterName(?string $alterName): void
  268.     {
  269.         $this->alterName $alterName;
  270.     }
  271.     public function getTypePrefix()
  272.     {
  273.         return $this->typePrefix;
  274.     }
  275.     public function setTypePrefix($typePrefix): self
  276.     {
  277.         $this->typePrefix $typePrefix;
  278.         return $this;
  279.     }
  280.     public function getAlias(): ?string
  281.     {
  282.         return $this->alias;
  283.     }
  284.     public function setAlias(?string $alias): void
  285.     {
  286.         $this->alias $alias;
  287.     }
  288.     public function getUnit(): ?string
  289.     {
  290.         return $this->unit;
  291.     }
  292.     public function setUnit(?string $unit)
  293.     {
  294.         $this->unit $unit;
  295.     }
  296.     public function getAnnotation(): ?string
  297.     {
  298.         return $this->annotation;
  299.     }
  300.     public function setAnnotation(?string $annotation)
  301.     {
  302.         $this->annotation $annotation;
  303.     }
  304.     public function getDescription(): ?string
  305.     {
  306.         return $this->description;
  307.     }
  308.     public function setDescription(?string $description)
  309.     {
  310.         $this->description $description;
  311.     }
  312.     public function getPriority(): ?int
  313.     {
  314.         return $this->priority;
  315.     }
  316.     public function setPriority(?int $priority): void
  317.     {
  318.         $this->priority $priority;
  319.     }
  320.     public function addPage(Page $page): self
  321.     {
  322.         $this->pages->add($page);
  323.         return $this;
  324.     }
  325.     public function removePage(Page $page)
  326.     {
  327.         $this->pages->removeElement($page);
  328.     }
  329.     public function getPages(): iterable
  330.     {
  331.         return $this->pages;
  332.     }
  333.     public function setPages(iterable $pages)
  334.     {
  335.         $this->pages $pages;
  336.     }
  337.     public function addPages(iterable $pages)
  338.     {
  339.         foreach ($pages as $page) {
  340.             if (!$this->pages->contains($page)) {
  341.                 $this->pages->add($page);
  342.             }
  343.         }
  344.     }
  345.     public function removePages(iterable $pages)
  346.     {
  347.         foreach ($pages as $page) {
  348.             $this->pages->removeElement($page);
  349.         }
  350.     }
  351.     public function getBrand(): ?Brand
  352.     {
  353.         return $this->brand;
  354.     }
  355.     public function setBrand(?Brand $brand): void
  356.     {
  357.         $this->brand $brand;
  358.     }
  359.     public function getIsActive(): bool
  360.     {
  361.         return $this->isActive;
  362.     }
  363.     public function setIsActive(bool $isActive): void
  364.     {
  365.         $this->isActive $isActive;
  366.     }
  367.     public function getItems(): iterable
  368.     {
  369.         return $this->items;
  370.     }
  371.     public function addItem(ProductItem $item)
  372.     {
  373.         $item->setProduct($this);
  374.         if (!$this->items->contains($item)) {
  375.             $this->items->add($item);
  376.         }
  377.     }
  378.     public function removeItem(ProductItem $item)
  379.     {
  380.         if ($this->items->contains($item)) {
  381.             $this->items->removeElement($item);
  382.         }
  383.     }
  384.     public function addItems(iterable $items)
  385.     {
  386.         foreach ($items as $item) {
  387.             $this->addItem($item);
  388.         }
  389.     }
  390.     public function removeItems(iterable $items)
  391.     {
  392.         foreach ($items as $item) {
  393.             $this->removeItem($item);
  394.         }
  395.     }
  396.     public function addImage(ProductImage $image)
  397.     {
  398.         $image->setProduct($this);
  399.         if (!$this->images->contains($image)) {
  400.             $this->images->add($image);
  401.         }
  402.     }
  403.     public function removeImage(ProductImage $image)
  404.     {
  405.         if ($this->items->contains($image)) {
  406.             $this->images->removeElement($image);
  407.         }
  408.     }
  409.     public function removeImages(iterable $images)
  410.     {
  411.         foreach ($images as $image) {
  412.             $this->removeImage($image);
  413.         }
  414.     }
  415.     public function addImages(iterable $images)
  416.     {
  417.         foreach ($images as $image) {
  418.             $this->addImage($image);
  419.         }
  420.     }
  421.     public function getImages(): iterable
  422.     {
  423.         return $this->images;
  424.     }
  425.     public function addDocument(ProductDocument $document)
  426.     {
  427.         $document->setProduct($this);
  428.         if (!$this->documents->contains($document)) {
  429.             $this->documents->add($document);
  430.         }
  431.     }
  432.     public function removeDocument(ProductDocument $document)
  433.     {
  434.         if ($this->documents->contains($document)) {
  435.             $this->documents->removeElement($document);
  436.         }
  437.     }
  438.     public function removeDocuments(iterable $documents)
  439.     {
  440.         foreach ($documents as $document) {
  441.             $this->removeDocument($document);
  442.         }
  443.     }
  444.     public function addDocuments(iterable $documents)
  445.     {
  446.         foreach ($documents as $document) {
  447.             $this->addDocument($document);
  448.         }
  449.     }
  450.     public function getDocuments(): iterable
  451.     {
  452.         return $this->documents;
  453.     }
  454.     public function getRelated(): iterable
  455.     {
  456.         return $this->related;
  457.     }
  458.     public function setRelated(iterable $related): void
  459.     {
  460.         $this->related $related;
  461.     }
  462.     public function addRelated($related)
  463.     {
  464.         if (!$this->related->contains($related)) {
  465.             $this->related->add($related);
  466.         }
  467.     }
  468.     public function removeRelated($related): void
  469.     {
  470.         if ($this->related->contains($related)) {
  471.             $this->related->removeElement($related);
  472.         }
  473.     }
  474.     public function getSkin()
  475.     {
  476.         return $this->skin;
  477.     }
  478.     public function setSkin($skin): self
  479.     {
  480.         $this->skin $skin;
  481.         return $this;
  482.     }
  483.     public function getComposition()
  484.     {
  485.         return $this->composition;
  486.     }
  487.     public function setComposition($composition): self
  488.     {
  489.         $this->composition $composition;
  490.         return $this;
  491.     }
  492.     public function getSeoInfo(): iterable
  493.     {
  494.         return $this->seoInfo;
  495.     }
  496.     public function setSeoInfo(iterable $seoInfo): void
  497.     {
  498.         $this->seoInfo $seoInfo;
  499.     }
  500.     public function getExtraFields(): ?array
  501.     {
  502.         return $this->extraFields;
  503.     }
  504.     public function setExtraFields(?array $extraFields): void
  505.     {
  506.         $this->extraFields $extraFields;
  507.     }
  508.     public function getArticles(): ?array
  509.     {
  510.         return $this->articles;
  511.     }
  512.     public function setArticles(?array $articles): self
  513.     {
  514.         $this->articles $articles;
  515.         return $this;
  516.     }
  517.     /**
  518.      * @return ArrayCollection
  519.      */
  520.     public function getProductContents(): Collection
  521.     {
  522.         return $this->productContents;
  523.     }
  524.     /**
  525.      * @param $productContents
  526.      * @return $this
  527.      */
  528.     public function addProductContents($productContents): self
  529.     {
  530.         foreach ($productContents as $productContent) {
  531.             if (!$this->productContents->contains($productContent)) {
  532.                 $this->productContents->add($productContent);
  533.             }
  534.         }
  535.         return $this;
  536.     }
  537.     /**
  538.      * @param ProductContent $productContent
  539.      * @return Product
  540.      */
  541.     public function addProductContent(ProductContent $productContent): self
  542.     {
  543.         $this->productContents[] = $productContent;
  544.         return $this;
  545.     }
  546.     /**
  547.      * @param $productContents
  548.      * @return Product
  549.      */
  550.     public function removeProductContents($productContents): self
  551.     {
  552.         foreach ($productContents as $productContent) {
  553.             $this->productContents->removeElement($productContent);
  554.         }
  555.         return $this;
  556.     }
  557.     /**
  558.      * @param ProductContent $productContent
  559.      * @return Product
  560.      */
  561.     public function removeProductContent(ProductContent $productContent): self
  562.     {
  563.         $this->productContents->removeElement($productContent);
  564.         return $this;
  565.     }
  566.     /**
  567.      * @return ArrayCollection|Collection
  568.      */
  569.     public function getWidgets()
  570.     {
  571.         $criteria Criteria::create()->where(
  572.             Criteria::expr()->eq('isActive'true)
  573.         );
  574.         $criteria->orderBy([
  575.             'priority' => Criteria::ASC,
  576.             'id' => Criteria::ASC,
  577.         ]);
  578.         return $this->getProductContents()->matching($criteria);
  579.     }
  580.     public function getRatingScore()
  581.     {
  582.         return $this->ratingScore;
  583.     }
  584.     public function setRatingScore($ratingScore): self
  585.     {
  586.         $this->ratingScore $ratingScore;
  587.         return $this;
  588.     }
  589.     public function getReviewsCount()
  590.     {
  591.         return $this->reviewsCount;
  592.     }
  593.     public function setReviewsCount($reviewsCount): self
  594.     {
  595.         $this->reviewsCount $reviewsCount;
  596.         return $this;
  597.     }
  598.     public function getSkinCondition(): Collection
  599.     {
  600.         return $this->skinCondition;
  601.     }
  602.     public function setSkinCondition($skinCondition): self
  603.     {
  604.         $this->skinCondition $skinCondition;
  605.         return $this;
  606.     }
  607.     public function getAroma(): Collection
  608.     {
  609.         return $this->aroma;
  610.     }
  611.     public function setAroma($aroma): self
  612.     {
  613.         $this->aroma $aroma;
  614.         return $this;
  615.     }
  616.     public function getEffect(): Collection
  617.     {
  618.         return $this->effect;
  619.     }
  620.     public function setEffect($effect): self
  621.     {
  622.         $this->effect $effect;
  623.         return $this;
  624.     }
  625.     public function getHairState(): Collection
  626.     {
  627.         return $this->hairState;
  628.     }
  629.     public function setHairState($hairState): self
  630.     {
  631.         $this->hairState $hairState;
  632.         return $this;
  633.     }
  634.     public function getHairType(): Collection
  635.     {
  636.         return $this->hairType;
  637.     }
  638.     public function setHairType($hairType): self
  639.     {
  640.         $this->hairType $hairType;
  641.         return $this;
  642.     }
  643. }