src/Entity/Gos/Cart.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use App\Entity\Gos\Uniqskills\Course;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * Cart
  9.  *
  10.  * @ORM\Table(name="cart")
  11.  * @ORM\Entity(repositoryClass="App\Repository\CartRepository")
  12.  * @ORM\HasLifecycleCallbacks
  13.  */
  14. class Cart
  15. {
  16.     /**
  17.      * @var int
  18.      *
  19.      * @ORM\Column(name="id", type="integer")
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue(strategy="AUTO")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @var string
  26.      *
  27.      * @ORM\Column(name="hash", type="string", length=255, unique=true)
  28.      */
  29.     private $hash;
  30.     /**
  31.      * @var bool
  32.      *
  33.      * @ORM\Column(type="boolean", nullable=true)
  34.      */
  35.     private $model;
  36.     /**
  37.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\CouponPending", mappedBy="cart", cascade={"persist"})
  38.      */
  39.     private $couponPending;
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\Coupon", inversedBy="cart", cascade={"persist"})
  42.      * @ORM\JoinColumn()
  43.      *
  44.      * TODO: DEV-171 Zostawilem to pole dla pewnosci zeby nic sie nie wysypalo
  45.      * Jesli wszystko zacznie uzywac multi kuponow bedzie mozna usunac to pole
  46.      */
  47.     private $coupon;
  48.     /**
  49.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\Coupon", inversedBy="carts", cascade={"persist"})
  50.      * @ORM\JoinTable(name="carts_coupons")
  51.      */
  52.     private $coupons;
  53.     /**
  54.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\ProductCart", mappedBy="cart", cascade={"persist"})
  55.      */
  56.     private $productCart;
  57.     /**
  58.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\Address", inversedBy="cart", cascade={"persist"})
  59.      * @ORM\JoinColumn()
  60.      */
  61.     private $address;
  62.     /**
  63.      * @ORM\OneToOne(targetEntity="App\Entity\Gos\User", inversedBy="cart")
  64.      * @ORM\JoinColumn(onDelete="SET NULL")
  65.      */
  66.     private $user;
  67.     /**
  68.      * @ORM\OneToOne(targetEntity="App\Entity\Gos\UserTemporary", inversedBy="cart", cascade={"persist"})
  69.      * @ORM\JoinColumn(onDelete="SET NULL")
  70.      */
  71.     private $userTemporary;
  72.     /**
  73.      * @ORM\Column(type="boolean", nullable=true)
  74.      */
  75.     private $hasMultiDiscount;
  76.     /**
  77.      * @ORM\Column(type="integer", nullable=true)
  78.      */
  79.     private $selectedDiscount;
  80.     /**
  81.      * @ORM\ManyToOne(targetEntity="Country", inversedBy="carts")
  82.      * @ORM\JoinColumn()
  83.      */
  84.     private $country;
  85.     /**
  86.      * @ORM\Column(type="integer", options={"default": 0})
  87.      */
  88.     private $extendedPaymentTime 0;
  89.     /**
  90.      * @ORM\ManyToOne(targetEntity="PaymentMethod", inversedBy="cart")
  91.      * @ORM\JoinColumn()
  92.      */
  93.     private $paymentMethod;
  94.     /**
  95.      * @ORM\ManyToOne(targetEntity="PaymentSystem", inversedBy="cart")
  96.      * @ORM\JoinColumn()
  97.      */
  98.     private $paymentSystem;
  99.     /**
  100.      * @ORM\Column(type="datetime")
  101.      */
  102.     private $createdAt;
  103.     /**
  104.      * @ORM\Column(type="datetime", nullable=true)
  105.      */
  106.     private $updatedAt;
  107.     /**
  108.      * @ORM\ManyToOne(targetEntity=PortalSettings::class, inversedBy="carts")
  109.      */
  110.     private $portalSettings;
  111.     /**
  112.      * @ORM\ManyToOne(targetEntity=ShippingType::class)
  113.      */
  114.     private $shippingType;
  115.     /**
  116.      * @ORM\Column(type="boolean", options={"default": false})
  117.      */
  118.     private $sentToSm false;
  119.     /**
  120.      * @ORM\Column(type="string", length=255, nullable=true)
  121.      */
  122.     private $burAssignedSupportId;
  123.     /**
  124.      * @ORM\Column(type="string", length=255, nullable=true)
  125.      */
  126.     private $salesManago2EventId;
  127.     public function isActive()
  128.     {
  129.         foreach ($this->getProductCart() as $productCart)
  130.         {
  131.             /** @var ProductCart $productCart */
  132.             if (!$productCart->isActive())
  133.             {
  134.                 return false;
  135.             }
  136.         }
  137.         return true;
  138.     }
  139.     public function __clone()
  140.     {
  141.         if ($this->id)
  142.         {
  143.             $this->setId(null);
  144.         }
  145.     }
  146.     /** @ORM\PrePersist() */
  147.     public function prePersist()
  148.     {
  149.         $this->createdAt = new \DateTime();
  150.     }
  151.     /** @ORM\PreUpdate() */
  152.     public function preUpdate()
  153.     {
  154.         $this->updatedAt = new \DateTime();
  155.     }
  156.     public function __toString()
  157.     {
  158.         return (string)$this->hash;
  159.     }
  160.     public function getCourse(): ?Course
  161.     {
  162.         /** @var ProductCart $productCart */
  163.         foreach ($this->getProductCart() as $productCart)
  164.         {
  165.             if ($productCart->getCourse())
  166.             {
  167.                 return $productCart->getCourse();
  168.             }
  169.         }
  170.         return null;
  171.     }
  172.     public function showButtonAdditionalAddress(): bool
  173.     {
  174.         if (!$this->getProductCart()->isEmpty())
  175.         {
  176.             /** @var ProductCart $productCart */
  177.             foreach ($this->getProductCart() as $productCart)
  178.             {
  179.                 if ($productCart->getProductPack())
  180.                 {
  181.                     foreach ($productCart->getProductPack()->getProductPackItem() as $item)
  182.                     {
  183.                         if ($item->getProductVariant()->getShowButtonAdditionalAddress() === true) return true;
  184.                     }
  185.                 }
  186.                 else if ($productCart->getProductVariant() && $productCart->getProductVariant()->getShowButtonAdditionalAddress() === true)
  187.                 {
  188.                     return true;
  189.                 }
  190.             }
  191.         }
  192.         return false;
  193.     }
  194.     public function hasProductVariant(ProductVariant $productVariant): bool
  195.     {
  196.         /** @var ProductCart $productCart */
  197.         foreach ($this->productCart as $productCart)
  198.         {
  199.             if ($productCart->getProductVariant() === $productVariant)
  200.             {
  201.                 return true;
  202.             }
  203.         }
  204.         return false;
  205.     }
  206.     public function hasOnlyDigitalProducts(): bool
  207.     {
  208.         if (!$this->getProductCart()->isEmpty())
  209.         {
  210.             /** @var ProductCart $productCart */
  211.             foreach ($this->getProductCart() as $productCart)
  212.             {
  213.                 if ($productCart->getProductPack())
  214.                 {
  215.                     foreach ($productCart->getProductPack()->getProductPackItem() as $item)
  216.                     {
  217.                         if (!$item->getProductVariant()->getIsDigital())
  218.                         {
  219.                             return false;
  220.                         }
  221.                     }
  222.                 }
  223.                 else if ($productCart->getProductVariant() && !$productCart->getProductVariant()->getIsDigital())
  224.                 {
  225.                     return false;
  226.                 }
  227.             }
  228.         }
  229.         return true;
  230.     }
  231.     public function hasEventProduct(): bool
  232.     {
  233.         if (!$this->getProductCart()->isEmpty())
  234.         {
  235.             foreach ($this->getProductCart() as $productCart)
  236.             {
  237.                 /** @var ProductCart $productCart */
  238.                 if ($productCart->hasEventProduct())
  239.                 {
  240.                     return true;
  241.                 }
  242.             }
  243.         }
  244.         return false;
  245.     }
  246.     public function hasEventProductTaxFree(): bool
  247.     {
  248.         if (!$this->getProductCart()->isEmpty())
  249.         {
  250.             foreach ($this->getProductCart() as $productCart)
  251.             {
  252.                 /** @var ProductCart $productCart */
  253.                 if ($productCart->hasEventProductTaxFree())
  254.                 {
  255.                     return true;
  256.                 }
  257.             }
  258.         }
  259.         return false;
  260.     }
  261.     public function hasOnlyEventProduct(): bool
  262.     {
  263.         if (!$this->getProductCart()->isEmpty())
  264.         {
  265.             foreach ($this->getProductCart() as $productCart)
  266.             {
  267.                 /** @var ProductCart $productCart */
  268.                 if (!$productCart->hasOnlyEventProduct())
  269.                 {
  270.                     return false;
  271.                 }
  272.             }
  273.         }
  274.         return true;
  275.     }
  276.     /**
  277.      * Return prodcutCart when has event product
  278.      * @return array
  279.      */
  280.     public function getEventProductCart(): array
  281.     {
  282.         $productsCart = array();
  283.         if (!$this->getProductCart()->isEmpty())
  284.         {
  285.             foreach ($this->getProductCart() as $productCart)
  286.             {
  287.                 /** @var ProductCart $productCart */
  288.                 if ($productCart->hasEventProduct())
  289.                 {
  290.                     $productsCart[] = $productCart;
  291.                 }
  292.             }
  293.         }
  294.         return $productsCart;
  295.     }
  296.     public function hasUniqskillsMultiUserCourse()
  297.     {
  298.         return !empty(array_filter($this->getProductCart()->toArray(), function($productCart)
  299.         {
  300.             return $productCart->getProductVariant() !== null
  301.                 && $productCart->getProductVariant()->getIsUniqskillsProduct()
  302.                 && $productCart->getProductVariant()->getMaxUsers() > 1
  303.                 && $productCart->getProductVariant()->getBuyMaxOne() === false
  304.                 && $productCart->getQuantity() > 1;
  305.         }));
  306.     }
  307.     public function getUniqskillsMultiUserCourse()
  308.     {
  309.         return array_filter($this->getProductCart()->toArray(), function($productCart)
  310.         {
  311.             return $productCart->getProductVariant() !== null
  312.                 && $productCart->getProductVariant()->getIsUniqskillsProduct()
  313.                 && $productCart->getProductVariant()->getMaxUsers() > 1
  314.                 && $productCart->getProductVariant()->getBuyMaxOne() === false;
  315.         });
  316.     }
  317.     //------------------------------ setters & getters
  318.     /**
  319.      * Set id
  320.      *
  321.      * @return Cart
  322.      */
  323.     public function setId($id)
  324.     {
  325.         $this->id $id;
  326.         return $this;
  327.     }
  328.     /**
  329.      * Constructor
  330.      */
  331.     public function __construct()
  332.     {
  333.         $this->productCart      = new ArrayCollection();
  334.         $this->couponPending    = new ArrayCollection();
  335.         $this->coupons          = new ArrayCollection();
  336.     }
  337.     /**
  338.      * Get id
  339.      *
  340.      * @return integer
  341.      */
  342.     public function getId()
  343.     {
  344.         return $this->id;
  345.     }
  346.     /**
  347.      * Set hash
  348.      *
  349.      * @param string $hash
  350.      *
  351.      * @return Cart
  352.      */
  353.     public function setHash($hash)
  354.     {
  355.         $this->hash $hash;
  356.         return $this;
  357.     }
  358.     /**
  359.      * Get hash
  360.      *
  361.      * @return string
  362.      */
  363.     public function getHash()
  364.     {
  365.         return $this->hash;
  366.     }
  367.     /**
  368.      * Set model
  369.      *
  370.      * @param boolean $model
  371.      *
  372.      * @return Cart
  373.      */
  374.     public function setModel($model)
  375.     {
  376.         $this->model $model;
  377.         return $this;
  378.     }
  379.     /**
  380.      * Get model
  381.      *
  382.      * @return boolean
  383.      */
  384.     public function getModel()
  385.     {
  386.         return $this->model;
  387.     }
  388.     /**
  389.      * Set createdAt
  390.      *
  391.      * @param \DateTime $createdAt
  392.      *
  393.      * @return Cart
  394.      */
  395.     public function setCreatedAt($createdAt)
  396.     {
  397.         $this->createdAt $createdAt;
  398.         return $this;
  399.     }
  400.     /**
  401.      * Get createdAt
  402.      *
  403.      * @return \DateTime
  404.      */
  405.     public function getCreatedAt()
  406.     {
  407.         return $this->createdAt;
  408.     }
  409.     /**
  410.      * Set updatedAt
  411.      *
  412.      * @param \DateTime $updatedAt
  413.      *
  414.      * @return Cart
  415.      */
  416.     public function setUpdatedAt($updatedAt)
  417.     {
  418.         $this->updatedAt $updatedAt;
  419.         return $this;
  420.     }
  421.     /**
  422.      * Get updatedAt
  423.      *
  424.      * @return \DateTime
  425.      */
  426.     public function getUpdatedAt()
  427.     {
  428.         return $this->updatedAt;
  429.     }
  430.     /**
  431.      * Set couponPending
  432.      * @deprecated Please use addCouponPending
  433.      *
  434.      * @param CouponPending $couponPending
  435.      *
  436.      * @return Cart
  437.      */
  438.     public function setCouponPending(CouponPending $couponPending null): Cart
  439.     {
  440.         if ($couponPending) {
  441.             return $this->addCouponPending($couponPending);
  442.         }
  443.         return $this;
  444.     }
  445.     /**
  446.      * Add couponPending
  447.      *
  448.      * @param CouponPending $couponPending
  449.      *
  450.      * @return $this
  451.      */
  452.     public function addCouponPending(CouponPending $couponPending): Cart
  453.     {
  454.         if (!$this->couponPending->contains($couponPending))
  455.         {
  456.             $this->couponPending->add($couponPending);
  457.             $couponPending->setCart($this);
  458.         }
  459.         return $this;
  460.     }
  461.     /**
  462.      * Remove couponPending
  463.      *
  464.      * @param CouponPending $couponPending
  465.      *
  466.      * @return $this
  467.      */
  468.     public function removeCouponPending(CouponPending $couponPending): Cart
  469.     {
  470.         if ($this->couponPending->contains($couponPending))
  471.         {
  472.             $this->couponPending->removeElement($couponPending);
  473.             $couponPending->setCart(null);
  474.         }
  475.         return $this;
  476.     }
  477.     /**
  478.      * Get couponPending
  479.      *
  480.      * @return Collection
  481.      */
  482.     public function getCouponPending()
  483.     {
  484.         return $this->couponPending;
  485.     }
  486.     /**
  487.      * Set coupon
  488.      *
  489.      * @param Coupon|null $coupon
  490.      * @deprecated Please use addCupon instead
  491.      *
  492.      * TODO: DEV-171 Zostawielem ta funkcje dla pewnosci zeby nic sie nie wysypalo
  493.      * Jesli wszystko zacznie uzywac multi kuponow bedzie mozna ja usunac
  494.      *
  495.      * @return Cart
  496.      */
  497.     public function setCoupon(Coupon $coupon null)
  498.     {
  499.         if ($this->coupon !== null && $this->coupons->contains($this->coupon))
  500.         {
  501.             $this->coupons->removeElement($this->coupon);
  502.         }
  503.         if ($coupon !== null && !$this->coupons->contains($coupon))
  504.         {
  505.             $this->coupons->add($coupon);
  506.         }
  507.         $this->coupon $coupon;
  508.         return $this;
  509.     }
  510.     /**
  511.      * Set coupons
  512.      *
  513.      * @param Collection $coupons
  514.      *
  515.      * @return Cart
  516.      */
  517.     public function setCoupons(Collection $coupons)
  518.     {
  519.         if ($coupons->isEmpty())
  520.         {
  521.             $this->coupon null;
  522.         }
  523.         $this->coupons $coupons;
  524.         /** @var Coupon $coupon */
  525.         foreach ($coupons as $coupon) {
  526.             $coupon->addCarts($this);
  527.         }
  528.         return $this;
  529.     }
  530.     /**
  531.      * Add coupon
  532.      *
  533.      * @param Coupon $coupon
  534.      *
  535.      * @return Cart
  536.      */
  537.     public function addCoupon(Coupon $coupon)
  538.     {
  539.         if(!$this->coupons->contains($coupon))
  540.         {
  541.             $this->coupons->add($coupon);
  542.             $coupon->addCarts($this);
  543.         }
  544.         return $this;
  545.     }
  546.     /**
  547.      * Remove coupon
  548.      *
  549.      * @param Coupon $coupon
  550.      *
  551.      * @return Cart
  552.      */
  553.     public function removeCoupon(Coupon $coupon)
  554.     {
  555.         if($this->coupons->contains($coupon))
  556.         {
  557.             $this->coupons->removeElement($coupon);
  558.             $coupon->removeCarts($this);
  559.         }
  560.         if ($this->coupon === $coupon)
  561.         {
  562.             $this->coupon null;
  563.         }
  564.         return $this;
  565.     }
  566.     /**
  567.      * Get coupon
  568.      * @deprecated Please use getCoupons instead
  569.      *
  570.      * TODO: DEV-171 Zostawielem ta funkcje dla pewnosci zeby nic sie nie wysypalo
  571.      * Jesli wszystko zacznie uzywac multi kuponow bedzie mozna usunac ta funkcje
  572.      *
  573.      * @return Coupon
  574.      */
  575.     public function getCoupon()
  576.     {
  577.         if ($this->coupons->isEmpty())
  578.         {
  579.             return $this->coupon;
  580.         }
  581.         return $this->coupons->first();
  582.     }
  583.     /**
  584.      * Get coupons
  585.      *
  586.      * @return Collection
  587.      */
  588.     public function getCoupons()
  589.     {
  590.         return $this->coupons;
  591.     }
  592.     /**
  593.      * Add productCart
  594.      *
  595.      * @param \App\Entity\Gos\ProductCart $productCart
  596.      *
  597.      * @return Cart
  598.      */
  599.     public function addProductCart(\App\Entity\Gos\ProductCart $productCart)
  600.     {
  601.         $this->productCart[] = $productCart;
  602.         $this->getPaymentSystems();
  603.         return $this;
  604.     }
  605.     /**
  606.      * Remove productCart
  607.      *
  608.      * @param \App\Entity\Gos\ProductCart $productCart
  609.      */
  610.     public function removeProductCart(\App\Entity\Gos\ProductCart $productCart)
  611.     {
  612.         $this->productCart->removeElement($productCart);
  613.     }
  614.     /**
  615.      * Get productCart
  616.      *
  617.      * @return \Doctrine\Common\Collections\Collection
  618.      */
  619.     public function getProductCart()
  620.     {
  621.         return $this->productCart;
  622.     }
  623.     public function hasProducts()
  624.     {
  625.         return $this->productCart->first();
  626.     }
  627.     /**
  628.      * @return Collection|ProductVariant[]
  629.      */
  630.     public function getAllProductVariants(): Collection
  631.     {
  632.         $productVariants = new ArrayCollection();
  633.         foreach ($this->productCart as $productCart)
  634.         {
  635.             /** @var ProductCart $productCart */
  636.             if ($productCart->getProductVariant())
  637.             {
  638.                 $productVariants->add($productCart->getProductVariant());
  639.             }
  640.             elseif ($productCart->getProductPack())
  641.             {
  642.                 foreach ($productCart->getProductPack()->getProductPackItem() as $productPackItem)
  643.                 {
  644.                     if ($productPackItem->getProductVariant())
  645.                     {
  646.                         $productVariants->add($productPackItem->getProductVariant());
  647.                     }
  648.                 }
  649.             }
  650.         }
  651.         return $productVariants;
  652.     }
  653.     public function checkCartHasOnlyProductPact(): bool
  654.     {
  655.         if ($this->getProductCart()->isEmpty())
  656.         {
  657.             return false;
  658.         }
  659.         /** @var ProductCart $productCart */
  660.         foreach ($this->getProductCart() as $productCart)
  661.         {
  662.             if (is_null($productCart->getProductPack()))
  663.             {
  664.                 return false;
  665.             }
  666.         }
  667.         return true;
  668.     }
  669.     public function omittedShippingCostsInAllProducts(): bool
  670.     {
  671.         foreach ($this->productCart as $productCart)
  672.         {
  673.             /** @var ProductCart $productCart */
  674.             if (!$productCart->getOmitShippingCosts())
  675.             {
  676.                 return false;
  677.             }
  678.         }
  679.         return true;
  680.     }
  681.     public function checkProlongationVariantInCart()
  682.     {
  683.         foreach ($this->productCart as $productCart)
  684.         {
  685.             /** @var ProductCart $productCart */
  686.             if ($productVariant $productCart->getProductVariant())
  687.             {
  688.                 if (substr($productVariant->getProductVariantNoComplete(), 01) == '2')
  689.                 {
  690.                     return true;
  691.                 }
  692.             }
  693.         }
  694.         return false;
  695.     }
  696.     /**
  697.      * Set address
  698.      *
  699.      * @param \App\Entity\Gos\Address $address
  700.      *
  701.      * @return Cart
  702.      */
  703.     public function setAddress(\App\Entity\Gos\Address $address null)
  704.     {
  705.         $this->address $address;
  706.         return $this;
  707.     }
  708.     /**
  709.      * Get address
  710.      *
  711.      * @return \App\Entity\Gos\Address
  712.      */
  713.     public function getAddress()
  714.     {
  715.         return $this->address;
  716.     }
  717.     /**
  718.      * Set user
  719.      *
  720.      * @param \App\Entity\Gos\User $user
  721.      *
  722.      * @return Cart
  723.      */
  724.     public function setUser(\App\Entity\Gos\User $user null)
  725.     {
  726.         $this->user $user;
  727.         return $this;
  728.     }
  729.     /**
  730.      * Get user
  731.      *
  732.      * @return \App\Entity\Gos\User
  733.      */
  734.     public function getUser()
  735.     {
  736.         return $this->user;
  737.     }
  738.     public function getUserTemporary(): ?UserTemporary
  739.     {
  740.         return $this->userTemporary;
  741.     }
  742.     public function setUserTemporary(?UserTemporary $userTemporary): self
  743.     {
  744.         $this->userTemporary $userTemporary;
  745.         return $this;
  746.     }
  747.     public function getExtendedPaymentTime(): ?int
  748.     {
  749.         return $this->extendedPaymentTime;
  750.     }
  751.     public function setExtendedPaymentTime(int $extendedPaymentTime): self
  752.     {
  753.         $this->extendedPaymentTime $extendedPaymentTime;
  754.         return $this;
  755.     }
  756.     public function getHasMultiDiscount(): ?bool
  757.     {
  758.         return $this->hasMultiDiscount;
  759.     }
  760.     public function setHasMultiDiscount(?bool $hasMultiDiscount): self
  761.     {
  762.         $this->hasMultiDiscount $hasMultiDiscount;
  763.         return $this;
  764.     }
  765.     public function getSelectedDiscount(): ?int
  766.     {
  767.         return $this->selectedDiscount;
  768.     }
  769.     public function setSelectedDiscount(?int $selectedDiscount): self
  770.     {
  771.         $this->selectedDiscount $selectedDiscount;
  772.         return $this;
  773.     }
  774.     public function getClientType(): ?ClientType
  775.     {
  776.         if (empty($this->address) || empty($this->getAddress()->getClientType()))
  777.         {
  778.             return null;
  779.         }
  780.         return $this->getAddress()->getClientType();
  781.     }
  782.     public function getClientTypeName(): ?string
  783.     {
  784.         return $this->getClientType() ? $this->getClientType()->getName() : null;
  785.     }
  786.     public function hasProductCartToGift(): bool
  787.     {
  788.         if (!empty($this->productCart))
  789.         {
  790.             foreach ($this->productCart as $productCart)
  791.             {
  792.                 /** @var ProductCart $productCart */
  793.                 if (!empty($productCart->getGift()) || $productCart->getIsGift())
  794.                 {
  795.                     return true;
  796.                 }
  797.             }
  798.         }
  799.         return false;
  800.     }
  801.     public function getProductsCartToGift()
  802.     {
  803.         if (!empty($this->productCart))
  804.         {
  805.             return $this->getProductCart()->filter(
  806.                 function ($productCart) {
  807.                     return $productCart->getGift();
  808.                 }
  809.             );
  810.         }
  811.         return [];
  812.     }
  813.     public function getCountry(): ?Country
  814.     {
  815.         return $this->country;
  816.     }
  817.     public function setCountry(?Country $country): self
  818.     {
  819.         $this->country $country;
  820.         return $this;
  821.     }
  822.     public function shouldShowGrossPrice(): bool
  823.     {
  824.         return $this->getPortalSettings() ? $this->getPortalSettings()->getShowGrossPrice() : false;
  825.     }
  826.     public function hasOnlyUniqskillsProducts(): bool
  827.     {
  828.         foreach ($this->getAllProductVariants() as $productVariant)
  829.         {
  830.             if ($productVariant->getCourses()->isEmpty())
  831.             {
  832.                 return false;
  833.             }
  834.         }
  835.         return true;
  836.     }
  837.     public function getPaymentSystems(): array
  838.     {
  839.         $paymentSystems = [];
  840. //        if ($this->hasOnlyUniqskillsProducts())
  841. //        {
  842.             if (empty($this->getAllProductVariants()))
  843.             {
  844.                 $this->setPaymentSystem(null);
  845.                 return $paymentSystems;
  846.             }
  847.             foreach ($this->getAllProductVariants() as $index => $productVariant)
  848.             {
  849.                 if ($index === 0)
  850.                 {
  851.                     foreach ($productVariant->getPaymentSystem() as $paymentSystem)
  852.                     {
  853.                         if ($paymentSystem->getIsActive() === false)
  854.                         {
  855.                             continue;
  856.                         }
  857.                         if ($this->hasProductCartToGift() && $paymentSystem->getSlug() === 'proforma-invoice')
  858.                         {
  859.                             continue;
  860.                         }
  861.                         $paymentSystems[$paymentSystem->getSlug()] = $paymentSystem;
  862.                     }
  863.                 }
  864.                 else
  865.                 {
  866.                     foreach ($paymentSystems as $key => $paymentSystem)
  867.                     {
  868.                         if (!in_array($paymentSystem$productVariant->getPaymentSystem()->toArray()))
  869.                         {
  870.                             unset($paymentSystems[$key]);
  871.                         }
  872.                     }
  873.                 }
  874.             }
  875.             uasort($paymentSystems, function (PaymentSystem $paymentSystemAPaymentSystem $paymentSystemB) {
  876.                 return $paymentSystemA->getPosition($this->getCountry(), $this->portalSettings) <=> $paymentSystemB->getPosition($this->getCountry(), $this->portalSettings);
  877.             });
  878.             if (!empty($paymentSystems) && empty($this->getPaymentSystem()))
  879.             {
  880.                 $this->setPaymentSystem(reset($paymentSystems));
  881.             }
  882. //        }
  883. //        elseif (empty($this->getCountry()) || $this->getCountry()->getSlug() == 'poland')
  884. //        {
  885. //            $paymentSystems[] = (new PaymentSystem())
  886. //                ->setName($this->getInvoicePaymentTitle())
  887. //                ->setSlug('invoice')
  888. //                ->setIsActive(true);
  889. //
  890. //            $this->setPaymentSystem(null);
  891. //        }
  892.         return $paymentSystems;
  893.     }
  894.     public function getPaymentMethod(): ?PaymentMethod
  895.     {
  896.         return $this->paymentMethod;
  897.     }
  898.     public function setPaymentMethod(?PaymentMethod $paymentMethod): self
  899.     {
  900.         $this->paymentMethod $paymentMethod;
  901.         return $this;
  902.     }
  903.     public function getPaymentSystem(): ?PaymentSystem
  904.     {
  905.         return $this->paymentSystem;
  906.     }
  907.     public function setPaymentSystem(?PaymentSystem $paymentSystem): self
  908.     {
  909.         $this->paymentSystem $paymentSystem;
  910.         return $this;
  911.     }
  912.     public function canBePaidForWithOnline()
  913.     {
  914.         /** @var ProductCart $productCart */
  915.         foreach ($this->productCart as $productCart)
  916.         {
  917.             $hasOnline array_filter($productCart->getAvailablePaymentMethods(),
  918.                 function($val) {return $val->getSlug() == 'online';});
  919.             if (empty($hasOnline))
  920.             {
  921.                 return false;
  922.             }
  923.         }
  924.         return true;
  925.     }
  926.     public function mustBeHiddenInSB()
  927.     {
  928.         $clientType $this->getAddress() ? $this->getAddress()->getClientType() : null;
  929.         /** @var ProductCart $productCart */
  930.         foreach ($this->productCart as $productCart)
  931.         {
  932.             if ($productCart->getProductVariant() !== null) {
  933.                 $additionalOptionsByClientType $productCart->getProductVariant()->getAdditionalOptionsByClientType($clientType);
  934.                 if ($additionalOptionsByClientType && $additionalOptionsByClientType->getHiddenInSBTillPaid() === true) {
  935.                     return true;
  936.                 }
  937.             }
  938.             if ($productCart->getProductPack() !== null) {
  939.                 foreach ($productCart->getProductPack()->getProductPackItem() as $productPackItem) {
  940.                     $additionalOptionsByClientType $productPackItem->getProductVariant()->getAdditionalOptionsByClientType($clientType);
  941.                     if ($additionalOptionsByClientType && $additionalOptionsByClientType->getHiddenInSBTillPaid() === true) {
  942.                         return true;
  943.                     }
  944.                 }
  945.             }
  946.         }
  947.         return false;
  948.     }
  949.     public function getProductsWithDelayedProformaPayment()
  950.     {
  951.         $products = array();
  952.         /** @var ProductCart $productCart */
  953.         foreach ($this->productCart as $productCart)
  954.         {
  955.             if ($productCart->getProductPack())
  956.             {
  957.                 if (count($productCart->getProductPack()->getProductPackItem()))
  958.                 {
  959.                     foreach ($productCart->getProductPack()->getProductPackItem() as $productPackItem)
  960.                     {
  961.                         if ($productPackItem->getProductVariant()
  962.                             ->checkIfProductVariantHavePaymentMethod($this->getClientType(), 'delayed-proforma'))
  963.                         {
  964.                             $products[] = $productPackItem->getProductVariant();
  965.                         }
  966.                     }
  967.                 }
  968.             }
  969.             else
  970.             {
  971.                 if ($productCart->getProductVariant())
  972.                 {
  973.                     if ($productCart->getProductVariant()
  974.                         ->checkIfProductVariantHavePaymentMethod($this->getClientType(), 'delayed-proforma'))
  975.                     {
  976.                         $products[] = $productCart->getProductVariant();
  977.                     }
  978.                 }
  979.             }
  980.         }
  981.         return $products;
  982.     }
  983.     public function getProductsWithInvoicePayment()
  984.     {
  985.         $products = array();
  986.         /** @var ProductCart $productCart */
  987.         foreach ($this->productCart as $productCart)
  988.         {
  989.             foreach ($productCart->getAvailablePaymentMethods() as $paymentMethod)
  990.             {
  991.                 if ($paymentMethod->getSlug() == 'invoice')
  992.                 {
  993.                     $products[] = $productCart;
  994.                 }
  995.             }
  996.         }
  997.         return $products;
  998.     }
  999.     public function getProductsWithProformaPayment()
  1000.     {
  1001.         $products = array();
  1002.         /** @var ProductCart $productCart */
  1003.         foreach ($this->productCart as $productCart)
  1004.         {
  1005.             foreach ($productCart->getAvailablePaymentMethods() as $paymentMethod)
  1006.             {
  1007.                 if ($paymentMethod->getSlug() == 'proforma-invoice')
  1008.                 {
  1009.                     $products[] = $productCart;
  1010.                 }
  1011.             }
  1012.         }
  1013.         return $products;
  1014.     }
  1015.     public function hasProductsWithRecurringPayment(): bool
  1016.     {
  1017.         /** @var ProductCart $productCart */
  1018.         foreach ($this->productCart as $productCart)
  1019.         {
  1020.             if ($productCart->getProductVariant())
  1021.             {
  1022.                 if ($productCart->getProductVariant()->getIsRecurringSubscription() === true)
  1023.                 {
  1024.                     return true;
  1025.                 }
  1026.             }
  1027.         }
  1028.         return false;
  1029.     }
  1030.     public function getInvoicePaymentTitle()
  1031.     {
  1032.         if (!empty($this->getProductsWithDelayedProformaPayment()))
  1033.         {
  1034.             return 'Faktura pro forma';
  1035.         }
  1036.         if (!empty($this->getProductsWithInvoicePayment()) && !empty($this->getProductsWithProformaPayment()))
  1037.         {
  1038.             $title 'Faktury: VAT oraz pro-forma';
  1039.         }
  1040.         elseif (!empty($this->getProductsWithProformaPayment()))
  1041.         {
  1042.             $title 'Faktura pro-forma';
  1043.         }
  1044.         else
  1045.         {
  1046.             $title 'Faktura VAT';
  1047.         }
  1048.         if ($this->canBePaidForWithOnline())
  1049.         {
  1050.             if ($this->mustBeHiddenInSB())
  1051.                 $title 'Płatność online';
  1052.             else
  1053.                 $title .= ' z możliwością opłacenia online';
  1054.         }
  1055.         return $title;
  1056.     }
  1057.     public function hasCycleProducts(): bool
  1058.     {
  1059.         /** @var ProductCart $productCart */
  1060.         foreach ($this->getProductCart() as $productCart)
  1061.         {
  1062.             if ($productCart->getCycleProductPack())
  1063.             {
  1064.                 return true;
  1065.             }
  1066.         }
  1067.         return false;
  1068.     }
  1069.     public function getCycleProducts(): array
  1070.     {
  1071.         $cycleProducts = array();
  1072.         /** @var ProductCart $productCart */
  1073.         foreach ($this->getProductCart() as $productCart)
  1074.         {
  1075.             if ($productCart->getCycleProductPack())
  1076.             {
  1077.                 $cycleProducts[] = $productCart->getProductVariant();
  1078.             }
  1079.         }
  1080.         return $cycleProducts;
  1081.     }
  1082.     public function getAvailableClientTypes()
  1083.     {
  1084.         $clientTypes = [];
  1085.         $quantity 0;
  1086.         /** @var ProductCart $productCart */
  1087.         foreach ($this->productCart as $productCart)
  1088.         {
  1089.             $clientTypes array_merge($clientTypes$productCart->getAvailableClientTypes()['types']);
  1090.             $quantity += $productCart->getAvailableClientTypes()['quantity'];
  1091.         }
  1092.         $count array_count_values(array_map(function ($clientType) {
  1093.             return $clientType->getId();
  1094.         }, $clientTypes));
  1095.         $arr = [];
  1096.         foreach ($count as $key => $item)
  1097.         {
  1098.             // if all product variants have the same clientType
  1099.             if($quantity == $item$arr[] = $this->findClientTypeById($key$clientTypes);
  1100.         }
  1101.         return $arr;
  1102.     }
  1103.     private function findClientTypeById($id$clientTypes)
  1104.     {
  1105.         foreach ($clientTypes as $clientType)
  1106.         {
  1107.             if($clientType->getId() == $id)
  1108.             {
  1109.                 return $clientType;
  1110.             }
  1111.         }
  1112.         return false;
  1113.     }
  1114.     public function getPortalSettings(): ?PortalSettings
  1115.     {
  1116.         return $this->portalSettings;
  1117.     }
  1118.     public function setPortalSettings(?PortalSettings $portalSettings): self
  1119.     {
  1120.         $this->portalSettings $portalSettings;
  1121.         return $this;
  1122.     }
  1123.     public function isEmailInvoiceEnabled(): bool
  1124.     {
  1125.         $emailInvoiceEnabled true;
  1126.         /** @var ProductCart $cartProduct */
  1127.         foreach ($this->getProductCart() as $cartProduct)
  1128.         {
  1129.             if (!$cartProduct->getEmailInvoiceEnabled())
  1130.             {
  1131.                 $emailInvoiceEnabled false;
  1132.                 break;
  1133.             }
  1134.         }
  1135.         return $emailInvoiceEnabled;
  1136.     }
  1137.     public function askForPWZ(): bool
  1138.     {
  1139.         /** @var ProductCart $productCart */
  1140.         foreach ($this->getProductCart() as $productCart)
  1141.         {
  1142.             if ($productCart->askForPWZ())
  1143.             {
  1144.                 return true;
  1145.             }
  1146.         }
  1147.         return false;
  1148.     }
  1149.     public function isNPWZRequired(): bool
  1150.     {
  1151.         /** @var ProductCart $productCart */
  1152.         foreach ($this->getProductCart() as $productCart)
  1153.         {
  1154.             if ($productCart->isNPWZRequired())
  1155.             {
  1156.                 return true;
  1157.             }
  1158.         }
  1159.         return false;
  1160.     }
  1161.     public function getShippingType(): ?ShippingType
  1162.     {
  1163.         return $this->shippingType;
  1164.     }
  1165.     public function setShippingType(?ShippingType $shippingType): self
  1166.     {
  1167.         $this->shippingType $shippingType;
  1168.         return $this;
  1169.     }
  1170.     public function isSentToSm(): ?bool
  1171.     {
  1172.         return $this->sentToSm;
  1173.     }
  1174.     public function setSentToSm(bool $sentToSm): self
  1175.     {
  1176.         $this->sentToSm $sentToSm;
  1177.         return $this;
  1178.     }
  1179.     public function validateCoupons(): void
  1180.     {
  1181.         /** @var Coupon $coupon */
  1182.         foreach ($this->getCoupons() as $coupon) {
  1183.             if ($coupon->isValid() === false) {
  1184.                 $this->removeCoupon($coupon);
  1185.             }
  1186.         }
  1187.         /** @var ProductCart $productCart */
  1188.         foreach ($this->getProductCart() as $productCart) {
  1189.             foreach ($productCart->getCoupons() as $coupon) {
  1190.                 if ($coupon->isValid() === false) {
  1191.                     $productCart->removeCoupon($coupon);
  1192.                 }
  1193.             }
  1194.         }
  1195.     }
  1196.     public function getBurAssignedSupportId(): ?string
  1197.     {
  1198.         return $this->burAssignedSupportId;
  1199.     }
  1200.     public function setBurAssignedSupportId(?string $burAssignedSupportId): self
  1201.     {
  1202.         $this->burAssignedSupportId $burAssignedSupportId;
  1203.         return $this;
  1204.     }
  1205.     public function getSalesManago2EventId(): ?string
  1206.     {
  1207.         return $this->salesManago2EventId;
  1208.     }
  1209.     public function setSalesManago2EventId(string $salesManago2EventId): self
  1210.     {
  1211.         $this->salesManago2EventId $salesManago2EventId;
  1212.         return $this;
  1213.     }
  1214. }