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.      * ProductPack constructor.
  90.      */
  91.     public function __construct()
  92.     {
  93.         $this->productPackItem = new ArrayCollection();
  94.         $this->productCart     = new ArrayCollection();
  95.         $this->orderCycles = new ArrayCollection();
  96.         $this->multiDiscounts = new ArrayCollection();
  97.     }
  98.     /** @ORM\PrePersist() */
  99.     public function prePersist()
  100.     {
  101.         $this->createdAt = new \DateTime();
  102.     }
  103.     /** @ORM\PreUpdate() */
  104.     public function preUpdate()
  105.     {
  106.         $this->updatedAt = new \DateTime();
  107.     }
  108.     public function __toString()
  109.     {
  110.         return $this->name;
  111.     }
  112.     public function isActive()
  113.     {
  114.         if (!$this->getIsActive())
  115.         {
  116.             return false;
  117.         }
  118.         if (!$this->getProductPackItem()->isEmpty())
  119.         {
  120.             foreach ($this->getProductPackItem() as $productPackItem)
  121.             {
  122.                 /** @var ProductPackItem $productPackItem */
  123.                 if (!$productPackItem->getProductVariant()->isActive())
  124.                 {
  125.                     return false;
  126.                 }
  127.             }
  128.         }
  129.         return true;
  130.     }
  131.     /**
  132.      * Return productPackItem when has event product
  133.      * @return array
  134.      */
  135.     public function getEventProductPackItem()
  136.     {
  137.         $productsPackItem = array();
  138.         if (!$this->getProductPackItem()->isEmpty())
  139.         {
  140.             foreach ($this->getProductPackItem() as $productPackItem)
  141.             {
  142.                 /** @var ProductPackItem $productPackItem */
  143.                 if ($productPackItem->getProductVariant()->isEvent())
  144.                 {
  145.                     $productsPackItem[] = $productPackItem;
  146.                 }
  147.             }
  148.         }
  149.         return $productsPackItem;
  150.     }
  151.     public function getFirstNonVirtualItem(): ?ProductPackItem
  152.     {
  153.         foreach ($this->getProductPackItem() as $productPackItem)
  154.         {
  155.             if (!$productPackItem->getProductVariant()->getIsVirtual())
  156.             {
  157.                 return $productPackItem;
  158.             }
  159.         }
  160.         return null;
  161.     }
  162.     public function hasPhysicalVariant(): bool
  163.     {
  164.         foreach ($this->getProductPackItem() as $productPackItem)
  165.         {
  166.             if ($productPackItem->getProductVariant()->isPhysical())
  167.             {
  168.                 return true;
  169.             }
  170.         }
  171.         return false;
  172.     }
  173.     public function askForPWZ(): bool
  174.     {
  175.         if (!$this->getProductPackItem()->isEmpty())
  176.         {
  177.             foreach ($this->getProductPackItem() as $productPackItem)
  178.             {
  179.                 /** @var ProductPackItem $productPackItem */
  180.                 if ($productPackItem->getProductVariant()->getRequiredPWZ())
  181.                 {
  182.                     return true;
  183.                 }
  184.             }
  185.         }
  186.         return false;
  187.     }
  188.     public function isNPWZRequired(): bool
  189.     {
  190.         if (!$this->getProductPackItem()->isEmpty())
  191.         {
  192.             foreach ($this->getProductPackItem() as $productPackItem)
  193.             {
  194.                 /** @var ProductPackItem $productPackItem */
  195.                 if ($productPackItem->getProductVariant()->getIsNPWZRequired() && $productPackItem->getProductVariant()->getRequiredPWZ())
  196.                 {
  197.                     return true;
  198.                 }
  199.             }
  200.         }
  201.         return false;
  202.     }
  203.     public function getCourseProductPackItem(): array
  204.     {
  205.         $coursePackItems = array();
  206.         foreach ($this->getProductPackItem() as $productPackItem)
  207.         {
  208.             if ($productPackItem->getProductVariant() && $productPackItem->getProductVariant()->getCourses())
  209.             {
  210.                 $coursePackItems[] = $productPackItem;
  211.             }
  212.         }
  213.         return $coursePackItems;
  214.     }
  215.     public function getTotalDiscountNet()
  216.     {
  217.         $totalDiscountNet 0;
  218.         foreach ($this->getProductPackItem() as $productPackItem)
  219.         {
  220.             $totalDiscountNet += $productPackItem->getDiscountNet();
  221.         }
  222.         return $totalDiscountNet;
  223.     }
  224.     public function getTotalDiscountGross()
  225.     {
  226.         $totalDiscountGross 0;
  227.         foreach ($this->getProductPackItem() as $productPackItem)
  228.         {
  229.             $totalDiscountGross += $productPackItem->getDiscountGross();
  230.         }
  231.         return $totalDiscountGross;
  232.     }
  233.     public function getTotalPriceBeforeDiscountNet()
  234.     {
  235.         $totalPriceNet 0;
  236.         foreach ($this->getProductPackItem() as $productPackItem)
  237.         {
  238.             $totalPriceNet += $productPackItem->getQuantity() * $productPackItem->getProductVariant()->getFullPrice('net');
  239.         }
  240.         return $totalPriceNet;
  241.     }
  242.     public function getTotalPriceBeforeDiscountGross()
  243.     {
  244.         $totalPriceGross 0;
  245.         foreach ($this->getProductPackItem() as $productPackItem)
  246.         {
  247.             $totalPriceGross += $productPackItem->getQuantity() * $productPackItem->getProductVariant()->getFullPrice('gross');
  248.         }
  249.         return $totalPriceGross;
  250.     }
  251.     public function getTotalPriceNet()
  252.     {
  253.         $totalPriceNet 0;
  254.         foreach ($this->getProductPackItem() as $productPackItem)
  255.         {
  256.             $totalPriceNet += $productPackItem->getQuantity() * $productPackItem->getPriceNet();
  257.         }
  258.         return $totalPriceNet;
  259.     }
  260.     public function getTotalPriceGross()
  261.     {
  262.         $totalPriceGross 0;
  263.         foreach ($this->getProductPackItem() as $productPackItem)
  264.         {
  265.             $totalPriceGross += $productPackItem->getQuantity() * $productPackItem->getPriceGross();
  266.         }
  267.         return $totalPriceGross;
  268.     }
  269.     //------------------------------ setters & getters
  270.     public function getId(): ?int
  271.     {
  272.         return $this->id;
  273.     }
  274.     public function getName(): ?string
  275.     {
  276.         return $this->name;
  277.     }
  278.     public function setName(string $name): self
  279.     {
  280.         $this->name $name;
  281.         return $this;
  282.     }
  283.     public function getCreatedAt(): ?\DateTimeInterface
  284.     {
  285.         return $this->createdAt;
  286.     }
  287.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  288.     {
  289.         $this->createdAt $createdAt;
  290.         return $this;
  291.     }
  292.     public function getUpdatedAt(): ?\DateTimeInterface
  293.     {
  294.         return $this->updatedAt;
  295.     }
  296.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  297.     {
  298.         $this->updatedAt $updatedAt;
  299.         return $this;
  300.     }
  301.     /**
  302.      * @return Collection|ProductPackItem[]
  303.      */
  304.     public function getProductPackItem(): Collection
  305.     {
  306.         return $this->productPackItem;
  307.     }
  308.     public function addProductPackItem(ProductPackItem $productPackItem): self
  309.     {
  310.         if (!$this->productPackItem->contains($productPackItem)) {
  311.             $this->productPackItem[] = $productPackItem;
  312.             $productPackItem->setProductPack($this);
  313.         }
  314.         return $this;
  315.     }
  316.     public function removeProductPackItem(ProductPackItem $productPackItem): self
  317.     {
  318.         if ($this->productPackItem->contains($productPackItem)) {
  319.             $this->productPackItem->removeElement($productPackItem);
  320.             // set the owning side to null (unless already changed)
  321.             if ($productPackItem->getProductPack() === $this) {
  322.                 $productPackItem->setProductPack(null);
  323.             }
  324.         }
  325.         return $this;
  326.     }
  327.     /**
  328.      * @return Collection|ProductCart[]
  329.      */
  330.     public function getProductCart(): Collection
  331.     {
  332.         return $this->productCart;
  333.     }
  334.     public function addProductCart(ProductCart $productCart): self
  335.     {
  336.         if (!$this->productCart->contains($productCart)) {
  337.             $this->productCart[] = $productCart;
  338.             $productCart->setProductPack($this);
  339.         }
  340.         return $this;
  341.     }
  342.     public function removeProductCart(ProductCart $productCart): self
  343.     {
  344.         if ($this->productCart->contains($productCart)) {
  345.             $this->productCart->removeElement($productCart);
  346.             // set the owning side to null (unless already changed)
  347.             if ($productCart->getProductPack() === $this) {
  348.                 $productCart->setProductPack(null);
  349.             }
  350.         }
  351.         return $this;
  352.     }
  353.     public function getBuyMaxOne(): ?bool
  354.     {
  355.         return $this->buyMaxOne;
  356.     }
  357.     public function setBuyMaxOne(?bool $buyMaxOne): self
  358.     {
  359.         $this->buyMaxOne $buyMaxOne;
  360.         return $this;
  361.     }
  362.     public function getIsActive(): ?bool
  363.     {
  364.         return $this->isActive;
  365.     }
  366.     public function setIsActive(?bool $isActive): self
  367.     {
  368.         $this->isActive $isActive;
  369.         return $this;
  370.     }
  371.     public function hasEventProduct()
  372.     {
  373.         if (!$this->getProductPackItem()->isEmpty())
  374.         {
  375.             foreach ($this->getProductPackItem() as $productPackItem)
  376.             {
  377.                 /** @var ProductPack $productPackItem */
  378.                 if ($productPackItem->getProductVariant()->isEvent())
  379.                 {
  380.                     return true;
  381.                 }
  382.             }
  383.         }
  384.         return false;
  385.     }
  386.     public function getLabel(): ?string
  387.     {
  388.         return $this->label;
  389.     }
  390.     public function setLabel(?string $label): self
  391.     {
  392.         $this->label $label;
  393.         return $this;
  394.     }
  395.     public function getShowPrice(): ?bool
  396.     {
  397.         return $this->showPrice;
  398.     }
  399.     public function setShowPrice(?bool $showPrice): self
  400.     {
  401.         $this->showPrice $showPrice;
  402.         return $this;
  403.     }
  404.     /**
  405.      * @param int|null $grossShow
  406.      * @return ProductPack
  407.      */
  408.     public function setGrossShow(?int $grossShow): self
  409.     {
  410.         $this->grossShow $grossShow;
  411.         return $this;
  412.     }
  413.     /**
  414.      * @return int|null
  415.      */
  416.     public function getGrossShow(): ?int
  417.     {
  418.         return $this->grossShow;
  419.     }
  420.     public function getType(): ?ProductPackType
  421.     {
  422.         return $this->type;
  423.     }
  424.     public function setType(?ProductPackType $type): self
  425.     {
  426.         $this->type $type;
  427.         return $this;
  428.     }
  429.     /**
  430.      * @return Collection|OrderCycle[]
  431.      */
  432.     public function getOrderCycles(): Collection
  433.     {
  434.         return $this->orderCycles;
  435.     }
  436.     public function addOrderCycle(OrderCycle $orderCycle): self
  437.     {
  438.         if (!$this->orderCycles->contains($orderCycle)) {
  439.             $this->orderCycles[] = $orderCycle;
  440.             $orderCycle->setCyclePack($this);
  441.         }
  442.         return $this;
  443.     }
  444.     public function removeOrderCycle(OrderCycle $orderCycle): self
  445.     {
  446.         if ($this->orderCycles->contains($orderCycle)) {
  447.             $this->orderCycles->removeElement($orderCycle);
  448.             // set the owning side to null (unless already changed)
  449.             if ($orderCycle->getCyclePack() === $this) {
  450.                 $orderCycle->setCyclePack(null);
  451.             }
  452.         }
  453.         return $this;
  454.     }
  455.     public function findCyclePosition(ProductVariant $productVariant)
  456.     {
  457.         $position 0;
  458.         $course $productVariant->getCourses()->first();
  459.         foreach ($this->getProductPackItem() as $item)
  460.         {
  461.             $position++;
  462.             if ($item->getProductVariant()->getCourses()->contains($course))
  463.                 return $position;
  464.         }
  465.     }
  466.     public function getIsPubliclyAvailable(): ?bool
  467.     {
  468.         return $this->isPubliclyAvailable;
  469.     }
  470.     public function setIsPubliclyAvailable(?bool $isPubliclyAvailable): self
  471.     {
  472.         $this->isPubliclyAvailable $isPubliclyAvailable;
  473.         return $this;
  474.     }
  475.     public function getPubliclyAvailableDateFrom(): ?\DateTimeInterface
  476.     {
  477.         return $this->publiclyAvailableDateFrom;
  478.     }
  479.     public function setPubliclyAvailableDateFrom(?\DateTimeInterface $publiclyAvailableDateFrom): self
  480.     {
  481.         $this->publiclyAvailableDateFrom $publiclyAvailableDateFrom;
  482.         return $this;
  483.     }
  484.     public function getPubliclyAvailableDateTo(): ?\DateTimeInterface
  485.     {
  486.         return $this->publiclyAvailableDateTo;
  487.     }
  488.     public function setPubliclyAvailableDateTo(?\DateTimeInterface $publiclyAvailableDateTo): self
  489.     {
  490.         $this->publiclyAvailableDateTo $publiclyAvailableDateTo;
  491.         return $this;
  492.     }
  493.     /**
  494.      * @return Collection|ProductPackMultiDiscount[]
  495.      */
  496.     public function getMultiDiscounts(): Collection
  497.     {
  498.         return $this->multiDiscounts;
  499.     }
  500.     public function addMultiDiscount(ProductPackMultiDiscount $multiDiscount): self
  501.     {
  502.         if (!$this->multiDiscounts->contains($multiDiscount)) {
  503.             $this->multiDiscounts[] = $multiDiscount;
  504.             $multiDiscount->setProductPack($this);
  505.         }
  506.         return $this;
  507.     }
  508.     public function removeMultiDiscount(ProductPackMultiDiscount $multiDiscount): self
  509.     {
  510.         if ($this->multiDiscounts->contains($multiDiscount)) {
  511.             $this->multiDiscounts->removeElement($multiDiscount);
  512.             // set the owning side to null (unless already changed)
  513.             if ($multiDiscount->getProductPack() === $this) {
  514.                 $multiDiscount->setProductPack(null);
  515.             }
  516.         }
  517.         return $this;
  518.     }
  519.     public function getPortals(): array
  520.     {
  521.         $portals = [];
  522.         /** @var ProductPackItem $productPackItem */
  523.         foreach ($this->getProductPackItem() as $productPackItem) {
  524.             foreach ($productPackItem->getProductVariant()->getPortalSettings() as $portalSetting) {
  525.                 $portals[$portalSetting->getDomain()] = $portalSetting->getHash();
  526.             }
  527.         }
  528.         return $portals;
  529.     }
  530. }