src/Flexy/ShopBundle/Entity/Product/Product.php line 39
<?phpnamespace App\Flexy\ShopBundle\Entity\Product;use ApiPlatform\Core\Annotation\ApiResource;use App\Flexy\ShopBundle\Entity\Brand;use App\Flexy\ShopBundle\Entity\Order\OrderItem;use App\Flexy\ShopBundle\Entity\Product\CategoryProduct;use App\Flexy\ShopBundle\Entity\Promotion\Promotion;use App\Flexy\ShopBundle\Entity\Store\Store;use App\Flexy\ShopBundle\Entity\Vendor\Vendor;use App\Flexy\ShopBundle\Repository\Product\ProductRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Doctrine\ORM\Mapping\Table;use Doctrine\ORM\Mapping\Entity;use Doctrine\ORM\Mapping\InheritanceType;use Gedmo\Mapping\Annotation as Gedmo;use Symfony\Component\Filesystem\Filesystem;use Symfony\Component\Serializer\Annotation\Groups;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;#[ApiResource(normalizationContext: ['groups' => ['read']],denormalizationContext: ['groups' => ['write']],)]#[Table(name: 'product')]#[ORM\Entity(repositoryClass: ProductRepository::class)]#[InheritanceType('JOINED')]#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]#[Gedmo\Tree(type: 'nested')]#[UniqueEntity(fields: ['name'],message: 'Ce produit avec ce nom est déja existe, utilisez un autre nom pour ce produit.',)]class Product implements \Stringable{#[Groups(['read', 'readDeep'])]#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column(type: 'integer')]private $id;#[Groups(['read', 'readDeep'])]#[ORM\Column(type: 'string', length: 255)]private ?string $name = null;#[Groups(['read', 'readDeep'])]#[ORM\Column(type: 'string', length: 255,nullable:true)]private string|null $image = "" ;#[Groups(['read', 'readDeep'])]#[ORM\Column(type: 'float',nullable:true)]private ?float $price = 0;#[Groups(['read', 'readDeep'])]#[ORM\Column(type: 'text', nullable: true)]private ?string $description = null;#[ORM\ManyToMany(targetEntity: CategoryProduct::class, inversedBy: 'products', cascade: ['persist'])]private $categoriesProduct;#[ORM\OneToMany(targetEntity: AttributValue::class, mappedBy: 'product', cascade: ['persist'])]#[Groups(['read', 'readDeep'])]private $attributValues;#[Groups(['read', 'readDeep'])]#[ORM\Column(type: 'float', nullable: true)]private ?float $oldPrice = null;#[Groups(['read', 'readDeep'])]#[ORM\Column(type: 'integer', nullable: true)]private ?int $quantity = null;#[Groups(['read', 'readDeep'])]#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $productType = "simple";#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $metaTitle = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $metaDescription = null;#[ORM\Column(type: 'simple_array', nullable: true)]private ?array $metaKeywords = [];#[ORM\OneToMany(targetEntity: ImageProduct::class, mappedBy: 'product', cascade: ['persist'])]private $images;/*** @Gedmo\Slug(fields={"name"})*/#[ORM\Column(type: 'string', length: 255)]private ?string $slug = null;#[ORM\Column(type: 'datetime_immutable', nullable: true)]private ?\DateTimeImmutable $createdAt = null;#[ORM\OneToMany(targetEntity: ProductVariant::class, mappedBy: 'product', cascade: ['persist'])]private $productVariants;#[ORM\Column(type: 'boolean', nullable: true)]private ?bool $isPriceReducedPerPercent = null;#[ORM\Column(type: 'float', nullable: true)]private ?float $percentReduction = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $skuCode = null;#[ORM\OneToMany(targetEntity: OrderItem::class, mappedBy: 'product', cascade: ['persist'])]private $orderItems;#[ORM\ManyToOne(targetEntity: Promotion::class, inversedBy: 'products')]private ?\App\Flexy\ShopBundle\Entity\Promotion\Promotion $promotion = null;#[ORM\ManyToOne(targetEntity: Vendor::class, inversedBy: 'products')]private ?\App\Flexy\ShopBundle\Entity\Vendor\Vendor $vendor = null;#[ORM\ManyToOne(targetEntity: Brand::class, inversedBy: 'products', cascade: ['persist'])]private ?\App\Flexy\ShopBundle\Entity\Brand $brand = null;#[ORM\Column(type: 'text', nullable: true)]private ?string $shortDescription = null;#[ORM\Column(type: 'boolean', nullable: true)]private ?bool $isPublished = true;#[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'product')]private $comments;#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $skuCodeShop = null;#[ORM\Column(type: 'datetime_immutable', nullable: true)]private ?\DateTimeImmutable $endAt = null;#[ORM\ManyToOne(targetEntity: CategoryProduct::class, inversedBy: 'productsChildrens')]private ?\App\Flexy\ShopBundle\Entity\Product\CategoryProduct $parentCategory = null;#[ORM\ManyToOne(targetEntity: Product::class)]private ?\App\Flexy\ShopBundle\Entity\Product\Product $clonedProduct = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $typeReduction = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $valueReduction = null;#[ORM\OneToMany(mappedBy: 'product', targetEntity: ProductSubscription::class, orphanRemoval: true)]private Collection $productSubscriptions;#[ORM\Column(nullable: true)]private ?float $subscriptionMonthlyPrice = null;#[ORM\Column(nullable: true)]private ?float $subscriptionYearlyPrice = null;#[ORM\ManyToOne(inversedBy: 'products')]private ?Store $store = null;#[ORM\Column(nullable: true)]private ?\DateTimeImmutable $deletedAt = null;#[ORM\OneToMany(mappedBy: 'parentProduct', targetEntity: ProductPack::class, orphanRemoval: true,cascade:["persist","remove"])]private Collection $childrenProductsPack;#[ORM\Column(nullable: true)]#[Groups(['read', 'readDeep'])]private ?bool $labelPriceFrom = null;#[ORM\Column(nullable: true)]private ?int $subscriptionDuration = null;public function __construct(){$this->categoriesProduct = new ArrayCollection();$this->attributValues = new ArrayCollection();$this->createdAt = new \DateTimeImmutable();$this->images = new ArrayCollection();$this->productVariants = new ArrayCollection();$this->orderItems = new ArrayCollection();$this->comments = new ArrayCollection();$this->productSubscriptions = new ArrayCollection();$this->childrenProductsPack = new ArrayCollection();}public function __toString(): string{return (string) $this->name;}public function getId(): ?int{return $this->id;}#[Groups(['read', 'readDeep'])]public function getCategoriesByName(){$categories = [];foreach($this->categoriesProduct as $singleCategory){$categories[]=$singleCategory->getName();}return $categories;}public function setId($id=null): self{$this->id = $id;return $this;}public function getName(): ?string{return $this->name;}public function setName(string $name): self{$this->name = $name;return $this;}public function getPrice(): ?float{return $this->price;}public function getReduction(): ?float{$reduction = null;if($this->typeReduction and $this->valueReduction){if($this->typeReduction == "percent"){$reduction = ((float)$this->price / 100) * $this->valueReduction;}else{$reduction = $this->valueReduction ;}}return $reduction;}public function setPrice(float $price): self{$this->price = $price;return $this;}public function getDescription(): ?string{return $this->description;}public function setDescription(?string $description): self{$this->description = $description;return $this;}/*** Get the value of image*/public function getImage(){return $this->image;}/*** Set the value of image*/public function setImage($image){$this->image = (string)$image;return $this;}/*** @return Collection|CategoryProduct[]*/public function getCategoriesProduct(): Collection{return $this->categoriesProduct;}public function addCategoryProduct(CategoryProduct $categoryProduct): self{if (!$this->categoriesProduct->contains($categoryProduct)) {$this->categoriesProduct[] = $categoryProduct;$categoryProduct->addProduct($this);}return $this;}public function removeCategoryProduct(CategoryProduct $categoryProduct): self{if ($this->categoriesProduct->removeElement($categoryProduct)) {$categoryProduct->removeProduct($this);}return $this;}/*** @return Collection|AttributValue[]*/public function getAttributValues(): Collection{return $this->attributValues;}public function addAttributValue(AttributValue $attributValue): self{if (!$this->attributValues->contains($attributValue)) {$this->attributValues[] = $attributValue;$attributValue->setProduct($this);}return $this;}public function removeAttributValue(AttributValue $attributValue): self{if ($this->attributValues->removeElement($attributValue)) {// set the owning side to null (unless already changed)if ($attributValue->getProduct() === $this) {$attributValue->setProduct(null);}}return $this;}public function getOldPrice(): ?float{return $this->oldPrice;}public function setOldPrice(?float $oldPrice): self{$this->oldPrice = $oldPrice;return $this;}public function getQuantity(): ?int{return $this->quantity;}public function setQuantity(?int $quantity): self{$this->quantity = $quantity;return $this;}public function getProductType(): ?string{return $this->productType;}public function setProductType(?string $productType): self{$this->productType = $productType;return $this;}public function getMetaTitle(): ?string{return $this->metaTitle;}public function setMetaTitle(?string $metaTitle): self{$this->metaTitle = $metaTitle;return $this;}public function getMetaDescription(): ?string{return $this->metaDescription;}public function setMetaDescription(?string $metaDescription): self{$this->metaDescription = $metaDescription;return $this;}public function getMetaKeywords(): ?array{return $this->metaKeywords;}public function setMetaKeywords(?array $metaKeywords): self{$this->metaKeywords = $metaKeywords;return $this;}/*** @return Collection|ImageProduct[]*/public function getImages(): Collection{return $this->images;}public function addImage(ImageProduct $image): self{if (!$this->images->contains($image)) {$this->images[] = $image;$image->setProduct($this);}return $this;}public function removeImage(ImageProduct $image): self{if ($this->images->removeElement($image)) {// set the owning side to null (unless already changed)if ($image->getProduct() === $this) {$image->setProduct(null);}}return $this;}public function getSlug(): ?string{return $this->slug;}public function setSlug(string $slug): self{$this->slug = $slug;return $this;}public function getCreatedAt(): ?\DateTimeImmutable{return $this->createdAt;}public function setCreatedAt(?\DateTimeImmutable $createdAt): self{$this->createdAt = $createdAt;return $this;}/*** @return Collection|ProductVariant[]*/public function getProductVariants(): Collection{return $this->productVariants;}public function addProductVariant(ProductVariant $productVariant): self{if (!$this->productVariants->contains($productVariant)) {$this->productVariants[] = $productVariant;$productVariant->setProduct($this);}return $this;}public function removeProductVariant(ProductVariant $productVariant): self{if ($this->productVariants->removeElement($productVariant)) {// set the owning side to null (unless already changed)if ($productVariant->getProduct() === $this) {$productVariant->setProduct(null);}}return $this;}public function getIsPriceReducedPerPercent(): ?bool{return $this->isPriceReducedPerPercent;}public function setIsPriceReducedPerPercent(?bool $isPriceReducedPerPercent): self{$this->isPriceReducedPerPercent = $isPriceReducedPerPercent;return $this;}public function getPercentReduction(): ?float{return $this->percentReduction;}public function setPercentReduction(?float $percentReduction): self{$this->percentReduction = $percentReduction;return $this;}public function getSkuCode(): ?string{return $this->skuCode;}public function setSkuCode(?string $skuCode): self{$this->skuCode = $skuCode;return $this;}/*** @return Collection|OrderItem[]*/public function getOrderItems(): Collection{return $this->orderItems;}public function addOrderItem(OrderItem $orderItem): self{if (!$this->orderItems->contains($orderItem)) {$this->orderItems[] = $orderItem;$orderItem->setProduct($this);}return $this;}public function removeOrderItem(OrderItem $orderItem): self{if ($this->orderItems->removeElement($orderItem)) {// set the owning side to null (unless already changed)if ($orderItem->getProduct() === $this) {$orderItem->setProduct(null);}}return $this;}public function getPromotion(): ?Promotion{return $this->promotion;}public function setPromotion(?Promotion $promotion): self{$this->promotion = $promotion;return $this;}public function getFormattedPrice(){return $this->price ;}public function getVendor(): ?Vendor{return $this->vendor;}public function setVendor(?Vendor $vendor): self{$this->vendor = $vendor;return $this;}public function getBrand(): ?Brand{return $this->brand;}public function setBrand(?Brand $brand): self{$this->brand = $brand;return $this;}public function getShortDescription(): ?string{return $this->shortDescription;}public function setShortDescription(?string $shortDescription): self{$this->shortDescription = $shortDescription;return $this;}public function getIsPublished(): ?bool{return $this->isPublished;}public function setIsPublished(?bool $isPublished): self{$this->isPublished = $isPublished;return $this;}/*** @return Collection|Comment[]*/public function getComments(): Collection{return $this->comments;}public function addComment(Comment $comment): self{if (!$this->comments->contains($comment)) {$this->comments[] = $comment;$comment->setProduct($this);}return $this;}public function removeComment(Comment $comment): self{if ($this->comments->removeElement($comment)) {// set the owning side to null (unless already changed)if ($comment->getProduct() === $this) {$comment->setProduct(null);}}return $this;}public function getStars5(){//for 5 stars$stars5=0;foreach($this->comments as $singleComment){if($singleComment->getRating() == 5){$stars5 = $stars5 + 1;}}return $stars5;}public function getStars4(){//for 4 stars$stars4=0;foreach($this->comments as $singleComment){if($singleComment->getRating() == 4){$stars4 = $stars4 + 1;}}return $stars4;}public function getStars3(){//for 3 stars$stars3=0;foreach($this->comments as $singleComment){if($singleComment->getRating() == 3){$stars3 = $stars3 + 1;}}return $stars3;}public function getStars2(){//for 2 stars$stars2=0;foreach($this->comments as $singleComment){if($singleComment->getRating() == 2){$stars2 = $stars2 + 1;}}return $stars2;}public function getStars1(){//for 5 stars$stars1=0;foreach($this->comments as $singleComment){if($singleComment->getRating() == 1){$stars1 = $stars1 + 1;}}return $stars1;}public function getRating(){$topRating = 0;$totalRating=0;$stars5 = $this->getStars5();$stars4 = $this->getStars4();$stars3 = $this->getStars3();$stars2 = $this->getStars2();$stars1 = $this->getStars1();$topRating = ($stars1 * 1 ) + ($stars2 * 2 ) + ($stars3 * 3 ) + ($stars4 * 4 )+ ($stars5 * 5 );$totalRating = $stars1 + $stars2 +$stars3 + $stars4 + $stars5;$result = 0;if($totalRating > 0){$result = $topRating / $totalRating;}return $result;}public function getSkuCodeShop(): ?string{if(!$this->skuCodeShop){return $this->skuCodeShop = "OM".$this->createdAt->format("ymdhs").$this->id;}return $this->skuCodeShop;}public function setSkuCodeShop(?string $skuCodeShop): self{$this->skuCodeShop = $skuCodeShop;return $this;}public function addCategoriesProduct(CategoryProduct $categoriesProduct): self{if (!$this->categoriesProduct->contains($categoriesProduct)) {$this->categoriesProduct[] = $categoriesProduct;}return $this;}public function removeCategoriesProduct(CategoryProduct $categoriesProduct): self{$this->categoriesProduct->removeElement($categoriesProduct);return $this;}public function getEndAt(): ?\DateTimeImmutable{return $this->endAt;}public function setEndAt(?\DateTimeImmutable $endAt): self{$this->endAt = $endAt;return $this;}public function getParentCategory(): ?CategoryProduct{return $this->parentCategory;}public function setParentCategory(?CategoryProduct $parentCategory): self{$this->parentCategory = $parentCategory;return $this;}public function getClonedProduct(): ?self{return $this->clonedProduct;}public function setClonedProduct(?self $clonedProduct): self{$this->clonedProduct = $clonedProduct;return $this;}public function getTypeReduction(): ?string{return $this->typeReduction;}public function setTypeReduction(?string $typeReduction): self{$this->typeReduction = $typeReduction;return $this;}public function getValueReduction(): ?string{return $this->valueReduction;}public function setValueReduction(?string $valueReduction): self{$this->valueReduction = $valueReduction;return $this;}/*** @return Collection<int, ProductSubscription>*/public function getProductSubscriptions(): Collection{return $this->productSubscriptions;}public function addProductSubscription(ProductSubscription $productSubscription): self{if (!$this->productSubscriptions->contains($productSubscription)) {$this->productSubscriptions->add($productSubscription);$productSubscription->setProduct($this);}return $this;}public function removeProductSubscription(ProductSubscription $productSubscription): self{if ($this->productSubscriptions->removeElement($productSubscription)) {// set the owning side to null (unless already changed)if ($productSubscription->getProduct() === $this) {$productSubscription->setProduct(null);}}return $this;}public function getSubscriptionMonthlyPrice(): ?float{return $this->subscriptionMonthlyPrice;}public function setSubscriptionMonthlyPrice(?float $subscriptionMonthlyPrice): self{$this->subscriptionMonthlyPrice = $subscriptionMonthlyPrice;return $this;}public function getSubscriptionYearlyPrice(): ?float{return $this->subscriptionYearlyPrice;}public function setSubscriptionYearlyPrice(?float $subscriptionYearlyPrice): self{$this->subscriptionYearlyPrice = $subscriptionYearlyPrice;return $this;}public function getStore(): ?Store{return $this->store;}public function setStore(?Store $store): self{$this->store = $store;return $this;}/*** Get the value of deletedAt*/public function getDeletedAt(){return $this->deletedAt;}/*** Set the value of deletedAt** @return self*/public function setDeletedAt($deletedAt){$this->deletedAt = $deletedAt;return $this;}/*** @return Collection<int, ProductPack>*/public function getChildrenProductsPack(): Collection{return $this->childrenProductsPack;}public function addChildrenProductsPack(ProductPack $childrenPackProduct): self{if (!$this->childrenProductsPack->contains($childrenPackProduct)) {$this->childrenProductsPack->add($childrenPackProduct);$childrenPackProduct->setParentProduct($this);}return $this;}public function removeChildrenProductsPack(ProductPack $childrenPackProduct): self{if ($this->childrenProductsPack->removeElement($childrenPackProduct)) {// set the owning side to null (unless already changed)if ($childrenPackProduct->getParentProduct() === $this) {$childrenPackProduct->setParentProduct(null);}}return $this;}public function isLabelPriceFrom(): ?bool{return $this->labelPriceFrom;}public function setLabelPriceFrom(?bool $labelPriceFrom): self{$this->labelPriceFrom = $labelPriceFrom;return $this;}public function getSubscriptionDuration(): ?int{return $this->subscriptionDuration;}public function setSubscriptionDuration(?int $subscriptionDuration): self{$this->subscriptionDuration = $subscriptionDuration;return $this;}}