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

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