src/Entity/Gos/ProductVariantPack.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. /**
  8.  * @ORM\HasLifecycleCallbacks()
  9.  * @ORM\Entity(repositoryClass="App\Repository\Gos\ProductVariantPackRepository")
  10.  */
  11. class ProductVariantPack
  12. {
  13.     /**
  14.      * @ORM\Id()
  15.      * @ORM\GeneratedValue()
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @Gedmo\Slug(fields={"name"})
  25.      * @ORM\Column(type="string", length=255)
  26.      */
  27.     private $slug;
  28.     /**
  29.      * @ORM\ManyToMany(targetEntity="ProductVariant", inversedBy="productVariantPacks")
  30.      * @ORM\JoinTable(name="product_variant_in_pack")
  31.      */
  32.     private $productVariants;
  33.     /**
  34.      * @ORM\ManyToMany(targetEntity="Coupon", mappedBy="productVariantPacks")
  35.      */
  36.     private $coupons;
  37.     /**
  38.      * @ORM\Column(type="datetime")
  39.      */
  40.     private $createdAt;
  41.     /**
  42.      * @ORM\Column(type="datetime", nullable=true)
  43.      */
  44.     private $updatedAt;
  45.     /**
  46.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\Country", inversedBy="productVariantPacks")
  47.      */
  48.     private $countries;
  49.     /**
  50.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\PortalSettings", inversedBy="productVariantPacks")
  51.      */
  52.     private $portalSettings;
  53.     /**
  54.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\ClientType", inversedBy="productVariantPacks")
  55.      */
  56.     private $clientTypes;
  57.     /**
  58.      * @ORM\Column(type="boolean", nullable=false, options={"default": false})
  59.      */
  60.     private $autoUpdate false;
  61.     public function __construct()
  62.     {
  63.         $this->productVariants = new ArrayCollection();
  64.         $this->coupons = new ArrayCollection();
  65.         $this->countries = new ArrayCollection();
  66.         $this->portalSettings = new ArrayCollection();
  67.         $this->clientTypes = new ArrayCollection();
  68.     }
  69.     /** @ORM\PrePersist() */
  70.     public function onPrePersist()
  71.     {
  72.         $this->createdAt = new \DateTime();
  73.     }
  74.     /** @ORM\PreUpdate() */
  75.     public function onPreUpdate()
  76.     {
  77.         $this->updatedAt = new \DateTime();
  78.     }
  79.     public function __toString()
  80.     {
  81.         return $this->getName();
  82.     }
  83.     public function getId(): ?int
  84.     {
  85.         return $this->id;
  86.     }
  87.     public function getName(): ?string
  88.     {
  89.         return $this->name;
  90.     }
  91.     public function setName(string $name): self
  92.     {
  93.         $this->name $name;
  94.         return $this;
  95.     }
  96.     public function getSlug(): ?string
  97.     {
  98.         return $this->slug;
  99.     }
  100.     public function setSlug(string $slug): self
  101.     {
  102.         $this->slug $slug;
  103.         return $this;
  104.     }
  105.     public function getCreatedAt(): ?\DateTimeInterface
  106.     {
  107.         return $this->createdAt;
  108.     }
  109.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  110.     {
  111.         $this->createdAt $createdAt;
  112.         return $this;
  113.     }
  114.     public function getUpdatedAt(): ?\DateTimeInterface
  115.     {
  116.         return $this->updatedAt;
  117.     }
  118.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  119.     {
  120.         $this->updatedAt $updatedAt;
  121.         return $this;
  122.     }
  123.     /**
  124.      * @return Collection|ProductVariant[]
  125.      */
  126.     public function getProductVariants(): Collection
  127.     {
  128.         return $this->productVariants;
  129.     }
  130.     public function addProductVariant(ProductVariant $productVariant): self
  131.     {
  132.         if (!$this->productVariants->contains($productVariant)) {
  133.             $this->productVariants[] = $productVariant;
  134.             $productVariant->addProductVariantPack($this);
  135.         }
  136.         return $this;
  137.     }
  138.     public function removeProductVariant(ProductVariant $productVariant): self
  139.     {
  140.         if ($this->productVariants->contains($productVariant)) {
  141.             $this->productVariants->removeElement($productVariant);
  142.             $productVariant->removeProductVariantPack($this);
  143.         }
  144.         return $this;
  145.     }
  146.     /**
  147.      * @return Collection|Coupon[]
  148.      */
  149.     public function getCoupons(): Collection
  150.     {
  151.         return $this->coupons;
  152.     }
  153.     public function addCoupon(Coupon $coupon): self
  154.     {
  155.         if (!$this->coupons->contains($coupon)) {
  156.             $this->coupons[] = $coupon;
  157.             $coupon->addProductVariantPack($this);
  158.         }
  159.         return $this;
  160.     }
  161.     public function removeCoupon(Coupon $coupon): self
  162.     {
  163.         if ($this->coupons->contains($coupon)) {
  164.             $this->coupons->removeElement($coupon);
  165.             $coupon->removeProductVariantPack($this);
  166.         }
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection|Country[]
  171.      */
  172.     public function getCountries(): Collection
  173.     {
  174.         return $this->countries;
  175.     }
  176.     public function addCountry(Country $country): self
  177.     {
  178.         if (!$this->countries->contains($country)) {
  179.             $this->countries[] = $country;
  180.         }
  181.         return $this;
  182.     }
  183.     public function removeCountry(Country $country): self
  184.     {
  185.         if ($this->countries->contains($country)) {
  186.             $this->countries->removeElement($country);
  187.         }
  188.         return $this;
  189.     }
  190.     /**
  191.      * @return Collection|PortalSettings[]
  192.      */
  193.     public function getPortalSettings(): Collection
  194.     {
  195.         return $this->portalSettings;
  196.     }
  197.     public function addPortalSetting(PortalSettings $portalSetting): self
  198.     {
  199.         if (!$this->portalSettings->contains($portalSetting)) {
  200.             $this->portalSettings[] = $portalSetting;
  201.         }
  202.         return $this;
  203.     }
  204.     public function removePortalSetting(PortalSettings $portalSetting): self
  205.     {
  206.         if ($this->portalSettings->contains($portalSetting)) {
  207.             $this->portalSettings->removeElement($portalSetting);
  208.         }
  209.         return $this;
  210.     }
  211.     /**
  212.      * @return Collection|ClientType[]
  213.      */
  214.     public function getClientTypes(): Collection
  215.     {
  216.         return $this->clientTypes;
  217.     }
  218.     public function addClientType(ClientType $clientType): self
  219.     {
  220.         if (!$this->clientTypes->contains($clientType)) {
  221.             $this->clientTypes[] = $clientType;
  222.         }
  223.         return $this;
  224.     }
  225.     public function removeClientType(ClientType $clientType): self
  226.     {
  227.         if ($this->clientTypes->contains($clientType)) {
  228.             $this->clientTypes->removeElement($clientType);
  229.         }
  230.         return $this;
  231.     }
  232.     /**
  233.      * Returns an array of all unique masterProductsIds for the given productVariantPack
  234.      *
  235.      * @return array
  236.      */
  237.     public function getMasterProductsIds(): array
  238.     {
  239.         $masterProducts = new ArrayCollection();
  240.         foreach ($this->getProductVariants() as $productVariant)
  241.         {
  242.             if (!$masterProducts->contains($productVariant->getMasterProduct()->getId()))
  243.             {
  244.                 $masterProducts->add($productVariant->getMasterProduct()->getId());
  245.             }
  246.         }
  247.         return $masterProducts->toArray();
  248.     }
  249.     public function getAutoUpdate(): ?bool
  250.     {
  251.         return $this->autoUpdate;
  252.     }
  253.     public function setAutoUpdate(bool $autoUpdate): self
  254.     {
  255.         $this->autoUpdate $autoUpdate;
  256.         return $this;
  257.     }
  258. }