src/Flexy/ShopBundle/Entity/Promotion/Coupon.php line 21
<?php
namespace App\Flexy\ShopBundle\Entity\Promotion;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Flexy\ShopBundle\Entity\Customer\Customer;
use App\Flexy\ShopBundle\Entity\Order\Order;
use App\Flexy\ShopBundle\Repository\Promotion\CouponRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
#[ApiResource]
#[ApiFilter(SearchFilter::class, properties: ['exact', 'code'])]
#[UniqueEntity('code')]
#[ORM\Entity(repositoryClass: CouponRepository::class)]
class Coupon
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private ?string $name = null;
#[ORM\Column(type: 'string', length: 255)]
private ?string $code = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $type = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $usageLimit = null;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $endAt = null;
#[ORM\ManyToOne(targetEntity: Promotion::class, inversedBy: 'coupons')]
private ?\App\Flexy\ShopBundle\Entity\Promotion\Promotion $promotion = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $typeReduction;
#[ORM\Column(type: 'float', nullable: true)]
private ?float $valueReduction = null;
#[ORM\OneToMany(targetEntity: Order::class, mappedBy: 'coupon')]
private \Doctrine\Common\Collections\Collection|array $orders;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $minProductsByOrder = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $description = null;
#[ORM\ManyToMany(targetEntity: Customer::class, inversedBy: 'affectedCoupons')]
private \Doctrine\Common\Collections\Collection|array $allowedCustomers;
#[ORM\ManyToOne(targetEntity: Customer::class, inversedBy: 'affectedCouponsOnlyForMe')]
private ?\App\Flexy\ShopBundle\Entity\Customer\Customer $onlyThisCustomer = null;
public function __construct()
{
$this->orders = new ArrayCollection();
$this->allowedCustomers = new ArrayCollection();
}
public function __toString()
{
return (string)$this->code;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getUsageLimit(): ?int
{
return $this->usageLimit;
}
public function setUsageLimit(?int $usageLimit): self
{
$this->usageLimit = $usageLimit;
return $this;
}
public function getEndAt(): ?\DateTimeImmutable
{
return $this->endAt;
}
public function setEndAt(?\DateTimeImmutable $endAt): self
{
$this->endAt = $endAt;
return $this;
}
public function getPromotion(): ?Promotion
{
return $this->promotion;
}
public function setPromotion(?Promotion $promotion): self
{
$this->promotion = $promotion;
return $this;
}
public function getTypeReduction()
{
return $this->typeReduction;
}
public function setTypeReduction( $typeReduction)
{
$this->typeReduction = $typeReduction;
return $this;
}
public function getValueReduction(): ?float
{
return $this->valueReduction;
}
public function setValueReduction(?float $valueReduction): self
{
$this->valueReduction = $valueReduction;
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setCoupon($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getCoupon() === $this) {
$order->setCoupon(null);
}
}
return $this;
}
public function getMinProductsByOrder(): ?int
{
return $this->minProductsByOrder;
}
public function setMinProductsByOrder(?int $minProductsByOrder): self
{
$this->minProductsByOrder = $minProductsByOrder;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection<int, Customer>
*/
public function getAllowedCustomers(): Collection
{
return $this->allowedCustomers;
}
public function addAllowedCustomer(Customer $allowedCustomer): self
{
if (!$this->allowedCustomers->contains($allowedCustomer)) {
$this->allowedCustomers[] = $allowedCustomer;
}
return $this;
}
public function removeAllowedCustomer(Customer $allowedCustomer): self
{
$this->allowedCustomers->removeElement($allowedCustomer);
return $this;
}
public function getOnlyThisCustomer(): ?Customer
{
return $this->onlyThisCustomer;
}
public function setOnlyThisCustomer(?Customer $onlyThisCustomer): self
{
$this->onlyThisCustomer = $onlyThisCustomer;
return $this;
}
}