src/Flexy/ShopBundle/Entity/Product/Product.php line 47

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Product;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Brand;
  5. use App\Flexy\ShopBundle\Entity\Order\OrderItem;
  6. use App\Flexy\ShopBundle\Entity\Payment\PaymentMethod;
  7. use App\Flexy\ShopBundle\Entity\Product\CategoryProduct;
  8. use App\Flexy\ShopBundle\Entity\Promotion\Promotion;
  9. use App\Flexy\ShopBundle\Entity\Shipping\Country;
  10. use App\Flexy\ShopBundle\Entity\Shipping\ShippingMethod;
  11. use App\Flexy\ShopBundle\Entity\Store\Store;
  12. use App\Flexy\ShopBundle\Entity\Vendor\Vendor;
  13. use App\Flexy\ShopBundle\Repository\Product\ProductRepository;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Doctrine\ORM\Mapping\Table;
  18. use Doctrine\ORM\Mapping\Entity;
  19. use Doctrine\ORM\Mapping\InheritanceType;
  20. use Gedmo\Mapping\Annotation as Gedmo;
  21. use Symfony\Component\Filesystem\Filesystem;
  22. use Symfony\Component\Serializer\Annotation\Groups;
  23. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  24. use ApiPlatform\Core\Annotation\ApiFilter;
  25. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  26. use Gedmo\Translatable\Translatable;
  27. #[ApiResource(
  28.     normalizationContext: ['groups' => ['read']],
  29.     denormalizationContext: ['groups' => ['write']],
  30.     
  31.     )]
  32. #[ApiFilter(SearchFilter::class, properties: ['name' => 'partial','categoriesProduct' => 'partial','productType'=>'exact'])]
  33. #[Table(name'product')]
  34. #[ORM\Entity(repositoryClassProductRepository::class)]
  35. #[InheritanceType('JOINED')]
  36. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  37. #[Gedmo\Tree(type'nested')]
  38. #[UniqueEntity(
  39.     fields: ['name'],
  40.     message'Ce produit avec ce nom est déja existe, utilisez un autre nom pour ce produit.',
  41. )]
  42. #[ORM\Cache(usage:"NONSTRICT_READ_WRITE",region:"append_depend")]
  43. class Product implements  Translatable
  44. {
  45.     #[Groups(['read''readDeep'])]
  46.     #[ORM\Id]
  47.     #[ORM\GeneratedValue]
  48.     #[ORM\Column(type'integer')]
  49.     private $id;
  50.     #[Groups(['read''readDeep','write'])]
  51.     #[ORM\Column(type'string'length255)]
  52.     #[Gedmo\Translatable]
  53.     private ?string $name null;
  54.     /**
  55.      *
  56.      * @example the pricipale image of the product
  57.      */
  58.     #[Groups(['read''readDeep'])]
  59.     #[ORM\Column(type'string'length255,nullable:true)]
  60.     private string|null $image "" ;
  61.     #[Groups(['read''readDeep'])]
  62.     #[ORM\Column(type'float',nullable:true)]
  63.     private ?float $price 0;
  64.     #[Groups(['read''readDeep'])]
  65.     #[ORM\Column(type'text'nullabletrue)]
  66.     #[Gedmo\Translatable]
  67.     private ?string $description null;
  68.     /**
  69.      * #requiredForAi
  70.      * @example The principale category of the product (Important)
  71.      */
  72.     #[ORM\ManyToOne(targetEntityCategoryProduct::class, inversedBy'productsChildrens',cascade:["persist"])]
  73.     private ?\App\Flexy\ShopBundle\Entity\Product\CategoryProduct $parentCategory null;
  74.     /**
  75.      *
  76.      * @example Sub categories if mentionned 
  77.      */
  78.     #[ORM\ManyToMany(targetEntityCategoryProduct::class, inversedBy'products'cascade: ['persist'])]
  79.     private  $categoriesProduct;
  80.     /**
  81.      *
  82.      * @example If productType is variable
  83.      */
  84.     #[ORM\OneToMany(targetEntityAttributValue::class, mappedBy'product'cascade: ['persist'])]
  85.     #[Groups(['read''readDeep'])]
  86.     private  $attributValues;
  87.     #[Groups(['read''readDeep'])]
  88.     #[ORM\Column(type'float'nullabletrue)]
  89.     private ?float $oldPrice null;
  90.     #[Groups(['read''readDeep'])]
  91.     #[ORM\Column(type'integer'nullabletrue)]
  92.     private ?int $quantity null;
  93.     /**
  94.      *   
  95.      * @example [simple|variable|pack|subscription] default: simple
  96.      */
  97.     
  98.     #[Groups(['read''readDeep'])]
  99.     #[ORM\Column(type'string'length255nullabletrue)]
  100.     private ?string $productType "simple";
  101.     #[ORM\Column(type'string'length255nullabletrue)]
  102.     #[Gedmo\Translatable]
  103.     private ?string $metaTitle null;
  104.     #[ORM\Column(type'string'length255nullabletrue)]
  105.     #[Gedmo\Translatable]
  106.     private ?string $metaDescription null;
  107.     #[ORM\Column(type'simple_array'nullabletrue)]
  108.     private ?array $metaKeywords = [];
  109.     #[ORM\OneToMany(targetEntityImageProduct::class, mappedBy'product'cascade: ['persist'])]
  110.     private  $images;
  111.     /**
  112.      *   
  113.      * @example Can be the name of the product
  114.      */
  115.     #[Gedmo\Slug(fields: ['name'],updatable:false)]
  116.     #[ORM\Column(type'string'length255)]
  117.     private ?string $slug null;
  118.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  119.     private ?\DateTimeImmutable $createdAt null;
  120.     #[ORM\OneToMany(targetEntityProductVariant::class, mappedBy'product'cascade: ['persist'])]
  121.     private  $productVariants;
  122.     /**
  123.      * #ignoredForAi
  124.      *
  125.      */
  126.     #[ORM\Column(type'boolean'nullabletrue)]
  127.     private ?bool $isPriceReducedPerPercent null;
  128.     #[ORM\Column(type'float'nullabletrue)]
  129.     private ?float $percentReduction null;
  130.     #[ORM\Column(type'string'length255nullabletrue)]
  131.     private ?string $skuCode null;
  132.     #[ORM\OneToMany(targetEntityOrderItem::class, mappedBy'product'cascade: ['persist'])]
  133.     private  $orderItems;
  134.     /**
  135.      * #ignoredForAi
  136.      *
  137.      */
  138.     #[ORM\ManyToOne(targetEntityPromotion::class, inversedBy'products')]
  139.     private ?\App\Flexy\ShopBundle\Entity\Promotion\Promotion $promotion null;
  140.     /**
  141.      * #ignoredForAi
  142.      *
  143.      */
  144.     #[ORM\ManyToOne(targetEntityVendor::class, inversedBy'products')]
  145.     private ?\App\Flexy\ShopBundle\Entity\Vendor\Vendor $vendor null;
  146.     /**
  147.      * #ignoredForAi
  148.      *
  149.      */
  150.     #[ORM\ManyToOne(targetEntityBrand::class, inversedBy'products'cascade: ['persist'])]
  151.     private ?\App\Flexy\ShopBundle\Entity\Brand $brand null;
  152.     #[ORM\Column(type'text'nullabletrue)]
  153.     #[Gedmo\Translatable]
  154.     private ?string $shortDescription null;
  155.     #[ORM\Column(type'boolean'nullabletrue)]
  156.     private ?bool $isPublished true;
  157.     #[ORM\OneToMany(targetEntityComment::class, mappedBy'product')]
  158.     private  $comments;
  159.     #[ORM\Column(type'string'length255nullabletrue)]
  160.     private ?string $skuCodeShop null;
  161.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  162.     private ?\DateTimeImmutable $endAt null;
  163.     /**
  164.      * #ignoredForAi
  165.      *
  166.      */
  167.     #[ORM\ManyToOne(targetEntityProduct::class)]
  168.     private ?\App\Flexy\ShopBundle\Entity\Product\Product $clonedProduct null;
  169.     /**
  170.      *   
  171.      * @example [amount|percentage|null] can be null
  172.      */
  173.     #[ORM\Column(type'string'length255nullabletrue)]
  174.     private ?string $typeReduction null;
  175.     /**
  176.      *   
  177.      * @example number related to typeReduction
  178.      */
  179.     #[ORM\Column(type'float'length255nullabletrue)]
  180.     private ?float $valueReduction null;
  181.     #[ORM\OneToMany(mappedBy'product'targetEntityProductSubscription::class, orphanRemovaltrue)]
  182.     private Collection $productSubscriptions;
  183.     #[ORM\Column(nullabletrue)]
  184.     #[Groups(['read''readDeep'])]
  185.     private ?float $subscriptionMonthlyPrice null;
  186.     #[ORM\Column(nullabletrue)]
  187.     #[Groups(['read''readDeep'])]
  188.     private ?float $subscriptionYearlyPrice null;
  189.     /**
  190.      * #ignoredForAi
  191.      *
  192.      */
  193.     #[ORM\ManyToOne(inversedBy'products')]
  194.     private ?Store $store null;
  195.     #[ORM\Column(nullabletrue)]
  196.     private ?\DateTimeImmutable $deletedAt null;
  197.     /**
  198.      * Used locale to override Translation listener`s locale
  199.      * this is not a mapped field of entity metadata, just a simple property
  200.      */
  201.     #[Gedmo\Locale]
  202.     private $locale;
  203.     #[ORM\OneToMany(mappedBy'parentProduct'targetEntityProductPack::class, orphanRemovaltrue,cascade:["persist","remove"])]
  204.     private Collection $childrenProductsPack;
  205.     #[ORM\Column(nullabletrue)]
  206.     #[Groups(['read''readDeep'])]
  207.     private ?bool $labelPriceFrom null;
  208.     #[ORM\ManyToMany(targetEntityShippingMethod::class, inversedBy'products',cascade:["persist"])]
  209.     private Collection $includedShippingMethods;
  210.     #[ORM\Column(nullabletrue)]
  211.     private ?array $metaData null;
  212.     #[ORM\Column(length255nullabletrue)]
  213.     private ?string $defaultCurrency null;
  214.     #[ORM\ManyToMany(targetEntityPaymentMethod::class, inversedBy'products')]
  215.     private Collection $includedPaymentMethods;
  216.     #[ORM\Column(length255nullabletrue)]
  217.     private ?string $video null;
  218.     #[ORM\Column(length255nullabletrue)]
  219.     private ?string $videoThumbnail null;
  220.     #[ORM\Column(nullabletrue)]
  221.     private ?float $costPrice null;
  222.     #[ORM\ManyToMany(targetEntityCountry::class, inversedBy'shippingProducts')]
  223.     private Collection $shipToCountries;
  224.     #[ORM\Column(type'integer'nullabletrue)]
  225.     private $position;
  226.     
  227.     public function __construct()
  228.     {
  229.         $this->categoriesProduct = new ArrayCollection();
  230.         $this->attributValues = new ArrayCollection();
  231.         $this->createdAt = new \DateTimeImmutable();
  232.         $this->images = new ArrayCollection();
  233.         $this->productVariants = new ArrayCollection();
  234.         $this->orderItems = new ArrayCollection();
  235.         $this->comments = new ArrayCollection();
  236.         $this->productSubscriptions = new ArrayCollection();
  237.         $this->childrenProductsPack = new ArrayCollection();
  238.         $this->includedShippingMethods = new ArrayCollection();
  239.         $this->includedPaymentMethods = new ArrayCollection();
  240.         $this->shipToCountries = new ArrayCollection();
  241.        
  242.   
  243.     }
  244.     public function __toString(): string
  245.     {
  246.         return (string) $this->name;
  247.     }
  248.     public function getId(): ?int
  249.     {
  250.         return $this->id;
  251.     }
  252.     #[Groups(['read''readDeep'])]
  253.     public function getCategoriesByName(){
  254.         $categories = [];
  255.         foreach($this->categoriesProduct as $singleCategory){
  256.             $categories[]=$singleCategory->getName();
  257.         }
  258.         return $categories;
  259.     }
  260.     #[Groups(['read'])]
  261.     public function getParentCategoryByName(){
  262.         $name null;
  263.         if($this->parentCategory){
  264.             $name $this->parentCategory->getName();
  265.         }
  266.         return $name;
  267.     }
  268.     public function setId($id=null): self
  269.     {
  270.         $this->id $id;
  271.         return $this;
  272.     }
  273.     public function getName(): ?string
  274.     {
  275.         return $this->name;
  276.     }
  277.     public function setName(string $name): self
  278.     {
  279.         $this->name $name;
  280.         return $this;
  281.     }
  282.     public function getPrice(): ?float
  283.     {
  284.         return $this->price;
  285.     }
  286.     #[Groups(['read''readDeep'])]
  287.     public function getReduction(): ?float
  288.     {
  289.         $reduction 0;
  290.         if($this->typeReduction and $this->valueReduction){
  291.             if($this->typeReduction == "percent"){
  292.                 $reduction = ((float)$this->price  100) * $this->valueReduction;
  293.                 
  294.             }else{
  295.                 $reduction =  $this->valueReduction ;
  296.             }
  297.         }
  298.         return $reduction;
  299.     }
  300.     
  301.     public function setPrice(float $price): self
  302.     {
  303.         $this->price $price;
  304.         return $this;
  305.     }
  306.     public function getDescription(): ?string
  307.     {
  308.         return $this->description;
  309.     }
  310.     public function setDescription(?string $description): self
  311.     {
  312.         $this->description $description;
  313.         return $this;
  314.     }
  315.     /**
  316.      * Get the value of image
  317.      */ 
  318.     public function getImage()
  319.     {
  320.         return $this->image;
  321.     }
  322.     /**
  323.      * Set the value of image
  324.      */
  325.     public function setImage($image)
  326.     {
  327.         $this->image = (string)$image;
  328.         return $this;
  329.     }
  330.     /**
  331.      * @return Collection|CategoryProduct[]
  332.      */
  333.     public function getCategoriesProduct(): Collection
  334.     {
  335.         return $this->categoriesProduct;
  336.     }
  337.     public function addCategoryProduct(CategoryProduct $categoryProduct): self
  338.     {
  339.         if (!$this->categoriesProduct->contains($categoryProduct)) {
  340.             $this->categoriesProduct[] = $categoryProduct;
  341.             $categoryProduct->addProduct($this);
  342.         }
  343.         return $this;
  344.     }
  345.     public function removeCategoryProduct(CategoryProduct $categoryProduct): self
  346.     {
  347.         if ($this->categoriesProduct->removeElement($categoryProduct)) {
  348.             $categoryProduct->removeProduct($this);
  349.         }
  350.         return $this;
  351.     }
  352.     /**
  353.      * @return Collection|AttributValue[]
  354.      */
  355.     public function getAttributValues(): Collection
  356.     {
  357.         return $this->attributValues;
  358.     }
  359.     public function addAttributValue(AttributValue $attributValue): self
  360.     {
  361.         if (!$this->attributValues->contains($attributValue)) {
  362.             $this->attributValues[] = $attributValue;
  363.             $attributValue->setProduct($this);
  364.         }
  365.         return $this;
  366.     }
  367.     public function removeAttributValue(AttributValue $attributValue): self
  368.     {
  369.         if ($this->attributValues->removeElement($attributValue)) {
  370.             // set the owning side to null (unless already changed)
  371.             if ($attributValue->getProduct() === $this) {
  372.                 $attributValue->setProduct(null);
  373.             }
  374.         }
  375.         return $this;
  376.     }
  377.     public function getOldPrice(): ?float
  378.     {
  379.         return $this->oldPrice;
  380.     }
  381.     public function setOldPrice(?float $oldPrice): self
  382.     {
  383.         $this->oldPrice $oldPrice;
  384.         return $this;
  385.     }
  386.     public function getQuantity(): ?int
  387.     {
  388.         return $this->quantity;
  389.     }
  390.     public function setQuantity(?int $quantity): self
  391.     {
  392.         $this->quantity $quantity;
  393.         return $this;
  394.     }
  395.     public function getProductType(): ?string
  396.     {
  397.         return $this->productType;
  398.     }
  399.     public function setProductType(?string $productType): self
  400.     {
  401.         $this->productType $productType;
  402.         return $this;
  403.     }
  404.     public function getMetaTitle(): ?string
  405.     {
  406.         return $this->metaTitle;
  407.     }
  408.     public function setMetaTitle(?string $metaTitle): self
  409.     {
  410.         $this->metaTitle $metaTitle;
  411.         return $this;
  412.     }
  413.     public function getMetaDescription(): ?string
  414.     {
  415.         return $this->metaDescription;
  416.     }
  417.     public function setMetaDescription(?string $metaDescription): self
  418.     {
  419.         $this->metaDescription $metaDescription;
  420.         return $this;
  421.     }
  422.     public function getMetaKeywords(): ?array
  423.     {
  424.         return $this->metaKeywords;
  425.     }
  426.     public function setMetaKeywords(?array $metaKeywords): self
  427.     {
  428.         $this->metaKeywords $metaKeywords;
  429.         return $this;
  430.     }
  431.     /**
  432.      * @return Collection|ImageProduct[]
  433.      */
  434.     public function getImages(): Collection
  435.     {
  436.         return $this->images;
  437.     }
  438.     public function addImage(ImageProduct $image): self
  439.     {
  440.         if (!$this->images->contains($image)) {
  441.             $this->images[] = $image;
  442.             $image->setProduct($this);
  443.         }
  444.         return $this;
  445.     }
  446.     public function removeImage(ImageProduct $image): self
  447.     {
  448.         if ($this->images->removeElement($image)) {
  449.             // set the owning side to null (unless already changed)
  450.             if ($image->getProduct() === $this) {
  451.                 $image->setProduct(null);
  452.             }
  453.         }
  454.         return $this;
  455.     }
  456.     public function getSlug(): ?string
  457.     {
  458.         return $this->slug;
  459.     }
  460.     public function setSlug(string $slug): self
  461.     {
  462.         $this->slug $slug;
  463.         return $this;
  464.     }
  465.     public function getCreatedAt(): ?\DateTimeImmutable
  466.     {
  467.         return $this->createdAt;
  468.     }
  469.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  470.     {
  471.         $this->createdAt $createdAt;
  472.         return $this;
  473.     }
  474.     /**
  475.      * @return Collection|ProductVariant[]
  476.      */
  477.     public function getProductVariants(): Collection
  478.     {
  479.         return $this->productVariants;
  480.     }
  481.     public function addProductVariant(ProductVariant $productVariant): self
  482.     {
  483.         if (!$this->productVariants->contains($productVariant)) {
  484.             $this->productVariants[] = $productVariant;
  485.             $productVariant->setProduct($this);
  486.         }
  487.         return $this;
  488.     }
  489.     public function removeProductVariant(ProductVariant $productVariant): self
  490.     {
  491.         if ($this->productVariants->removeElement($productVariant)) {
  492.             // set the owning side to null (unless already changed)
  493.             if ($productVariant->getProduct() === $this) {
  494.                 $productVariant->setProduct(null);
  495.             }
  496.         }
  497.         return $this;
  498.     }
  499.     public function getIsPriceReducedPerPercent(): ?bool
  500.     {
  501.         return $this->isPriceReducedPerPercent;
  502.     }
  503.     public function setIsPriceReducedPerPercent(?bool $isPriceReducedPerPercent): self
  504.     {
  505.         $this->isPriceReducedPerPercent $isPriceReducedPerPercent;
  506.         return $this;
  507.     }
  508.     public function getPercentReduction(): ?float
  509.     {
  510.         return $this->percentReduction;
  511.     }
  512.     public function setPercentReduction(?float $percentReduction): self
  513.     {
  514.         $this->percentReduction $percentReduction;
  515.         return $this;
  516.     }
  517.     public function getSkuCode(): ?string
  518.     {
  519.         return $this->skuCode;
  520.     }
  521.     public function setSkuCode(?string $skuCode): self
  522.     {
  523.         $this->skuCode $skuCode;
  524.         return $this;
  525.     }
  526.     /**
  527.      * @return Collection|OrderItem[]
  528.      */
  529.     public function getOrderItems(): Collection
  530.     {
  531.         return $this->orderItems;
  532.     }
  533.     public function addOrderItem(OrderItem $orderItem): self
  534.     {
  535.         if (!$this->orderItems->contains($orderItem)) {
  536.             $this->orderItems[] = $orderItem;
  537.             $orderItem->setProduct($this);
  538.         }
  539.         return $this;
  540.     }
  541.     public function removeOrderItem(OrderItem $orderItem): self
  542.     {
  543.         if ($this->orderItems->removeElement($orderItem)) {
  544.             // set the owning side to null (unless already changed)
  545.             if ($orderItem->getProduct() === $this) {
  546.                 $orderItem->setProduct(null);
  547.             }
  548.         }
  549.         return $this;
  550.     }
  551.     public function getPromotion(): ?Promotion
  552.     {
  553.         return $this->promotion;
  554.     }
  555.     public function setPromotion(?Promotion $promotion): self
  556.     {
  557.         $this->promotion $promotion;
  558.         return $this;
  559.     }
  560.     #[Groups(['read''readDeep'])]
  561.     public function getFinalPrice(){
  562.         
  563.         $finalPrice $this->getPrice();
  564.         if($this->getTypeReduction() and $this->getValueReduction()){
  565.             if($this->getTypeReduction() == "percent"){
  566.                 $finalPrice $finalPrice - ($finalPrice $this->getValueReduction() / 100);
  567.                 
  568.                 return $finalPrice;
  569.             }else{
  570.                 $finalPrice $finalPrice $this->getValueReduction();
  571.                 return $finalPrice;
  572.             }
  573.         }
  574.         elseif($this->getPromotion()){
  575.             
  576.             if($this->getPromotion()->getType()=="percent"){
  577.                 
  578.                 $reduction = ($this->getPrice() / 100) * $this->getPromotion()->getValue();
  579.                 $finalPrice $this->getPrice() - $reduction;
  580.                 
  581.             }else{
  582.                 
  583.                 $finalPrice $this->getPrice() - $this->getPromotion()->getValue();
  584.                 
  585.             }
  586.             
  587.             return $finalPrice;
  588.             
  589.             
  590.         }
  591.        
  592.         return $this->price $this->getReduction() ;
  593.     }
  594.     public function getVendor(): ?Vendor
  595.     {
  596.         return $this->vendor;
  597.     }
  598.     public function setVendor(?Vendor $vendor): self
  599.     {
  600.         $this->vendor $vendor;
  601.         return $this;
  602.     }
  603.     public function getBrand(): ?Brand
  604.     {
  605.         return $this->brand;
  606.     }
  607.     public function setBrand(?Brand $brand): self
  608.     {
  609.         $this->brand $brand;
  610.         return $this;
  611.     }
  612.     public function getShortDescription(): ?string
  613.     {
  614.         return $this->shortDescription;
  615.     }
  616.     public function setShortDescription(?string $shortDescription): self
  617.     {
  618.         $this->shortDescription $shortDescription;
  619.         return $this;
  620.     }
  621.     public function getIsPublished(): ?bool
  622.     {
  623.         return $this->isPublished;
  624.     }
  625.     public function setIsPublished(?bool $isPublished): self
  626.     {
  627.         $this->isPublished $isPublished;
  628.         return $this;
  629.     }
  630.     /**
  631.      * @return Collection|Comment[]
  632.      */
  633.     public function getComments(): Collection
  634.     {
  635.         return $this->comments;
  636.     }
  637.     public function addComment(Comment $comment): self
  638.     {
  639.         if (!$this->comments->contains($comment)) {
  640.             $this->comments[] = $comment;
  641.             $comment->setProduct($this);
  642.         }
  643.         return $this;
  644.     }
  645.     public function removeComment(Comment $comment): self
  646.     {
  647.         if ($this->comments->removeElement($comment)) {
  648.             // set the owning side to null (unless already changed)
  649.             if ($comment->getProduct() === $this) {
  650.                 $comment->setProduct(null);
  651.             }
  652.         }
  653.         return $this;
  654.     }
  655.     public function getStars5(){
  656.         //for 5 stars
  657.         $stars5=0;
  658.         foreach($this->comments as $singleComment){
  659.             if($singleComment->getRating() == 5){
  660.                 $stars5 $stars5 1;
  661.             }
  662.             
  663.         }
  664.         return $stars5;
  665.     }
  666.     public function getStars4(){
  667.         //for 4 stars
  668.         $stars4=0;
  669.         foreach($this->comments as $singleComment){
  670.             if($singleComment->getRating() == 4){
  671.                 $stars4 $stars4 1;
  672.             }
  673.             
  674.         }
  675.         return $stars4;
  676.     }
  677.     public function getStars3(){
  678.         //for 3 stars
  679.         $stars3=0;
  680.         foreach($this->comments as $singleComment){
  681.             if($singleComment->getRating() == 3){
  682.                 $stars3 $stars3 1;
  683.             }
  684.             
  685.         }
  686.         return $stars3;
  687.     }
  688.     public function getStars2(){
  689.         //for 2 stars
  690.         $stars2=0;
  691.         foreach($this->comments as $singleComment){
  692.             if($singleComment->getRating() == 2){
  693.                 $stars2 $stars2 1;
  694.             }
  695.             
  696.         }
  697.         return $stars2;
  698.     }
  699.     public function getStars1(){
  700.         //for 5 stars
  701.         $stars1=0;
  702.         foreach($this->comments as $singleComment){
  703.             if($singleComment->getRating() == 1){
  704.                 $stars1 $stars1 1;
  705.             }
  706.             
  707.         }
  708.         return $stars1;
  709.     }
  710.     public function getRating(){
  711.         $topRating 0;
  712.         $totalRating=0;
  713.         $stars5 $this->getStars5();
  714.         $stars4 $this->getStars4();
  715.         $stars3 $this->getStars3();
  716.         $stars2 $this->getStars2();
  717.         $stars1 $this->getStars1();
  718.         $topRating = ($stars1 ) + ($stars2 ) + ($stars3 ) + ($stars4 )+ ($stars5 );
  719.         $totalRating $stars1 $stars2 +$stars3 $stars4 $stars5;
  720.         
  721.         $result 0;
  722.         if($totalRating 0){
  723.             $result $topRating $totalRating;
  724.         }
  725.         
  726.         return $result;
  727.         
  728.     }
  729.     public function getSkuCodeShop(): ?string
  730.     {
  731.         if(!$this->skuCodeShop){
  732.             return $this->skuCodeShop "OM".$this->createdAt->format("ymdhs").$this->id;
  733.         }
  734.         return $this->skuCodeShop;
  735.     }
  736.     public function setSkuCodeShop(?string $skuCodeShop): self
  737.     {
  738.         $this->skuCodeShop $skuCodeShop;
  739.         return $this;
  740.     }
  741.     public function addCategoriesProduct(CategoryProduct $categoriesProduct): self
  742.     {
  743.         if (!$this->categoriesProduct->contains($categoriesProduct)) {
  744.             $this->categoriesProduct[] = $categoriesProduct;
  745.         }
  746.         return $this;
  747.     }
  748.     public function removeCategoriesProduct(CategoryProduct $categoriesProduct): self
  749.     {
  750.         $this->categoriesProduct->removeElement($categoriesProduct);
  751.         return $this;
  752.     }
  753.     public function getEndAt(): ?\DateTimeImmutable
  754.     {
  755.         return $this->endAt;
  756.     }
  757.     public function setEndAt(?\DateTimeImmutable $endAt): self
  758.     {
  759.         $this->endAt $endAt;
  760.         return $this;
  761.     }
  762.     public function getParentCategory(): ?CategoryProduct
  763.     {
  764.         return $this->parentCategory;
  765.     }
  766.     public function setParentCategory(?CategoryProduct $parentCategory): self
  767.     {
  768.         $this->parentCategory $parentCategory;
  769.         return $this;
  770.     }
  771.     public function getClonedProduct(): ?self
  772.     {
  773.         return $this->clonedProduct;
  774.     }
  775.     public function setClonedProduct(?self $clonedProduct): self
  776.     {
  777.         $this->clonedProduct $clonedProduct;
  778.         return $this;
  779.     }
  780.     public function getTypeReduction(): ?string
  781.     {
  782.         return $this->typeReduction;
  783.     }
  784.     public function setTypeReduction(?string $typeReduction): self
  785.     {
  786.         $this->typeReduction $typeReduction;
  787.         return $this;
  788.     }
  789.     public function getValueReduction(): ?float
  790.     {
  791.         return $this->valueReduction;
  792.     }
  793.     public function setValueReduction(?float $valueReduction): self
  794.     {
  795.         $this->valueReduction $valueReduction;
  796.         return $this;
  797.     }
  798.     /**
  799.      * @return Collection<int, ProductSubscription>
  800.      */
  801.     public function getProductSubscriptions(): Collection
  802.     {
  803.         return $this->productSubscriptions;
  804.     }
  805.     public function addProductSubscription(ProductSubscription $productSubscription): self
  806.     {
  807.         if (!$this->productSubscriptions->contains($productSubscription)) {
  808.             $this->productSubscriptions->add($productSubscription);
  809.             $productSubscription->setProduct($this);
  810.         }
  811.         return $this;
  812.     }
  813.     public function removeProductSubscription(ProductSubscription $productSubscription): self
  814.     {
  815.         if ($this->productSubscriptions->removeElement($productSubscription)) {
  816.             // set the owning side to null (unless already changed)
  817.             if ($productSubscription->getProduct() === $this) {
  818.                 $productSubscription->setProduct(null);
  819.             }
  820.         }
  821.         return $this;
  822.     }
  823.     public function getSubscriptionMonthlyPrice(): ?float
  824.     {
  825.         return $this->subscriptionMonthlyPrice;
  826.     }
  827.     public function setSubscriptionMonthlyPrice(?float $subscriptionMonthlyPrice): self
  828.     {
  829.         $this->subscriptionMonthlyPrice $subscriptionMonthlyPrice;
  830.         return $this;
  831.     }
  832.     public function getSubscriptionYearlyPrice(): ?float
  833.     {
  834.         return $this->subscriptionYearlyPrice;
  835.     }
  836.     public function setSubscriptionYearlyPrice(?float $subscriptionYearlyPrice): self
  837.     {
  838.         $this->subscriptionYearlyPrice $subscriptionYearlyPrice;
  839.         return $this;
  840.     }
  841.     public function getStore(): ?Store
  842.     {
  843.         return $this->store;
  844.     }
  845.     public function setStore(?Store $store): self
  846.     {
  847.         $this->store $store;
  848.         return $this;
  849.     }
  850.    
  851.     /**
  852.      * Get the value of deletedAt
  853.      */ 
  854.     public function getDeletedAt()
  855.     {
  856.         return $this->deletedAt;
  857.     }
  858.     /**
  859.      * Set the value of deletedAt
  860.      *
  861.      * @return  self
  862.      */ 
  863.     public function setDeletedAt($deletedAt)
  864.     {
  865.         $this->deletedAt $deletedAt;
  866.         return $this;
  867.     }
  868.   
  869.     /**
  870.      * @return Collection<int, ProductPack>
  871.      */
  872.     public function getChildrenProductsPack(): Collection
  873.     {
  874.         return $this->childrenProductsPack;
  875.     }
  876.     public function addChildrenProductsPack(ProductPack $childrenPackProduct): self
  877.     {
  878.         if (!$this->childrenProductsPack->contains($childrenPackProduct)) {
  879.             $this->childrenProductsPack->add($childrenPackProduct);
  880.             $childrenPackProduct->setParentProduct($this);
  881.         }
  882.         return $this;
  883.     }
  884.     public function removeChildrenProductsPack(ProductPack $childrenPackProduct): self
  885.     {
  886.         if ($this->childrenProductsPack->removeElement($childrenPackProduct)) {
  887.             // set the owning side to null (unless already changed)
  888.             if ($childrenPackProduct->getParentProduct() === $this) {
  889.                 $childrenPackProduct->setParentProduct(null);
  890.             }
  891.         }
  892.         return $this;
  893.     }
  894.     public function isLabelPriceFrom(): ?bool
  895.     {
  896.         return $this->labelPriceFrom;
  897.     }
  898.     public function setLabelPriceFrom(?bool $labelPriceFrom): self
  899.     {
  900.         $this->labelPriceFrom $labelPriceFrom;
  901.         return $this;
  902.     }
  903.     
  904.     #[Groups(['read''readDeep'])]
  905.     public function getDefaultQuantity()
  906.     {
  907.         
  908.         if($this->getProductType() == "pack"){
  909.             $quantity 0;
  910.             foreach($this->getChildrenProductsPack() as $childrenProduct){
  911.                 
  912.                 $quantity $quantity $childrenProduct->getQuantity();
  913.                 
  914.             }
  915.             return $quantity;
  916.         }
  917.         
  918.         
  919.         return 1;
  920.     }
  921.     public function getAttributes(){
  922.         $attributes = [];
  923.         if($this->productType == "variable"){
  924.             
  925.             foreach($this->attributValues as $singleAttrValue){
  926.                 if(!in_array($singleAttrValue->getAttribut()->getName(),$attributes)){
  927.                     $attributes[] =$singleAttrValue->getAttribut()->getName();
  928.                 }
  929.                 
  930.             }
  931.         }
  932.        
  933.         return $attributes;
  934.     }
  935.     public function setTranslatableLocale($locale)
  936.     {
  937.         $this->locale $locale;
  938.     }
  939.     /**
  940.      * @return Collection<int, ShippingMethod>
  941.      */
  942.     public function getIncludedShippingMethods(): Collection
  943.     {
  944.         return $this->includedShippingMethods;
  945.     }
  946.     public function addIncludedShippingMethod(ShippingMethod $includedShippingMethod): static
  947.     {
  948.         if (!$this->includedShippingMethods->contains($includedShippingMethod)) {
  949.             $this->includedShippingMethods->add($includedShippingMethod);
  950.         }
  951.         return $this;
  952.     }
  953.     public function removeIncludedShippingMethod(ShippingMethod $includedShippingMethod): static
  954.     {
  955.         $this->includedShippingMethods->removeElement($includedShippingMethod);
  956.         return $this;
  957.     }
  958.     public function getMetaData(): ?array
  959.     {
  960.         return $this->metaData;
  961.     }
  962.     public function setMetaData(?array $metaData): static
  963.     {
  964.         $this->metaData $metaData;
  965.         return $this;
  966.     }
  967.     public function getDefaultCurrency(): ?string
  968.     {
  969.         return $this->defaultCurrency;
  970.     }
  971.     public function setDefaultCurrency(?string $defaultCurrency): static
  972.     {
  973.         $this->defaultCurrency $defaultCurrency;
  974.         return $this;
  975.     }
  976.     /**
  977.      * @return Collection<int, PaymentMethod>
  978.      */
  979.     public function getIncludedPaymentMethods(): Collection
  980.     {
  981.         return $this->includedPaymentMethods;
  982.     }
  983.     public function addIncludedPaymentMethod(PaymentMethod $includedPaymentMethod): static
  984.     {
  985.         if (!$this->includedPaymentMethods->contains($includedPaymentMethod)) {
  986.             $this->includedPaymentMethods->add($includedPaymentMethod);
  987.         }
  988.         return $this;
  989.     }
  990.     public function removeIncludedPaymentMethod(PaymentMethod $includedPaymentMethod): static
  991.     {
  992.         $this->includedPaymentMethods->removeElement($includedPaymentMethod);
  993.         return $this;
  994.     }
  995.     public function getVideo(): ?string
  996.     {
  997.         return $this->video;
  998.     }
  999.     public function setVideo(?string $video): static
  1000.     {
  1001.         $this->video $video;
  1002.         return $this;
  1003.     }
  1004.     public function getVideoThumbnail(): ?string
  1005.     {
  1006.         return $this->videoThumbnail;
  1007.     }
  1008.     public function setVideoThumbnail(?string $videoThumbnail): static
  1009.     {
  1010.         $this->videoThumbnail $videoThumbnail;
  1011.         return $this;
  1012.     }
  1013.     public function getCostPrice(): ?float
  1014.     {
  1015.         return $this->costPrice;
  1016.     }
  1017.     public function setCostPrice(?float $costPrice): static
  1018.     {
  1019.         $this->costPrice $costPrice;
  1020.         return $this;
  1021.     }
  1022.     /**
  1023.      * @return Collection<int, Country>
  1024.      */
  1025.     public function getShipToCountries(): Collection
  1026.     {
  1027.         return $this->shipToCountries;
  1028.     }
  1029.     public function addShipToCountry(Country $shipToCountry): static
  1030.     {
  1031.         if (!$this->shipToCountries->contains($shipToCountry)) {
  1032.             $this->shipToCountries->add($shipToCountry);
  1033.         }
  1034.         return $this;
  1035.     }
  1036.     public function removeShipToCountry(Country $shipToCountry): static
  1037.     {
  1038.         $this->shipToCountries->removeElement($shipToCountry);
  1039.         return $this;
  1040.     }
  1041.    
  1042.   
  1043.     /**
  1044.      * Get the value of position
  1045.      */ 
  1046.     public function getPosition()
  1047.     {
  1048.         return $this->position;
  1049.     }
  1050.     /**
  1051.      * Set the value of position
  1052.      *
  1053.      * @return  self
  1054.      */ 
  1055.     public function setPosition($position)
  1056.     {
  1057.         $this->position $position;
  1058.         return $this;
  1059.     }
  1060. }