src/Flexy/ShopBundle/Entity/Product/CategoryProduct.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Product;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Product\Product;
  5. use App\Flexy\ShopBundle\Repository\Product\CategoryProductRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Doctrine\ORM\Mapping\Table;
  10. /**
  11.  * @ORM\Entity(repositoryClass=CategoryProductRepository::class)
  12.  * @Table(name="flexy_categoryproduct")
  13.  */
  14. #[ApiResource]
  15. class CategoryProduct
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=255)
  25.      */
  26.     private $name;
  27.     /**
  28.      * @ORM\Column(type="text", nullable=true)
  29.      */
  30.     private $description;
  31.     /**
  32.      * @ORM\Column(type="string", length=255, nullable=true)
  33.      */
  34.     private $image;
  35.     /**
  36.      * @ORM\ManyToMany(targetEntity=Product::class, mappedBy="categoriesProduct",cascade={"persist"})
  37.      */
  38.     private $products;
  39.     /**
  40.      * @ORM\ManyToOne(targetEntity=CategoryProduct::class, inversedBy="subCategories")
  41.      */
  42.     private $parentCategory;
  43.     /**
  44.      * @ORM\OneToMany(targetEntity=CategoryProduct::class, mappedBy="parentCategory")
  45.      */
  46.     private $subCategories;
  47.     /**
  48.      * @ORM\ManyToMany(targetEntity=Attribut::class, inversedBy="categoriesProduct")
  49.      */
  50.     private $attributes;
  51.     /**
  52.      * @ORM\Column(type="float", nullable=true)
  53.      */
  54.     private $commission;
  55.     /**
  56.      * @ORM\OneToMany(targetEntity=Product::class, mappedBy="parentCategory")
  57.      */
  58.     private $productsChildrens;
  59.     /**
  60.      * @ORM\Column(type="string", length=255, nullable=true)
  61.      */
  62.     private $forProductType;
  63.     public function __construct()
  64.     {
  65.         $this->products = new ArrayCollection();
  66.         $this->attributes = new ArrayCollection();
  67.         $this->subCategories = new ArrayCollection();
  68.         $this->productsChildrens = new ArrayCollection();
  69.     }
  70.     public function __toString()
  71.     {
  72.         return $this->name;
  73.     }
  74.     public function getId(): ?int
  75.     {
  76.         return $this->id;
  77.     }
  78.     public function getName(): ?string
  79.     {
  80.         return $this->name;
  81.     }
  82.     public function setName(string $name): self
  83.     {
  84.         $this->name $name;
  85.         return $this;
  86.     }
  87.     public function getDescription(): ?string
  88.     {
  89.         return $this->description;
  90.     }
  91.     public function setDescription(?string $description): self
  92.     {
  93.         $this->description $description;
  94.         return $this;
  95.     }
  96.     public function getImage(): ?string
  97.     {
  98.         return $this->image;
  99.     }
  100.     public function setImage(?string $image): self
  101.     {
  102.         $this->image $image;
  103.         return $this;
  104.     }
  105.     /**
  106.      * @return Collection|Product[]
  107.      */
  108.     public function getProducts(): Collection
  109.     {
  110.         return $this->products;
  111.     }
  112.     public function addProduct(Product $product): self
  113.     {
  114.         if (!$this->products->contains($product)) {
  115.             $this->products[] = $product;
  116.         }
  117.         return $this;
  118.     }
  119.     public function removeProduct(Product $product): self
  120.     {
  121.         $this->products->removeElement($product);
  122.         return $this;
  123.     }
  124.     public function getParentCategory(): ?self
  125.     {
  126.         return $this->parentCategory;
  127.     }
  128.     public function setParentCategory(?self $parentCategory): self
  129.     {
  130.         $this->parentCategory $parentCategory;
  131.         return $this;
  132.     }
  133.     /**
  134.      * Get the value of subCategories
  135.      */ 
  136.     public function getSubCategories()
  137.     {
  138.         return $this->subCategories;
  139.     }
  140.     /**
  141.      * Set the value of subCategories
  142.      *
  143.      * @return  self
  144.      */ 
  145.     public function setSubCategories($subCategories)
  146.     {
  147.         $this->subCategories $subCategories;
  148.         return $this;
  149.     }
  150.     /**
  151.      * @return Collection|Attribut[]
  152.      */
  153.     public function getAttributes(): Collection
  154.     {
  155.         return $this->attributes;
  156.     }
  157.     public function addAttribute(Attribut $attribute): self
  158.     {
  159.         if (!$this->attributes->contains($attribute)) {
  160.             $this->attributes[] = $attribute;
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeAttribute(Attribut $attribute): self
  165.     {
  166.         $this->attributes->removeElement($attribute);
  167.         return $this;
  168.     }
  169.     public function getCommission(): ?float
  170.     {
  171.         return $this->commission;
  172.     }
  173.   
  174.     public function setCommission(?float $commission): self
  175.     {
  176.         $this->commission $commission;
  177.         return $this;
  178.     }
  179.     public function addSubCategory(CategoryProduct $subCategory): self
  180.     {
  181.         if (!$this->subCategories->contains($subCategory)) {
  182.             $this->subCategories[] = $subCategory;
  183.             $subCategory->setParentCategory($this);
  184.         }
  185.         return $this;
  186.     }
  187.     public function removeSubCategory(CategoryProduct $subCategory): self
  188.     {
  189.         if ($this->subCategories->removeElement($subCategory)) {
  190.             // set the owning side to null (unless already changed)
  191.             if ($subCategory->getParentCategory() === $this) {
  192.                 $subCategory->setParentCategory(null);
  193.             }
  194.         }
  195.         return $this;
  196.     }
  197.     /**
  198.      * @return Collection<int, Product>
  199.      */
  200.     public function getProductsChildrens(): Collection
  201.     {
  202.         return $this->productsChildrens;
  203.     }
  204.     public function addProductsChildren(Product $productsChildren): self
  205.     {
  206.         if (!$this->productsChildrens->contains($productsChildren)) {
  207.             $this->productsChildrens[] = $productsChildren;
  208.             $productsChildren->setParentCategory($this);
  209.         }
  210.         return $this;
  211.     }
  212.     public function removeProductsChildren(Product $productsChildren): self
  213.     {
  214.         if ($this->productsChildrens->removeElement($productsChildren)) {
  215.             // set the owning side to null (unless already changed)
  216.             if ($productsChildren->getParentCategory() === $this) {
  217.                 $productsChildren->setParentCategory(null);
  218.             }
  219.         }
  220.         return $this;
  221.     }
  222.     public function getForProductType(): ?string
  223.     {
  224.         return $this->forProductType;
  225.     }
  226.     public function setForProductType(?string $forProductType): self
  227.     {
  228.         $this->forProductType $forProductType;
  229.         return $this;
  230.     }
  231. }