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