src/Flexy/ShopBundle/Entity/Promotion/Promotion.php line 19

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Promotion;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Product\CategoryProduct;
  5. use App\Flexy\ShopBundle\Entity\Product\Product;
  6. use App\Flexy\ShopBundle\Repository\Promotion\PromotionRepository;
  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 Gedmo\Mapping\Annotation as Gedmo;
  12. use Gedmo\Sortable\Entity\Repository\SortableRepository;
  13. #[ApiResource]
  14. #[ORM\Entity(repositoryClassPromotionRepository::class)]
  15. #[ORM\Cache(usage:"NONSTRICT_READ_WRITE",region:"append_depend")]
  16. class Promotion implements \Stringable
  17. {
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column(type'integer')]
  21.     private $id;
  22.     #[ORM\Column(type'float')]
  23.     
  24.     private ?float $value 0;
  25.     #[ORM\Column(type'string'length255nullabletrue)]
  26.     private ?string $type "price";
  27.     #[ORM\Column(type'text'nullabletrue)]
  28.     private ?string $description null;
  29.     #[ORM\Column(type'string'length255)]
  30.     private ?string $code null;
  31.     #[ORM\Column(type'string'length255)]
  32.     #[Assert\NotNull()]
  33.     private ?string $name null;
  34.     #[Gedmo\SortablePosition]
  35.     #[ORM\Column(type'integer'nullabletrue)]
  36.     private ?int $priority null;
  37.     #[ORM\Column(type'integer'nullabletrue)]
  38.     private ?int $usageLimit null;
  39.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  40.     private ?\DateTimeImmutable $startAt null;
  41.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  42.     private ?\DateTimeImmutable $endAt null;
  43.     #[ORM\OneToMany(targetEntityCoupon::class, mappedBy'promotion')]
  44.     private \Doctrine\Common\Collections\Collection|array $coupons;
  45.     #[ORM\OneToMany(targetEntityPromotionRule::class, mappedBy'promotion'orphanRemovaltrue)]
  46.     private \Doctrine\Common\Collections\Collection|array $promotionRules;
  47.     #[ORM\OneToMany(targetEntityPromotionAction::class, mappedBy'promotion'orphanRemovaltrue)]
  48.     private \Doctrine\Common\Collections\Collection|array $promotionActions;
  49.     #[ORM\OneToMany(targetEntityProduct::class, mappedBy'promotion')]
  50.     private \Doctrine\Common\Collections\Collection|array $products;
  51.     #[ORM\Column(nullabletrue)]
  52.     private ?bool $keepCurrentPrice null;
  53.     #[ORM\OneToMany(mappedBy'promotion'targetEntityCategoryProduct::class)]
  54.     private Collection $categories;
  55.     #[ORM\Column(nullabletrue)]
  56.     private ?float $adjustableValue 0;
  57.     public function __toString(): string
  58.     {
  59.         return (string) $this->name;
  60.     }
  61.     public function __construct()
  62.     {
  63.         $this->coupons = new ArrayCollection();
  64.         $this->promotionRules = new ArrayCollection();
  65.         $this->promotionActions = new ArrayCollection();
  66.         $this->products = new ArrayCollection();
  67.         $this->categories = new ArrayCollection();
  68.     }
  69.     public function getId(): ?int
  70.     {
  71.         return $this->id;
  72.     }
  73.     public function getValue(): ?float
  74.     {
  75.         return $this->value;
  76.     }
  77.     public function setValue(float $value): self
  78.     {
  79.         $this->value $value;
  80.         return $this;
  81.     }
  82.     public function getType(): ?string
  83.     {
  84.         return $this->type;
  85.     }
  86.     public function setType(?string $type): self
  87.     {
  88.         $this->type $type;
  89.         return $this;
  90.     }
  91.     public function getDescription(): ?string
  92.     {
  93.         return $this->description;
  94.     }
  95.     public function setDescription(?string $description): self
  96.     {
  97.         $this->description $description;
  98.         return $this;
  99.     }
  100.     public function getCode(): ?string
  101.     {
  102.         return $this->code;
  103.     }
  104.     public function setCode(string $code): self
  105.     {
  106.         $this->code $code;
  107.         return $this;
  108.     }
  109.     public function getName(): ?string
  110.     {
  111.         return $this->name;
  112.     }
  113.     public function setName(string $name): self
  114.     {
  115.         $this->name $name;
  116.         return $this;
  117.     }
  118.     public function getPriority(): ?int
  119.     {
  120.         return $this->priority;
  121.     }
  122.     public function setPriority(?int $priority): self
  123.     {
  124.         $this->priority $priority;
  125.         return $this;
  126.     }
  127.     public function getUsageLimit(): ?int
  128.     {
  129.         return $this->usageLimit;
  130.     }
  131.     public function setUsageLimit(?int $usageLimit): self
  132.     {
  133.         $this->usageLimit $usageLimit;
  134.         return $this;
  135.     }
  136.     public function getStartAt(): ?\DateTimeImmutable
  137.     {
  138.         return $this->startAt;
  139.     }
  140.     public function setStartAt(?\DateTimeImmutable $startAt): self
  141.     {
  142.         $this->startAt $startAt;
  143.         return $this;
  144.     }
  145.     public function getEndAt(): ?\DateTimeImmutable
  146.     {
  147.         return $this->endAt;
  148.     }
  149.     public function setEndAt(?\DateTimeImmutable $endAt): self
  150.     {
  151.         $this->endAt $endAt;
  152.         return $this;
  153.     }
  154.     /**
  155.      * @return Collection|Coupon[]
  156.      */
  157.     public function getCoupons(): Collection
  158.     {
  159.         return $this->coupons;
  160.     }
  161.     public function addCoupon(Coupon $coupon): self
  162.     {
  163.         if (!$this->coupons->contains($coupon)) {
  164.             $this->coupons[] = $coupon;
  165.             $coupon->setPromotion($this);
  166.         }
  167.         return $this;
  168.     }
  169.     public function removeCoupon(Coupon $coupon): self
  170.     {
  171.         if ($this->coupons->removeElement($coupon)) {
  172.             // set the owning side to null (unless already changed)
  173.             if ($coupon->getPromotion() === $this) {
  174.                 $coupon->setPromotion(null);
  175.             }
  176.         }
  177.         return $this;
  178.     }
  179.     /**
  180.      * @return Collection|PromotionRule[]
  181.      */
  182.     public function getPromotionRules(): Collection
  183.     {
  184.         return $this->promotionRules;
  185.     }
  186.     public function addPromotionRule(PromotionRule $promotionRule): self
  187.     {
  188.         if (!$this->promotionRules->contains($promotionRule)) {
  189.             $this->promotionRules[] = $promotionRule;
  190.             $promotionRule->setPromotion($this);
  191.         }
  192.         return $this;
  193.     }
  194.     public function removePromotionRule(PromotionRule $promotionRule): self
  195.     {
  196.         if ($this->promotionRules->removeElement($promotionRule)) {
  197.             // set the owning side to null (unless already changed)
  198.             if ($promotionRule->getPromotion() === $this) {
  199.                 $promotionRule->setPromotion(null);
  200.             }
  201.         }
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return Collection|PromotionAction[]
  206.      */
  207.     public function getPromotionActions(): Collection
  208.     {
  209.         return $this->promotionActions;
  210.     }
  211.     public function addPromotionAction(PromotionAction $promotionAction): self
  212.     {
  213.         if (!$this->promotionActions->contains($promotionAction)) {
  214.             $this->promotionActions[] = $promotionAction;
  215.             $promotionAction->setPromotion($this);
  216.         }
  217.         return $this;
  218.     }
  219.     public function removePromotionAction(PromotionAction $promotionAction): self
  220.     {
  221.         if ($this->promotionActions->removeElement($promotionAction)) {
  222.             // set the owning side to null (unless already changed)
  223.             if ($promotionAction->getPromotion() === $this) {
  224.                 $promotionAction->setPromotion(null);
  225.             }
  226.         }
  227.         return $this;
  228.     }
  229.     /**
  230.      * @return Collection|Product[]
  231.      */
  232.     public function getProducts(): Collection
  233.     {
  234.         return $this->products;
  235.     }
  236.     public function addProduct(Product $product): self
  237.     {
  238.         if (!$this->products->contains($product)) {
  239.             $this->products[] = $product;
  240.             $product->setPromotion($this);
  241.         }
  242.         return $this;
  243.     }
  244.     public function removeProduct(Product $product): self
  245.     {
  246.         if ($this->products->removeElement($product)) {
  247.             // set the owning side to null (unless already changed)
  248.             if ($product->getPromotion() === $this) {
  249.                 $product->setPromotion(null);
  250.             }
  251.         }
  252.         return $this;
  253.     }
  254.     public function isKeepCurrentPrice(): ?bool
  255.     {
  256.         return $this->keepCurrentPrice;
  257.     }
  258.     public function setKeepCurrentPrice(?bool $keepCurrentPrice): static
  259.     {
  260.         $this->keepCurrentPrice $keepCurrentPrice;
  261.         return $this;
  262.     }
  263.     /**
  264.      * @return Collection<int, CategoryProduct>
  265.      */
  266.     public function getCategories(): Collection
  267.     {
  268.         return $this->categories;
  269.     }
  270.     public function addCategory(CategoryProduct $category): static
  271.     {
  272.         if (!$this->categories->contains($category)) {
  273.             $this->categories->add($category);
  274.             $category->setPromotion($this);
  275.         }
  276.         return $this;
  277.     }
  278.     public function removeCategory(CategoryProduct $category): static
  279.     {
  280.         if ($this->categories->removeElement($category)) {
  281.             // set the owning side to null (unless already changed)
  282.             if ($category->getPromotion() === $this) {
  283.                 $category->setPromotion(null);
  284.             }
  285.         }
  286.         return $this;
  287.     }
  288.     public function getAdjustableValue(): ?float
  289.     {
  290.         return (float)$this->adjustableValue;
  291.     }
  292.     public function setAdjustableValue(?float $adjustableValue): static
  293.     {
  294.         $this->adjustableValue $adjustableValue;
  295.         return $this;
  296.     }
  297. }