src/Entity/Gos/Coupon.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use App\Enum\CouponCombinationMode;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * Coupon
  9.  *
  10.  * @ORM\Table(name="coupon")
  11.  * @ORM\Entity(repositoryClass="App\Repository\CouponRepository")
  12.  * @ORM\HasLifecycleCallbacks
  13.  */
  14. class Coupon extends BaseCoupon
  15. {
  16.     /**
  17.      * @var string
  18.      *
  19.      * @ORM\Column(name="code", type="string", length=191, unique=true)
  20.      */
  21.     protected $code;
  22.     /**
  23.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\ProductVariant", inversedBy="coupon")
  24.      * @ORM\JoinTable(name="product_variant_coupon")
  25.      */
  26.     private $productVariant;
  27.     /**
  28.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\ProductPack", inversedBy="coupon")
  29.      * @ORM\JoinTable(name="product_pack_coupon")
  30.      */
  31.     private $productPack;
  32.     /**
  33.      * @ORM\ManyToMany(targetEntity="ProductVariantPack", inversedBy="coupons")
  34.      * @ORM\JoinTable(name="product_variant_pack_coupon")
  35.      */
  36.     private $productVariantPacks;
  37.     /**
  38.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\ProductVariant", inversedBy="gratisCoupon")
  39.      * @ORM\JoinTable(name="product_variant_gratis_coupon")
  40.      */
  41.     private $gratis;
  42.     /**
  43.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\ProductVariant", inversedBy="bundleCoupon")
  44.      * @ORM\JoinTable(name="product_variant_bundle_coupon")
  45.      */
  46.     private $bundleProducts;
  47.     /**
  48.      * @ORM\Column(type="boolean", nullable=true)
  49.      */
  50.     private $appliesToPack;
  51.     /**
  52.      * @ORM\Column(type="boolean", nullable=true)
  53.      */
  54.     private $discountsAllProducts;
  55.     /**
  56.      * @ORM\ManyToMany(targetEntity=ProductVariant::class)
  57.      * @ORM\JoinTable(name="product_variant_coupon_exception")
  58.      */
  59.     private $productVariantException;
  60.     /**
  61.      * @ORM\ManyToMany(targetEntity=ProductVariantPack::class)
  62.      * @ORM\JoinTable(name="product_variant_pack_coupon_exception")
  63.      */
  64.     private $productVariantPackException;
  65.     /**
  66.      * @ORM\Column(type="boolean", nullable=true)
  67.      */
  68.     private $isPubliclyAvailable;
  69.     /**
  70.      * @ORM\ManyToOne(targetEntity=ColporteurVoucher::class, inversedBy="coupons")
  71.      */
  72.     private $colporteurVoucher;
  73.     /**
  74.      * @ORM\Column(type="string", nullable=false, options={"default":"none"})
  75.      */
  76.     private $combinationMode CouponCombinationMode::NONE;
  77.     /**
  78.      * @ORM\ManyToMany(targetEntity=Coupon::class, mappedBy="couponsToCombine")
  79.      */
  80.     private $couponsCombiningWithMe;
  81.     /**
  82.      * @ORM\JoinTable(name="coupon_combination")
  83.      * @ORM\ManyToMany(targetEntity=Coupon::class, inversedBy="couponsCombiningWithMe")
  84.      */
  85.     private $couponsToCombine;
  86.     /**
  87.      * Constructor
  88.      */
  89.     public function __construct()
  90.     {
  91.         parent::__construct();
  92.         $this->productVariant              = new ArrayCollection();
  93.         $this->productPack                 = new ArrayCollection();
  94.         $this->gratis                      = new ArrayCollection();
  95.         $this->bundleProducts              = new ArrayCollection();
  96.         $this->productVariantPacks         = new ArrayCollection();
  97.         $this->productVariantException     = new ArrayCollection();
  98.         $this->productVariantPackException = new ArrayCollection();
  99.         $this->couponsCombiningWithMe      = new ArrayCollection();
  100.         $this->couponsToCombine            = new ArrayCollection();
  101.     }
  102.     /**
  103.      * Add productVariant
  104.      *
  105.      * @param \App\Entity\Gos\ProductVariant $productVariant
  106.      *
  107.      * @return Coupon
  108.      */
  109.     public function addProductVariant(\App\Entity\Gos\ProductVariant $productVariant)
  110.     {
  111.         if (!$this->productVariant->contains($productVariant))
  112.         {
  113.             $this->productVariant[] = $productVariant;
  114.             $productVariant->addCoupon($this);
  115.         }
  116.         return $this;
  117.     }
  118.     /**
  119.      * Remove productVariant
  120.      *
  121.      * @param \App\Entity\Gos\ProductVariant $productVariant
  122.      */
  123.     public function removeProductVariant(\App\Entity\Gos\ProductVariant $productVariant)
  124.     {
  125.         if ($this->productVariant->contains($productVariant))
  126.         {
  127.             $this->productVariant->removeElement($productVariant);
  128.             $productVariant->removeCoupon($this);
  129.         }
  130.     }
  131.     /**
  132.      * Get productVariant
  133.      *
  134.      * @return \Doctrine\Common\Collections\Collection
  135.      */
  136.     public function getProductVariant()
  137.     {
  138.         return $this->productVariant;
  139.     }
  140.     /**
  141.      * Add productVariant
  142.      *
  143.      * @param \App\Entity\Gos\ProductPack $productPack
  144.      *
  145.      * @return Coupon
  146.      */
  147.     public function addProductPack(\App\Entity\Gos\ProductPack $productPack)
  148.     {
  149.         if (!$this->productPack->contains($productPack))
  150.         {
  151.             $this->productPack[] = $productPack;
  152.             $productPack->addCoupon($this);
  153.         }
  154.         return $this;
  155.     }
  156.     /**
  157.      * Remove productPack
  158.      *
  159.      * @param \App\Entity\Gos\ProductPack $productPack
  160.      */
  161.     public function removeProductPack(\App\Entity\Gos\ProductPack $productPack)
  162.     {
  163.         if ($this->productPack->contains($productPack))
  164.         {
  165.             $this->productPack->removeElement($productPack);
  166.             $productPack->removeCoupon($this);
  167.         }
  168.     }
  169.     /**
  170.      * Get productPack
  171.      *
  172.      * @return \Doctrine\Common\Collections\Collection
  173.      */
  174.     public function getProductPack()
  175.     {
  176.         return $this->productPack;
  177.     }
  178.     /**
  179.      * Add bundleProducts
  180.      *
  181.      * @param \App\Entity\Gos\ProductVariant $productVariant
  182.      * @return Coupon
  183.      */
  184.     public function addBundleProduct(\App\Entity\Gos\ProductVariant $productVariant)
  185.     {
  186.         $this->bundleProducts[] = $productVariant;
  187.         return $this;
  188.     }
  189.     /**
  190.      * Remove bundleProducts
  191.      *
  192.      * @param \App\Entity\Gos\ProductVariant $productVariant
  193.      */
  194.     public function removeBundleProduct(\App\Entity\Gos\ProductVariant $productVariant)
  195.     {
  196.         $this->bundleProducts->removeElement($productVariant);
  197.     }
  198.     /**
  199.      * Get bundleProducts
  200.      *
  201.      * @return \Doctrine\Common\Collections\Collection
  202.      */
  203.     public function getBundleProducts()
  204.     {
  205.         return $this->bundleProducts;
  206.     }
  207.     /**
  208.      * Set bundleProducts
  209.      *
  210.      * @param \Doctrine\Common\Collections\Collection $bundleProducts
  211.      * @return \App\Entity\Gos\Coupon
  212.      */
  213.     public function setBundleProducts($bundleProducts)
  214.     {
  215.         $this->bundleProducts $bundleProducts;
  216.         return $this;
  217.     }
  218.     /**
  219.      * @return Collection|ProductVariant[]
  220.      */
  221.     public function getGratis()
  222.     {
  223.         return $this->gratis;
  224.     }
  225.     public function addGrati(ProductVariant $grati): self
  226.     {
  227.         if (!$this->gratis->contains($grati)) {
  228.             $this->gratis[] = $grati;
  229.         }
  230.         return $this;
  231.     }
  232.     public function removeGrati(ProductVariant $grati): self
  233.     {
  234.         if ($this->gratis->contains($grati)) {
  235.             $this->gratis->removeElement($grati);
  236.         }
  237.         return $this;
  238.     }
  239.     /**
  240.      * @return Collection|ProductVariantPack[]
  241.      */
  242.     public function getProductVariantPacks()
  243.     {
  244.         return $this->productVariantPacks;
  245.     }
  246.     public function addProductVariantPack(ProductVariantPack $productVariantPack): self
  247.     {
  248.         if (!$this->productVariantPacks->contains($productVariantPack)) {
  249.             $this->productVariantPacks[] = $productVariantPack;
  250.         }
  251.         return $this;
  252.     }
  253.     public function removeProductVariantPack(ProductVariantPack $productVariantPack): self
  254.     {
  255.         if ($this->productVariantPacks->contains($productVariantPack)) {
  256.             $this->productVariantPacks->removeElement($productVariantPack);
  257.         }
  258.         return $this;
  259.     }
  260.     public function getAppliesToPack(): ?bool
  261.     {
  262.         return $this->appliesToPack;
  263.     }
  264.     public function setAppliesToPack(?bool $appliesToPack): self
  265.     {
  266.         $this->appliesToPack $appliesToPack;
  267.         return $this;
  268.     }
  269.     public function getDiscountsAllProducts(): ?bool
  270.     {
  271.         return $this->discountsAllProducts;
  272.     }
  273.     public function setDiscountsAllProducts(?bool $discountsAllProducts): self
  274.     {
  275.         $this->discountsAllProducts $discountsAllProducts;
  276.         return $this;
  277.     }
  278.     /**
  279.      * @return Collection|ProductVariant[]
  280.      */
  281.     public function getProductVariantException(): Collection
  282.     {
  283.         return $this->productVariantException;
  284.     }
  285.     public function addProductVariantException(ProductVariant $productVariantException): self
  286.     {
  287.         if (!$this->productVariantException->contains($productVariantException)) {
  288.             $this->productVariantException[] = $productVariantException;
  289.         }
  290.         return $this;
  291.     }
  292.     public function removeProductVariantException(ProductVariant $productVariantException): self
  293.     {
  294.         if ($this->productVariantException->contains($productVariantException)) {
  295.             $this->productVariantException->removeElement($productVariantException);
  296.         }
  297.         return $this;
  298.     }
  299.     /**
  300.      * @return Collection|ProductVariantPack[]
  301.      */
  302.     public function getProductVariantPackException(): Collection
  303.     {
  304.         return $this->productVariantPackException;
  305.     }
  306.     public function addProductVariantPackException(ProductVariantPack $productVariantPackException): self
  307.     {
  308.         if (!$this->productVariantPackException->contains($productVariantPackException)) {
  309.             $this->productVariantPackException[] = $productVariantPackException;
  310.         }
  311.         return $this;
  312.     }
  313.     public function removeProductVariantPackException(ProductVariantPack $productVariantPackException): self
  314.     {
  315.         if ($this->productVariantPackException->contains($productVariantPackException)) {
  316.             $this->productVariantPackException->removeElement($productVariantPackException);
  317.         }
  318.         return $this;
  319.     }
  320.     public function getIsPubliclyAvailable(): ?bool
  321.     {
  322.         return $this->isPubliclyAvailable;
  323.     }
  324.     public function setIsPubliclyAvailable(?bool $isPubliclyAvailable): self
  325.     {
  326.         $this->isPubliclyAvailable $isPubliclyAvailable;
  327.         return $this;
  328.     }
  329.     public function getColporteurVoucher(): ?ColporteurVoucher
  330.     {
  331.         return $this->colporteurVoucher;
  332.     }
  333.     public function setColporteurVoucher(?ColporteurVoucher $colporteurVoucher): self
  334.     {
  335.         $this->colporteurVoucher $colporteurVoucher;
  336.         return $this;
  337.     }
  338.     public function setCombinationMode(string $combinationMode CouponCombinationMode::NONE): self
  339.     {
  340.         if (!in_array($combinationMode, [
  341.                 CouponCombinationMode::NONE,
  342.                 CouponCombinationMode::ALL,
  343.                 CouponCombinationMode::SELECTED
  344.         ])) {
  345.             throw new \InvalidArgumentException("Invalid status");
  346.         }
  347.         $this->combinationMode $combinationMode;
  348.         return $this;
  349.     }
  350.     public function getCombinationMode(): string
  351.     {
  352.         return $this->combinationMode;
  353.     }
  354.     public function addCouponsToCombine(Coupon $coupon): self
  355.     {
  356.         if (!$this->couponsToCombine->contains($coupon))
  357.         {
  358.             $this->couponsToCombine->add($coupon);
  359.             $this->couponsCombiningWithMe->add($coupon);
  360.             if ($coupon->getCombinationMode() === CouponCombinationMode::NONE)
  361.             {
  362.                 $coupon->setCombinationMode(CouponCombinationMode::SELECTED);
  363.             }
  364.             $coupon->addCouponsToCombine($this);
  365.         }
  366.         return $this;
  367.     }
  368.     public function removeCouponsToCombine(Coupon $coupon): self
  369.     {
  370.         if ($this->couponsToCombine->contains($coupon))
  371.         {
  372.             $this->couponsToCombine->removeElement($coupon);
  373.             $this->couponsCombiningWithMe->removeElement($coupon);
  374.             $coupon->removeCouponsToCombine($this);
  375.         }
  376.         return $this;
  377.     }
  378.     public function getCouponsToCombine(): Collection
  379.     {
  380.         return $this->couponsToCombine;
  381.     }
  382.     public function canProductPackApply(?ProductPack $productPack): bool
  383.     {
  384.         return $this->appliesToPack && $this->productPack->contains($productPack);
  385.     }
  386. }