src/Entity/Product.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProductRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassProductRepository::class)]
  9. class Product
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $slug null;
  17.     #[ORM\Column(length255)]
  18.     private ?string $sku null;
  19.     #[ORM\Column(length255nullabletrue)]
  20.     private ?string $barcode null;
  21.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  22.     private ?string $description null;
  23.     #[ORM\Column]
  24.     private array $images = [];
  25.     #[ORM\Column(nullabletrue)]
  26.     private ?array $videos null;
  27.     #[ORM\Column(nullabletrue)]
  28.     private ?array $documents null;
  29.     #[ORM\Column]
  30.     private ?float $price null;
  31.     #[ORM\Column(nullabletrue)]
  32.     private ?float $compareAtPrice null;
  33.     #[ORM\Column]
  34.     private ?int $stock null;
  35.     #[ORM\Column]
  36.     private ?int $minStockAlert null;
  37.     #[ORM\Column]
  38.     private ?bool $manageStock null;
  39.     #[ORM\Column]
  40.     private ?bool $allowBackorders null;
  41.     #[ORM\Column(length20)]
  42.     private ?string $stockStatus null;
  43.     #[ORM\Column(nullabletrue)]
  44.     private ?float $weight null;
  45.     #[ORM\Column(nullabletrue)]
  46.     private ?float $length null;
  47.     #[ORM\Column(nullabletrue)]
  48.     private ?float $width null;
  49.     #[ORM\Column(nullabletrue)]
  50.     private ?float $height null;
  51.     #[ORM\Column]
  52.     private ?bool $isDigital null;
  53.     #[ORM\Column(length255nullabletrue)]
  54.     private ?string $digitalFile null;
  55.     #[ORM\Column(nullabletrue)]
  56.     private ?array $attributes null;
  57.     #[ORM\Column(nullabletrue)]
  58.     private ?array $variations null;
  59.     #[ORM\Column]
  60.     private ?bool $isActive null;
  61.     #[ORM\Column]
  62.     private ?bool $isFeatured null;
  63.     #[ORM\Column]
  64.     private ?\DateTimeImmutable $publishedAt null;
  65.     #[ORM\Column(nullabletrue)]
  66.     private ?\DateTimeImmutable $availableFrom null;
  67.     #[ORM\Column(nullabletrue)]
  68.     private ?\DateTimeImmutable $availableTo null;
  69.     #[ORM\Column(length255nullabletrue)]
  70.     private ?string $metaTitle null;
  71.     #[ORM\Column(length255nullabletrue)]
  72.     private ?string $metaDescription null;
  73.     #[ORM\Column(length255nullabletrue)]
  74.     private ?string $metaKeywords null;
  75.     #[ORM\Column]
  76.     private ?int $viewCount null;
  77.     #[ORM\Column]
  78.     private ?int $salesCount null;
  79.     #[ORM\Column]
  80.     private ?float $averageRating null;
  81.     #[ORM\Column]
  82.     private ?int $reviewCount null;
  83.     #[ORM\Column(nullabletrue)]
  84.     private ?array $tierPrices null// [{min:int, price:float}, ...]
  85.     #[ORM\Column(options: ["default" => false])]
  86.     private ?bool $hasTierPricing false;
  87.     #[ORM\ManyToOne(inversedBy'products')]
  88.     #[ORM\JoinColumn(nullablefalse)]
  89.     private ?Shop $shop null;
  90.     #[ORM\ManyToOne(inversedBy'products')]
  91.     #[ORM\JoinColumn(nullablefalse)]
  92.     private ?Category $category null;
  93.     #[ORM\ManyToOne(inversedBy'products')]
  94.     #[ORM\JoinColumn(nullabletrue)]
  95.     private ?Brand $brand null;
  96.     #[ORM\ManyToOne(inversedBy'products')]
  97.     #[ORM\JoinColumn(nullabletrue)]
  98.     private ?ProductCondition $condition null;
  99.     #[ORM\OneToMany(targetEntityProductRanking::class, mappedBy'product')]
  100.     private Collection $rankings;
  101.     #[ORM\OneToMany(targetEntityProductVariant::class, mappedBy'product'cascade: ['persist''remove'])]
  102.     private Collection $variants;
  103.     #[ORM\OneToMany(targetEntityProductDetail::class, mappedBy'product'cascade: ['persist''remove'])]
  104.     private Collection $details;
  105.     #[ORM\Column(length255)]
  106.     private ?string $name null;
  107.     public function __construct()
  108.     {
  109.         $this->variants = new ArrayCollection();
  110.         $this->details = new ArrayCollection();
  111.     }
  112.     public function getId(): ?int
  113.     {
  114.         return $this->id;
  115.     }
  116.     public function getSlug(): ?string
  117.     {
  118.         return $this->slug;
  119.     }
  120.     public function setSlug(string $slug): static
  121.     {
  122.         $this->slug $slug;
  123.         return $this;
  124.     }
  125.     public function getSku(): ?string
  126.     {
  127.         return $this->sku;
  128.     }
  129.     public function setSku(string $sku): static
  130.     {
  131.         $this->sku $sku;
  132.         return $this;
  133.     }
  134.     public function getBarcode(): ?string
  135.     {
  136.         return $this->barcode;
  137.     }
  138.     public function setBarcode(?string $barcode): static
  139.     {
  140.         $this->barcode $barcode;
  141.         return $this;
  142.     }
  143.     public function getDescription(): ?string
  144.     {
  145.         return $this->description;
  146.     }
  147.     public function setDescription(?string $description): static
  148.     {
  149.         $this->description $description;
  150.         return $this;
  151.     }
  152.     public function getImages(): array
  153.     {
  154.         return $this->images;
  155.     }
  156.     public function setImages(array $images): static
  157.     {
  158.         $this->images $images;
  159.         return $this;
  160.     }
  161.     public function getVideos(): ?array
  162.     {
  163.         return $this->videos;
  164.     }
  165.     public function setVideos(?array $videos): static
  166.     {
  167.         $this->videos $videos;
  168.         return $this;
  169.     }
  170.     public function getDocuments(): ?array
  171.     {
  172.         return $this->documents;
  173.     }
  174.     public function setDocuments(?array $documents): static
  175.     {
  176.         $this->documents $documents;
  177.         return $this;
  178.     }
  179.     public function getPrice(): ?float
  180.     {
  181.         return $this->price;
  182.     }
  183.     public function setPrice(float $price): static
  184.     {
  185.         $this->price $price;
  186.         return $this;
  187.     }
  188.     public function getCompareAtPrice(): ?float
  189.     {
  190.         return $this->compareAtPrice;
  191.     }
  192.     public function setCompareAtPrice(?float $compareAtPrice): static
  193.     {
  194.         $this->compareAtPrice $compareAtPrice;
  195.         return $this;
  196.     }
  197.     public function getStock(): ?int
  198.     {
  199.         return $this->stock;
  200.     }
  201.     public function setStock(int $stock): static
  202.     {
  203.         $this->stock $stock;
  204.         return $this;
  205.     }
  206.     public function getMinStockAlert(): ?int
  207.     {
  208.         return $this->minStockAlert;
  209.     }
  210.     public function setMinStockAlert(int $minStockAlert): static
  211.     {
  212.         $this->minStockAlert $minStockAlert;
  213.         return $this;
  214.     }
  215.     public function isManageStock(): ?bool
  216.     {
  217.         return $this->manageStock;
  218.     }
  219.     public function setManageStock(bool $manageStock): static
  220.     {
  221.         $this->manageStock $manageStock;
  222.         return $this;
  223.     }
  224.     public function isAllowBackorders(): ?bool
  225.     {
  226.         return $this->allowBackorders;
  227.     }
  228.     public function setAllowBackorders(bool $allowBackorders): static
  229.     {
  230.         $this->allowBackorders $allowBackorders;
  231.         return $this;
  232.     }
  233.     public function getStockStatus(): ?string
  234.     {
  235.         return $this->stockStatus;
  236.     }
  237.     public function setStockStatus(string $stockStatus): static
  238.     {
  239.         $this->stockStatus $stockStatus;
  240.         return $this;
  241.     }
  242.     public function getWeight(): ?float
  243.     {
  244.         return $this->weight;
  245.     }
  246.     public function setWeight(?float $weight): static
  247.     {
  248.         $this->weight $weight;
  249.         return $this;
  250.     }
  251.     public function getLength(): ?float
  252.     {
  253.         return $this->length;
  254.     }
  255.     public function setLength(?float $length): static
  256.     {
  257.         $this->length $length;
  258.         return $this;
  259.     }
  260.     public function getWidth(): ?float
  261.     {
  262.         return $this->width;
  263.     }
  264.     public function setWidth(?float $width): static
  265.     {
  266.         $this->width $width;
  267.         return $this;
  268.     }
  269.     public function getHeight(): ?float
  270.     {
  271.         return $this->height;
  272.     }
  273.     public function setHeight(?float $height): static
  274.     {
  275.         $this->height $height;
  276.         return $this;
  277.     }
  278.     public function isIsDigital(): ?bool
  279.     {
  280.         return $this->isDigital;
  281.     }
  282.     public function setIsDigital(bool $isDigital): static
  283.     {
  284.         $this->isDigital $isDigital;
  285.         return $this;
  286.     }
  287.     public function getDigitalFile(): ?string
  288.     {
  289.         return $this->digitalFile;
  290.     }
  291.     public function setDigitalFile(?string $digitalFile): static
  292.     {
  293.         $this->digitalFile $digitalFile;
  294.         return $this;
  295.     }
  296.     public function getAttributes(): ?array
  297.     {
  298.         return $this->attributes;
  299.     }
  300.     public function setAttributes(?array $attributes): static
  301.     {
  302.         $this->attributes $attributes;
  303.         return $this;
  304.     }
  305.     public function getVariations(): ?array
  306.     {
  307.         return $this->variations;
  308.     }
  309.     public function setVariations(?array $variations): static
  310.     {
  311.         $this->variations $variations;
  312.         return $this;
  313.     }
  314.     public function isIsActive(): ?bool
  315.     {
  316.         return $this->isActive;
  317.     }
  318.     public function setIsActive(bool $isActive): static
  319.     {
  320.         $this->isActive $isActive;
  321.         return $this;
  322.     }
  323.     public function isIsFeatured(): ?bool
  324.     {
  325.         return $this->isFeatured;
  326.     }
  327.     public function setIsFeatured(bool $isFeatured): static
  328.     {
  329.         $this->isFeatured $isFeatured;
  330.         return $this;
  331.     }
  332.     public function getPublishedAt(): ?\DateTimeImmutable
  333.     {
  334.         return $this->publishedAt;
  335.     }
  336.     public function setPublishedAt(\DateTimeImmutable $publishedAt): static
  337.     {
  338.         $this->publishedAt $publishedAt;
  339.         return $this;
  340.     }
  341.     public function getAvailableFrom(): ?\DateTimeImmutable
  342.     {
  343.         return $this->availableFrom;
  344.     }
  345.     public function setAvailableFrom(?\DateTimeImmutable $availableFrom): static
  346.     {
  347.         $this->availableFrom $availableFrom;
  348.         return $this;
  349.     }
  350.     public function getAvailableTo(): ?\DateTimeImmutable
  351.     {
  352.         return $this->availableTo;
  353.     }
  354.     public function setAvailableTo(?\DateTimeImmutable $availableTo): static
  355.     {
  356.         $this->availableTo $availableTo;
  357.         return $this;
  358.     }
  359.     public function getMetaTitle(): ?string
  360.     {
  361.         return $this->metaTitle;
  362.     }
  363.     public function setMetaTitle(?string $metaTitle): static
  364.     {
  365.         $this->metaTitle $metaTitle;
  366.         return $this;
  367.     }
  368.     public function getMetaDescription(): ?string
  369.     {
  370.         return $this->metaDescription;
  371.     }
  372.     public function setMetaDescription(?string $metaDescription): static
  373.     {
  374.         $this->metaDescription $metaDescription;
  375.         return $this;
  376.     }
  377.     public function getMetaKeywords(): ?string
  378.     {
  379.         return $this->metaKeywords;
  380.     }
  381.     public function setMetaKeywords(?string $metaKeywords): static
  382.     {
  383.         $this->metaKeywords $metaKeywords;
  384.         return $this;
  385.     }
  386.     public function getViewCount(): ?int
  387.     {
  388.         return $this->viewCount;
  389.     }
  390.     public function setViewCount(int $viewCount): static
  391.     {
  392.         $this->viewCount $viewCount;
  393.         return $this;
  394.     }
  395.     public function getSalesCount(): ?int
  396.     {
  397.         return $this->salesCount;
  398.     }
  399.     public function setSalesCount(int $salesCount): static
  400.     {
  401.         $this->salesCount $salesCount;
  402.         return $this;
  403.     }
  404.     public function getAverageRating(): ?float
  405.     {
  406.         return $this->averageRating;
  407.     }
  408.     public function setAverageRating(float $averageRating): static
  409.     {
  410.         $this->averageRating $averageRating;
  411.         return $this;
  412.     }
  413.     public function getReviewCount(): ?int
  414.     {
  415.         return $this->reviewCount;
  416.     }
  417.     public function setReviewCount(int $reviewCount): static
  418.     {
  419.         $this->reviewCount $reviewCount;
  420.         return $this;
  421.     }
  422.     public function getTierPrices(): ?array
  423.     {
  424.         return $this->tierPrices;
  425.     }
  426.     public function setTierPrices(?array $tierPrices): static
  427.     {
  428.         $this->tierPrices $tierPrices;
  429.         return $this;
  430.     }
  431.     public function hasTierPricing(): ?bool
  432.     {
  433.         return $this->hasTierPricing;
  434.     }
  435.     public function setHasTierPricing(bool $hasTierPricing): static
  436.     {
  437.         $this->hasTierPricing $hasTierPricing;
  438.         return $this;
  439.     }
  440.     public function getShop(): ?Shop
  441.     {
  442.         return $this->shop;
  443.     }
  444.     public function setShop(?Shop $shop): static
  445.     {
  446.         $this->shop $shop;
  447.         return $this;
  448.     }
  449.     public function getCategory(): ?Category
  450.     {
  451.         return $this->category;
  452.     }
  453.     public function setCategory(?Category $category): static
  454.     {
  455.         $this->category $category;
  456.         return $this;
  457.     }
  458.     public function getBrand(): ?Brand
  459.     {
  460.         return $this->brand;
  461.     }
  462.     public function setBrand(?Brand $brand): static
  463.     {
  464.         $this->brand $brand;
  465.         return $this;
  466.     }
  467.     public function getCondition(): ?ProductCondition
  468.     {
  469.         return $this->condition;
  470.     }
  471.     public function setCondition(?ProductCondition $condition): static
  472.     {
  473.         $this->condition $condition;
  474.         return $this;
  475.     }
  476.     /**
  477.      * @return Collection<int, ProductRanking>
  478.      */
  479.     public function getRankings(): Collection
  480.     {
  481.         return $this->rankings;
  482.     }
  483.     public function addRanking(ProductRanking $ranking): static
  484.     {
  485.         if (!$this->rankings->contains($ranking)) {
  486.             $this->rankings->add($ranking);
  487.             $ranking->setProduct($this);
  488.         }
  489.         return $this;
  490.     }
  491.     public function removeRanking(ProductRanking $ranking): static
  492.     {
  493.         if ($this->rankings->removeElement($ranking)) {
  494.             if ($ranking->getProduct() === $this) {
  495.                 $ranking->setProduct(null);
  496.             }
  497.         }
  498.         return $this;
  499.     }
  500.     /**
  501.      * Obtenir le rang dans une catégorie spécifique
  502.      */
  503.     public function getRankInCategory(Category $category): ?int
  504.     {
  505.         foreach ($this->rankings as $ranking) {
  506.             if ($ranking->getCategory() === $category) {
  507.                 return $ranking->getRank();
  508.             }
  509.         }
  510.         return null;
  511.     }
  512.     /**
  513.      * Obtenir le meilleur rang du produit
  514.      */
  515.     public function getBestRank(): ?int
  516.     {
  517.         $bestRank null;
  518.         foreach ($this->rankings as $ranking) {
  519.             if ($bestRank === null || $ranking->getRank() < $bestRank) {
  520.                 $bestRank $ranking->getRank();
  521.             }
  522.         }
  523.         return $bestRank;
  524.     }
  525.     /**
  526.      * @return Collection<int, ProductVariant>
  527.      */
  528.     public function getVariants(): Collection
  529.     {
  530.         return $this->variants;
  531.     }
  532.     public function addVariant(ProductVariant $variant): static
  533.     {
  534.         if (!$this->variants->contains($variant)) {
  535.             $this->variants->add($variant);
  536.             $variant->setProduct($this);
  537.         }
  538.         return $this;
  539.     }
  540.     public function removeVariant(ProductVariant $variant): static
  541.     {
  542.         if ($this->variants->removeElement($variant)) {
  543.             if ($variant->getProduct() === $this) {
  544.                 $variant->setProduct(null);
  545.             }
  546.         }
  547.         return $this;
  548.     }
  549.     /**
  550.      * Obtenir la variante par défaut
  551.      */
  552.     public function getDefaultVariant(): ?ProductVariant
  553.     {
  554.         foreach ($this->variants as $variant) {
  555.             if ($variant->isIsDefault() && $variant->isIsActive()) {
  556.                 return $variant;
  557.             }
  558.         }
  559.         return $this->variants->first() ?: null;
  560.     }
  561.     /**
  562.      * Vérifier si le produit a des variantes
  563.      */
  564.     public function hasVariants(): bool
  565.     {
  566.         return $this->variants->count() > 0;
  567.     }
  568.     /**
  569.      * @return Collection<int, ProductDetail>
  570.      */
  571.     public function getDetails(): Collection
  572.     {
  573.         return $this->details;
  574.     }
  575.     public function addDetail(ProductDetail $detail): static
  576.     {
  577.         if (!$this->details->contains($detail)) {
  578.             $this->details->add($detail);
  579.             $detail->setProduct($this);
  580.         }
  581.         return $this;
  582.     }
  583.     public function removeDetail(ProductDetail $detail): static
  584.     {
  585.         if ($this->details->removeElement($detail)) {
  586.             if ($detail->getProduct() === $this) {
  587.                 $detail->setProduct(null);
  588.             }
  589.         }
  590.         return $this;
  591.     }
  592.     public function getName(): ?string
  593.     {
  594.         return $this->name;
  595.     }
  596.     public function setName(string $name): static
  597.     {
  598.         $this->name $name;
  599.         return $this;
  600.     }
  601. }