src/Flexy/ShopBundle/Entity/Promotion/Coupon.php line 18

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Promotion;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Customer\Customer;
  5. use App\Flexy\ShopBundle\Entity\Order\Order;
  6. use App\Flexy\ShopBundle\Repository\Promotion\CouponRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. #[ApiResource]
  13. #[UniqueEntity('code')]
  14. #[ORM\Entity(repositoryClassCouponRepository::class)]
  15. class Coupon
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column(type'integer')]
  20.     private $id;
  21.     #[ORM\Column(type'string'length255)]
  22.     private ?string $name null;
  23.     #[ORM\Column(type'string'length255)]
  24.     private ?string $code null;
  25.     #[ORM\Column(type'string'length255nullabletrue)]
  26.     private ?string $type null;
  27.     #[ORM\Column(type'integer'nullabletrue)]
  28.     private ?int $usageLimit null;
  29.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  30.     private ?\DateTimeImmutable $endAt null;
  31.     #[ORM\ManyToOne(targetEntityPromotion::class, inversedBy'coupons')]
  32.     private ?\App\Flexy\ShopBundle\Entity\Promotion\Promotion $promotion null;
  33.     #[ORM\Column(type'string'length255nullabletrue)]
  34.     private $typeReduction;
  35.     #[ORM\Column(type'float'nullabletrue)]
  36.     private ?float $valueReduction null;
  37.     #[ORM\OneToMany(targetEntityOrder::class, mappedBy'coupon')]
  38.     private \Doctrine\Common\Collections\Collection|array $orders;
  39.         #[ORM\Column(type'integer'nullabletrue)]
  40.     private ?int $minProductsByOrder null;
  41.     #[ORM\Column(type'text'nullabletrue)]
  42.     private ?string $description null;
  43.     #[ORM\ManyToMany(targetEntityCustomer::class, inversedBy'affectedCoupons')]
  44.     private \Doctrine\Common\Collections\Collection|array $allowedCustomers;
  45.     #[ORM\ManyToOne(targetEntityCustomer::class, inversedBy'affectedCouponsOnlyForMe')]
  46.     private ?\App\Flexy\ShopBundle\Entity\Customer\Customer $onlyThisCustomer null;
  47.     public function __construct()
  48.     {
  49.         $this->orders = new ArrayCollection();
  50.         $this->allowedCustomers = new ArrayCollection();
  51.     }
  52.     public function getId(): ?int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getName(): ?string
  57.     {
  58.         return $this->name;
  59.     }
  60.     public function setName(string $name): self
  61.     {
  62.         $this->name $name;
  63.         return $this;
  64.     }
  65.     public function getCode(): ?string
  66.     {
  67.         return $this->code;
  68.     }
  69.     public function setCode(string $code): self
  70.     {
  71.         $this->code $code;
  72.         return $this;
  73.     }
  74.     public function getType(): ?string
  75.     {
  76.         return $this->type;
  77.     }
  78.     public function setType(?string $type): self
  79.     {
  80.         $this->type $type;
  81.         return $this;
  82.     }
  83.     public function getUsageLimit(): ?int
  84.     {
  85.         return $this->usageLimit;
  86.     }
  87.     public function setUsageLimit(?int $usageLimit): self
  88.     {
  89.         $this->usageLimit $usageLimit;
  90.         return $this;
  91.     }
  92.     public function getEndAt(): ?\DateTimeImmutable
  93.     {
  94.         return $this->endAt;
  95.     }
  96.     public function setEndAt(?\DateTimeImmutable $endAt): self
  97.     {
  98.         $this->endAt $endAt;
  99.         return $this;
  100.     }
  101.     public function getPromotion(): ?Promotion
  102.     {
  103.         return $this->promotion;
  104.     }
  105.     public function setPromotion(?Promotion $promotion): self
  106.     {
  107.         $this->promotion $promotion;
  108.         return $this;
  109.     }
  110.     public function getTypeReduction()
  111.     {
  112.         return $this->typeReduction;
  113.     }
  114.     public function setTypeReduction$typeReduction)
  115.     {
  116.         $this->typeReduction $typeReduction;
  117.         return $this;
  118.     }
  119.     public function getValueReduction(): ?float
  120.     {
  121.         return $this->valueReduction;
  122.     }
  123.     public function setValueReduction(?float $valueReduction): self
  124.     {
  125.         $this->valueReduction $valueReduction;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @return Collection<int, Order>
  130.      */
  131.     public function getOrders(): Collection
  132.     {
  133.         return $this->orders;
  134.     }
  135.     public function addOrder(Order $order): self
  136.     {
  137.         if (!$this->orders->contains($order)) {
  138.             $this->orders[] = $order;
  139.             $order->setCoupon($this);
  140.         }
  141.         return $this;
  142.     }
  143.     public function removeOrder(Order $order): self
  144.     {
  145.         if ($this->orders->removeElement($order)) {
  146.             // set the owning side to null (unless already changed)
  147.             if ($order->getCoupon() === $this) {
  148.                 $order->setCoupon(null);
  149.             }
  150.         }
  151.         return $this;
  152.     }
  153.     public function getMinProductsByOrder(): ?int
  154.     {
  155.         return $this->minProductsByOrder;
  156.     }
  157.     public function setMinProductsByOrder(?int $minProductsByOrder): self
  158.     {
  159.         $this->minProductsByOrder $minProductsByOrder;
  160.         return $this;
  161.     }
  162.     public function getDescription(): ?string
  163.     {
  164.         return $this->description;
  165.     }
  166.     public function setDescription(?string $description): self
  167.     {
  168.         $this->description $description;
  169.         return $this;
  170.     }
  171.     /**
  172.      * @return Collection<int, Customer>
  173.      */
  174.     public function getAllowedCustomers(): Collection
  175.     {
  176.         return $this->allowedCustomers;
  177.     }
  178.     public function addAllowedCustomer(Customer $allowedCustomer): self
  179.     {
  180.         if (!$this->allowedCustomers->contains($allowedCustomer)) {
  181.             $this->allowedCustomers[] = $allowedCustomer;
  182.         }
  183.         return $this;
  184.     }
  185.     public function removeAllowedCustomer(Customer $allowedCustomer): self
  186.     {
  187.         $this->allowedCustomers->removeElement($allowedCustomer);
  188.         return $this;
  189.     }
  190.     public function getOnlyThisCustomer(): ?Customer
  191.     {
  192.         return $this->onlyThisCustomer;
  193.     }
  194.     public function setOnlyThisCustomer(?Customer $onlyThisCustomer): self
  195.     {
  196.         $this->onlyThisCustomer $onlyThisCustomer;
  197.         return $this;
  198.     }
  199. }