src/Entity/Gos/ProductPack.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use App\Entity\Gos\Uniqskills\OrderCycle;
  4. use App\Entity\Gos\ProductPackMultiDiscount;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\Gos\ProductPackRepository")
  10.  * @ORM\HasLifecycleCallbacks
  11.  */
  12. class ProductPack
  13. {
  14.     /**
  15.      * @ORM\Id()
  16.      * @ORM\GeneratedValue()
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=255)
  22.      */
  23.     private $name;
  24.     /**
  25.      * @var string
  26.      *
  27.      * @ORM\Column(type="text", nullable=true)
  28.      */
  29.     private $label;
  30.     /**
  31.      * @ORM\Column(type="boolean", nullable=true)
  32.      */
  33.     private $isActive;
  34.     /**
  35.      * @ORM\Column(type="boolean", nullable=true)
  36.      */
  37.     private $showPrice;
  38.     /**
  39.      * @var bool
  40.      *
  41.      * @ORM\Column(type="boolean", nullable=true)
  42.      */
  43.     private $buyMaxOne;
  44.     /**
  45.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\ProductPackItem", mappedBy="productPack", cascade={"persist"})
  46.      */
  47.     private $productPackItem;
  48.     /**
  49.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\ProductCart", mappedBy="productPack")
  50.      */
  51.     private $productCart;
  52.     /**
  53.      * @ORM\Column(type="datetime")
  54.      */
  55.     private $createdAt;
  56.     /**
  57.      * @ORM\Column(type="datetime", nullable=true)
  58.      */
  59.     private $updatedAt;
  60.     /**
  61.      * @ORM\Column(type="integer", nullable=true)
  62.      */
  63.     private $grossShow;
  64.     /**
  65.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\ProductPackType")
  66.      */
  67.     private $type;
  68.     /**
  69.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\Uniqskills\OrderCycle", mappedBy="cyclePack")
  70.      */
  71.     private $orderCycles;
  72.     /**
  73.      * @ORM\Column(type="boolean", nullable=true)
  74.      */
  75.     private $isPubliclyAvailable;
  76.     /**
  77.      * @ORM\Column(type="date", nullable=true)
  78.      */
  79.     private $publiclyAvailableDateFrom;
  80.     /**
  81.      * @ORM\Column(type="date", nullable=true)
  82.      */
  83.     private $publiclyAvailableDateTo;
  84.     /**
  85.      * @ORM\OneToMany(targetEntity=ProductPackMultiDiscount::class, mappedBy="productPack", orphanRemoval=true, cascade={"persist"})
  86.      */
  87.     private $multiDiscounts;
  88.     /**
  89.      * @ORM\Column(type="text", nullable=true)
  90.      */
  91.     private $customPromo1;
  92.     /**
  93.      * @ORM\Column(type="text", nullable=true)
  94.      */
  95.     private $customPromo2;
  96.     /**
  97.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\Coupon", mappedBy="productPack")
  98.      */
  99.     private $coupon;
  100.     /**
  101.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\Omnibus", mappedBy="productPack", orphanRemoval=true, cascade={"persist"})
  102.      */
  103.     private $omnibus;
  104.     /**
  105.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\Events", inversedBy="productPacks")
  106.      */
  107.     private $event;
  108.     /**
  109.      * ProductPack constructor.
  110.      */
  111.     public function __construct()
  112.     {
  113.         $this->productPackItem = new ArrayCollection();
  114.         $this->productCart     = new ArrayCollection();
  115.         $this->orderCycles     = new ArrayCollection();
  116.         $this->multiDiscounts  = new ArrayCollection();
  117.         $this->coupon          = new ArrayCollection();
  118.         $this->omnibus         = new ArrayCollection();
  119.     }
  120.     /** @ORM\PrePersist() */
  121.     public function prePersist()
  122.     {
  123.         $this->createdAt = new \DateTime();
  124.     }
  125.     /** @ORM\PreUpdate() */
  126.     public function preUpdate()
  127.     {
  128.         $this->updatedAt = new \DateTime();
  129.     }
  130.     public function __toString()
  131.     {
  132.         return $this->name;
  133.     }
  134.     public function isActive()
  135.     {
  136.         if (!$this->getIsActive())
  137.         {
  138.             return false;
  139.         }
  140.         if (!$this->getProductPackItem()->isEmpty())
  141.         {
  142.             foreach ($this->getProductPackItem() as $productPackItem)
  143.             {
  144.                 /** @var ProductPackItem $productPackItem */
  145.                 if (!$productPackItem->getProductVariant()->isActive())
  146.                 {
  147.                     return false;
  148.                 }
  149.             }
  150.         }
  151.         return true;
  152.     }
  153.     /**
  154.      * Return productPackItem when has event product
  155.      * @return array
  156.      */
  157.     public function getEventProductPackItem()
  158.     {
  159.         $productsPackItem = array();
  160.         if (!$this->getProductPackItem()->isEmpty())
  161.         {
  162.             foreach ($this->getProductPackItem() as $productPackItem)
  163.             {
  164.                 /** @var ProductPackItem $productPackItem */
  165.                 if ($productPackItem->getProductVariant()->isEvent())
  166.                 {
  167.                     $productsPackItem[] = $productPackItem;
  168.                 }
  169.             }
  170.         }
  171.         return $productsPackItem;
  172.     }
  173.     public function getFirstNonVirtualItem(): ?ProductPackItem
  174.     {
  175.         foreach ($this->getProductPackItem() as $productPackItem)
  176.         {
  177.             if (!$productPackItem->getProductVariant()->getIsVirtual())
  178.             {
  179.                 return $productPackItem;
  180.             }
  181.         }
  182.         return null;
  183.     }
  184.     public function hasPhysicalVariant(): bool
  185.     {
  186.         foreach ($this->getProductPackItem() as $productPackItem)
  187.         {
  188.             if ($productPackItem->getProductVariant()->isPhysical())
  189.             {
  190.                 return true;
  191.             }
  192.         }
  193.         return false;
  194.     }
  195.     public function askForPWZ(): bool
  196.     {
  197.         if (!$this->getProductPackItem()->isEmpty())
  198.         {
  199.             foreach ($this->getProductPackItem() as $productPackItem)
  200.             {
  201.                 /** @var ProductPackItem $productPackItem */
  202.                 if ($productPackItem->getProductVariant()->getRequiredPWZ())
  203.                 {
  204.                     return true;
  205.                 }
  206.             }
  207.         }
  208.         return false;
  209.     }
  210.     public function isNPWZRequired(): bool
  211.     {
  212.         if (!$this->getProductPackItem()->isEmpty())
  213.         {
  214.             foreach ($this->getProductPackItem() as $productPackItem)
  215.             {
  216.                 /** @var ProductPackItem $productPackItem */
  217.                 if ($productPackItem->getProductVariant()->getIsNPWZRequired() && $productPackItem->getProductVariant()->getRequiredPWZ())
  218.                 {
  219.                     return true;
  220.                 }
  221.             }
  222.         }
  223.         return false;
  224.     }
  225.     public function getCourseProductPackItem(): array
  226.     {
  227.         $coursePackItems = array();
  228.         foreach ($this->getProductPackItem() as $productPackItem)
  229.         {
  230.             if ($productPackItem->getProductVariant() && $productPackItem->getProductVariant()->getCourses())
  231.             {
  232.                 $coursePackItems[] = $productPackItem;
  233.             }
  234.         }
  235.         return $coursePackItems;
  236.     }
  237.     public function getTotalDiscountNet()
  238.     {
  239.         $totalDiscountNet 0;
  240.         foreach ($this->getProductPackItem() as $productPackItem)
  241.         {
  242.             $totalDiscountNet += $productPackItem->getDiscountNet();
  243.         }
  244.         return $totalDiscountNet;
  245.     }
  246.     public function getTotalDiscountGross()
  247.     {
  248.         $totalDiscountGross 0;
  249.         foreach ($this->getProductPackItem() as $productPackItem)
  250.         {
  251.             $totalDiscountGross += $productPackItem->getDiscountGross();
  252.         }
  253.         return $totalDiscountGross;
  254.     }
  255.     public function getTotalPriceBeforeDiscountNet()
  256.     {
  257.         $totalPriceNet 0;
  258.         foreach ($this->getProductPackItem() as $productPackItem)
  259.         {
  260.             $totalPriceNet += $productPackItem->getQuantity() * $productPackItem->getProductVariant()->getFullPrice('net');
  261.         }
  262.         return $totalPriceNet;
  263.     }
  264.     public function getTotalPriceBeforeDiscountGross()
  265.     {
  266.         $totalPriceGross 0;
  267.         foreach ($this->getProductPackItem() as $productPackItem)
  268.         {
  269.             $totalPriceGross += $productPackItem->getQuantity() * $productPackItem->getProductVariant()->getFullPrice('gross');
  270.         }
  271.         return $totalPriceGross;
  272.     }
  273.     public function getTotalPriceNet()
  274.     {
  275.         $totalPriceNet 0;
  276.         foreach ($this->getProductPackItem() as $productPackItem)
  277.         {
  278.             $totalPriceNet += $productPackItem->getQuantity() * $productPackItem->getPriceNet();
  279.         }
  280.         return $totalPriceNet;
  281.     }
  282.     public function getTotalPriceGross()
  283.     {
  284.         $totalPriceGross 0;
  285.         foreach ($this->getProductPackItem() as $productPackItem)
  286.         {
  287.             $totalPriceGross += $productPackItem->getQuantity() * $productPackItem->getPriceGross();
  288.         }
  289.         return $totalPriceGross;
  290.     }
  291.     //------------------------------ setters & getters
  292.     public function getId(): ?int
  293.     {
  294.         return $this->id;
  295.     }
  296.     public function getName(): ?string
  297.     {
  298.         return $this->name;
  299.     }
  300.     public function setName(string $name): self
  301.     {
  302.         $this->name $name;
  303.         return $this;
  304.     }
  305.     public function getCreatedAt(): ?\DateTimeInterface
  306.     {
  307.         return $this->createdAt;
  308.     }
  309.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  310.     {
  311.         $this->createdAt $createdAt;
  312.         return $this;
  313.     }
  314.     public function getUpdatedAt(): ?\DateTimeInterface
  315.     {
  316.         return $this->updatedAt;
  317.     }
  318.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  319.     {
  320.         $this->updatedAt $updatedAt;
  321.         return $this;
  322.     }
  323.     /**
  324.      * @return Collection|ProductPackItem[]
  325.      */
  326.     public function getProductPackItem(): Collection
  327.     {
  328.         return $this->productPackItem;
  329.     }
  330.     public function addProductPackItem(ProductPackItem $productPackItem): self
  331.     {
  332.         if (!$this->productPackItem->contains($productPackItem)) {
  333.             $this->productPackItem[] = $productPackItem;
  334.             $productPackItem->setProductPack($this);
  335.         }
  336.         return $this;
  337.     }
  338.     public function removeProductPackItem(ProductPackItem $productPackItem): self
  339.     {
  340.         if ($this->productPackItem->contains($productPackItem)) {
  341.             $this->productPackItem->removeElement($productPackItem);
  342.             // set the owning side to null (unless already changed)
  343.             if ($productPackItem->getProductPack() === $this) {
  344.                 $productPackItem->setProductPack(null);
  345.             }
  346.         }
  347.         return $this;
  348.     }
  349.     /**
  350.      * @return Collection|ProductCart[]
  351.      */
  352.     public function getProductCart(): Collection
  353.     {
  354.         return $this->productCart;
  355.     }
  356.     public function addProductCart(ProductCart $productCart): self
  357.     {
  358.         if (!$this->productCart->contains($productCart)) {
  359.             $this->productCart[] = $productCart;
  360.             $productCart->setProductPack($this);
  361.         }
  362.         return $this;
  363.     }
  364.     public function removeProductCart(ProductCart $productCart): self
  365.     {
  366.         if ($this->productCart->contains($productCart)) {
  367.             $this->productCart->removeElement($productCart);
  368.             // set the owning side to null (unless already changed)
  369.             if ($productCart->getProductPack() === $this) {
  370.                 $productCart->setProductPack(null);
  371.             }
  372.         }
  373.         return $this;
  374.     }
  375.     public function getBuyMaxOne(): ?bool
  376.     {
  377.         return $this->buyMaxOne;
  378.     }
  379.     public function setBuyMaxOne(?bool $buyMaxOne): self
  380.     {
  381.         $this->buyMaxOne $buyMaxOne;
  382.         return $this;
  383.     }
  384.     public function getIsActive(): ?bool
  385.     {
  386.         return $this->isActive;
  387.     }
  388.     public function setIsActive(?bool $isActive): self
  389.     {
  390.         $this->isActive $isActive;
  391.         return $this;
  392.     }
  393.     public function hasEventProduct()
  394.     {
  395.         if (!$this->getProductPackItem()->isEmpty())
  396.         {
  397.             foreach ($this->getProductPackItem() as $productPackItem)
  398.             {
  399.                 /** @var ProductPack $productPackItem */
  400.                 if ($productPackItem->getProductVariant()->isEvent())
  401.                 {
  402.                     return true;
  403.                 }
  404.             }
  405.         }
  406.         return false;
  407.     }
  408.     public function getLabel(): ?string
  409.     {
  410.         return $this->label;
  411.     }
  412.     public function setLabel(?string $label): self
  413.     {
  414.         $this->label $label;
  415.         return $this;
  416.     }
  417.     public function getShowPrice(): ?bool
  418.     {
  419.         return $this->showPrice;
  420.     }
  421.     public function setShowPrice(?bool $showPrice): self
  422.     {
  423.         $this->showPrice $showPrice;
  424.         return $this;
  425.     }
  426.     /**
  427.      * @param int|null $grossShow
  428.      * @return ProductPack
  429.      */
  430.     public function setGrossShow(?int $grossShow): self
  431.     {
  432.         $this->grossShow $grossShow;
  433.         return $this;
  434.     }
  435.     /**
  436.      * @return int|null
  437.      */
  438.     public function getGrossShow(): ?int
  439.     {
  440.         return $this->grossShow;
  441.     }
  442.     public function getType(): ?ProductPackType
  443.     {
  444.         return $this->type;
  445.     }
  446.     public function setType(?ProductPackType $type): self
  447.     {
  448.         $this->type $type;
  449.         return $this;
  450.     }
  451.     /**
  452.      * @return Collection|OrderCycle[]
  453.      */
  454.     public function getOrderCycles(): Collection
  455.     {
  456.         return $this->orderCycles;
  457.     }
  458.     public function addOrderCycle(OrderCycle $orderCycle): self
  459.     {
  460.         if (!$this->orderCycles->contains($orderCycle)) {
  461.             $this->orderCycles[] = $orderCycle;
  462.             $orderCycle->setCyclePack($this);
  463.         }
  464.         return $this;
  465.     }
  466.     public function removeOrderCycle(OrderCycle $orderCycle): self
  467.     {
  468.         if ($this->orderCycles->contains($orderCycle)) {
  469.             $this->orderCycles->removeElement($orderCycle);
  470.             // set the owning side to null (unless already changed)
  471.             if ($orderCycle->getCyclePack() === $this) {
  472.                 $orderCycle->setCyclePack(null);
  473.             }
  474.         }
  475.         return $this;
  476.     }
  477.     public function findCyclePosition(ProductVariant $productVariant)
  478.     {
  479.         $position 0;
  480.         $course $productVariant->getCourses()->first();
  481.         foreach ($this->getProductPackItem() as $item)
  482.         {
  483.             $position++;
  484.             if ($item->getProductVariant()->getCourses()->contains($course))
  485.                 return $position;
  486.         }
  487.     }
  488.     public function getIsPubliclyAvailable(): ?bool
  489.     {
  490.         return $this->isPubliclyAvailable;
  491.     }
  492.     public function setIsPubliclyAvailable(?bool $isPubliclyAvailable): self
  493.     {
  494.         $this->isPubliclyAvailable $isPubliclyAvailable;
  495.         return $this;
  496.     }
  497.     public function getPubliclyAvailableDateFrom(): ?\DateTimeInterface
  498.     {
  499.         return $this->publiclyAvailableDateFrom;
  500.     }
  501.     public function setPubliclyAvailableDateFrom(?\DateTimeInterface $publiclyAvailableDateFrom): self
  502.     {
  503.         $this->publiclyAvailableDateFrom $publiclyAvailableDateFrom;
  504.         return $this;
  505.     }
  506.     public function getPubliclyAvailableDateTo(): ?\DateTimeInterface
  507.     {
  508.         return $this->publiclyAvailableDateTo;
  509.     }
  510.     public function setPubliclyAvailableDateTo(?\DateTimeInterface $publiclyAvailableDateTo): self
  511.     {
  512.         $this->publiclyAvailableDateTo $publiclyAvailableDateTo;
  513.         return $this;
  514.     }
  515.     /**
  516.      * @return Collection|ProductPackMultiDiscount[]
  517.      */
  518.     public function getMultiDiscounts(): Collection
  519.     {
  520.         return $this->multiDiscounts;
  521.     }
  522.     public function addMultiDiscount(ProductPackMultiDiscount $multiDiscount): self
  523.     {
  524.         if (!$this->multiDiscounts->contains($multiDiscount)) {
  525.             $this->multiDiscounts[] = $multiDiscount;
  526.             $multiDiscount->setProductPack($this);
  527.         }
  528.         return $this;
  529.     }
  530.     public function removeMultiDiscount(ProductPackMultiDiscount $multiDiscount): self
  531.     {
  532.         if ($this->multiDiscounts->contains($multiDiscount)) {
  533.             $this->multiDiscounts->removeElement($multiDiscount);
  534.             // set the owning side to null (unless already changed)
  535.             if ($multiDiscount->getProductPack() === $this) {
  536.                 $multiDiscount->setProductPack(null);
  537.             }
  538.         }
  539.         return $this;
  540.     }
  541.     public function getPortals(): array
  542.     {
  543.         $portals = [];
  544.         /** @var ProductPackItem $productPackItem */
  545.         foreach ($this->getProductPackItem() as $productPackItem) {
  546.             foreach ($productPackItem->getProductVariant()->getPortalSettings() as $portalSetting) {
  547.                 $portals[$portalSetting->getDomain()] = $portalSetting->getHash();
  548.             }
  549.         }
  550.         return $portals;
  551.     }
  552.     public function getCustomPromo1(): ?string
  553.     {
  554.         return $this->customPromo1;
  555.     }
  556.     public function setCustomPromo1(?string $customPromo1): self
  557.     {
  558.         $this->customPromo1 $customPromo1;
  559.         return $this;
  560.     }
  561.     public function getCustomPromo2(): ?string
  562.     {
  563.         return $this->customPromo2;
  564.     }
  565.     public function setCustomPromo2(?string $customPromo2): self
  566.     {
  567.         $this->customPromo2 $customPromo2;
  568.         return $this;
  569.     }
  570.     public function addCoupon(Coupon $coupon): self
  571.     {
  572.         if (!$this->coupon->contains($coupon)) {
  573.             $this->coupon[] = $coupon;
  574.         }
  575.         return $this;
  576.     }
  577.     public function removeCoupon(Coupon $coupon): void
  578.     {
  579.         $this->coupon->removeElement($coupon);
  580.     }
  581.     public function getCoupon()
  582.     {
  583.         return $this->coupon;
  584.     }
  585.     public function getOmnibus(): Collection
  586.     {
  587.         return $this->omnibus;
  588.     }
  589.     public function getEvent(): ?Events
  590.     {
  591.         return $this->event;
  592.     }
  593.     public function setEvent(?Events $event): self
  594.     {
  595.         $this->event $event;
  596.         return $this;
  597.     }
  598. }