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

  1. <?php
  2. namespace App\IlaveU\ShopBundle\Entity\Product;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\IlaveU\ShopBundle\Entity\Brand;
  5. use App\IlaveU\ShopBundle\Entity\Order\OrderItem;
  6. use App\IlaveU\ShopBundle\Entity\Payment\PaymentMethod;
  7. use App\IlaveU\ShopBundle\Entity\Product\CategoryProduct;
  8. use App\IlaveU\ShopBundle\Entity\Promotion\Promotion;
  9. use App\IlaveU\ShopBundle\Entity\Shipping\Country;
  10. use App\IlaveU\ShopBundle\Entity\Shipping\ShippingMethod;
  11. use App\IlaveU\ShopBundle\Entity\Store\Store;
  12. use App\IlaveU\ShopBundle\Entity\Vendor\Vendor;
  13. use App\IlaveU\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\IlaveU\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\IlaveU\ShopBundle\Entity\Promotion\Promotion $promotion null;
  140.     /**
  141.      * #ignoredForAi
  142.      *
  143.      */
  144.     #[ORM\ManyToOne(targetEntityVendor::class, inversedBy'products')]
  145.     private ?\App\IlaveU\ShopBundle\Entity\Vendor\Vendor $vendor null;
  146.     /**
  147.      * #ignoredForAi
  148.      *
  149.      */
  150.     #[ORM\ManyToOne(targetEntityBrand::class, inversedBy'products'cascade: ['persist'])]
  151.     private ?\App\IlaveU\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\IlaveU\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.     
  253.     public function getName(): ?string
  254.     {
  255.         return $this->name;
  256.     }
  257.     public function setName(string $name): self
  258.     {
  259.         $this->name $name;
  260.         return $this;
  261.     }
  262.     
  263.     #[Groups(['read'])]
  264.     public function getParentCategoryByName(){
  265.         $name null;
  266.         if($this->parentCategory){
  267.             $name $this->parentCategory->getName();
  268.         }
  269.         return $name;
  270.     }
  271.     #[Groups(['read''readDeep'])]
  272.     public function getCategoriesByName(){
  273.         $categories = [];
  274.         foreach($this->categoriesProduct as $singleCategory){
  275.             $categories[]=$singleCategory->getName();
  276.         }
  277.         return $categories;
  278.     }
  279.     
  280.     public function getPrice(): ?float
  281.     {
  282.         return $this->price;
  283.     }
  284.     #[Groups(['read''readDeep'])]
  285.     public function getReduction(): ?float
  286.     {
  287.         $reduction 0;
  288.         if($this->typeReduction and $this->valueReduction){
  289.             if($this->typeReduction == "percent"){
  290.                 $reduction = ((float)$this->price  100) * $this->valueReduction;
  291.                 
  292.             }else{
  293.                 $reduction =  $this->valueReduction ;
  294.             }
  295.         }
  296.         return $reduction;
  297.     }
  298.     
  299.     public function setPrice(float $price): self
  300.     {
  301.         $this->price $price;
  302.         return $this;
  303.     }
  304.     public function getDescription(): ?string
  305.     {
  306.         return $this->description;
  307.     }
  308.     public function setDescription(?string $description): self
  309.     {
  310.         $this->description $description;
  311.         return $this;
  312.     }
  313.     /**
  314.      * Get the value of image
  315.      */ 
  316.     public function getImage()
  317.     {
  318.         return $this->image;
  319.     }
  320.     /**
  321.      * Set the value of image
  322.      */
  323.     public function setImage($image)
  324.     {
  325.         $this->image = (string)$image;
  326.         return $this;
  327.     }
  328.     /**
  329.      * @return Collection|CategoryProduct[]
  330.      */
  331.     public function getCategoriesProduct(): Collection
  332.     {
  333.         return $this->categoriesProduct;
  334.     }
  335.     public function addCategoryProduct(CategoryProduct $categoryProduct): self
  336.     {
  337.         if (!$this->categoriesProduct->contains($categoryProduct)) {
  338.             $this->categoriesProduct[] = $categoryProduct;
  339.             $categoryProduct->addProduct($this);
  340.         }
  341.         return $this;
  342.     }
  343.     public function removeCategoryProduct(CategoryProduct $categoryProduct): self
  344.     {
  345.         if ($this->categoriesProduct->removeElement($categoryProduct)) {
  346.             $categoryProduct->removeProduct($this);
  347.         }
  348.         return $this;
  349.     }
  350.     /**
  351.      * @return Collection|AttributValue[]
  352.      */
  353.     public function getAttributValues(): Collection
  354.     {
  355.         return $this->attributValues;
  356.     }
  357.     public function addAttributValue(AttributValue $attributValue): self
  358.     {
  359.         if (!$this->attributValues->contains($attributValue)) {
  360.             $this->attributValues[] = $attributValue;
  361.             $attributValue->setProduct($this);
  362.         }
  363.         return $this;
  364.     }
  365.     public function removeAttributValue(AttributValue $attributValue): self
  366.     {
  367.         if ($this->attributValues->removeElement($attributValue)) {
  368.             // set the owning side to null (unless already changed)
  369.             if ($attributValue->getProduct() === $this) {
  370.                 $attributValue->setProduct(null);
  371.             }
  372.         }
  373.         return $this;
  374.     }
  375.     public function getOldPrice(): ?float
  376.     {
  377.         return $this->oldPrice;
  378.     }
  379.     public function setOldPrice(?float $oldPrice): self
  380.     {
  381.         $this->oldPrice $oldPrice;
  382.         return $this;
  383.     }
  384.     public function getQuantity(): ?int
  385.     {
  386.         return $this->quantity;
  387.     }
  388.     public function setQuantity(?int $quantity): self
  389.     {
  390.         $this->quantity $quantity;
  391.         return $this;
  392.     }
  393.     public function getProductType(): ?string
  394.     {
  395.         return $this->productType;
  396.     }
  397.     public function setProductType(?string $productType): self
  398.     {
  399.         $this->productType $productType;
  400.         return $this;
  401.     }
  402.     public function getMetaTitle(): ?string
  403.     {
  404.         return $this->metaTitle;
  405.     }
  406.     public function setMetaTitle(?string $metaTitle): self
  407.     {
  408.         $this->metaTitle $metaTitle;
  409.         return $this;
  410.     }
  411.     public function getMetaDescription(): ?string
  412.     {
  413.         return $this->metaDescription;
  414.     }
  415.     public function setMetaDescription(?string $metaDescription): self
  416.     {
  417.         $this->metaDescription $metaDescription;
  418.         return $this;
  419.     }
  420.     public function getMetaKeywords(): ?array
  421.     {
  422.         return $this->metaKeywords;
  423.     }
  424.     public function setMetaKeywords(?array $metaKeywords): self
  425.     {
  426.         $this->metaKeywords $metaKeywords;
  427.         return $this;
  428.     }
  429.     /**
  430.      * @return Collection|ImageProduct[]
  431.      */
  432.     public function getImages(): Collection
  433.     {
  434.         return $this->images;
  435.     }
  436.     public function addImage(ImageProduct $image): self
  437.     {
  438.         if (!$this->images->contains($image)) {
  439.             $this->images[] = $image;
  440.             $image->setProduct($this);
  441.         }
  442.         return $this;
  443.     }
  444.     public function removeImage(ImageProduct $image): self
  445.     {
  446.         if ($this->images->removeElement($image)) {
  447.             // set the owning side to null (unless already changed)
  448.             if ($image->getProduct() === $this) {
  449.                 $image->setProduct(null);
  450.             }
  451.         }
  452.         return $this;
  453.     }
  454.     public function getSlug(): ?string
  455.     {
  456.         return $this->slug;
  457.     }
  458.     public function setSlug(string $slug): self
  459.     {
  460.         $this->slug $slug;
  461.         return $this;
  462.     }
  463.     public function getCreatedAt(): ?\DateTimeImmutable
  464.     {
  465.         return $this->createdAt;
  466.     }
  467.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  468.     {
  469.         $this->createdAt $createdAt;
  470.         return $this;
  471.     }
  472.     /**
  473.      * @return Collection|ProductVariant[]
  474.      */
  475.     public function getProductVariants(): Collection
  476.     {
  477.         return $this->productVariants;
  478.     }
  479.     public function addProductVariant(ProductVariant $productVariant): self
  480.     {
  481.         if (!$this->productVariants->contains($productVariant)) {
  482.             $this->productVariants[] = $productVariant;
  483.             $productVariant->setProduct($this);
  484.         }
  485.         return $this;
  486.     }
  487.     public function removeProductVariant(ProductVariant $productVariant): self
  488.     {
  489.         if ($this->productVariants->removeElement($productVariant)) {
  490.             // set the owning side to null (unless already changed)
  491.             if ($productVariant->getProduct() === $this) {
  492.                 $productVariant->setProduct(null);
  493.             }
  494.         }
  495.         return $this;
  496.     }
  497.     public function getIsPriceReducedPerPercent(): ?bool
  498.     {
  499.         return $this->isPriceReducedPerPercent;
  500.     }
  501.     public function setIsPriceReducedPerPercent(?bool $isPriceReducedPerPercent): self
  502.     {
  503.         $this->isPriceReducedPerPercent $isPriceReducedPerPercent;
  504.         return $this;
  505.     }
  506.     public function getPercentReduction(): ?float
  507.     {
  508.         return $this->percentReduction;
  509.     }
  510.     public function setPercentReduction(?float $percentReduction): self
  511.     {
  512.         $this->percentReduction $percentReduction;
  513.         return $this;
  514.     }
  515.     public function getSkuCode(): ?string
  516.     {
  517.         return $this->skuCode;
  518.     }
  519.     public function setSkuCode(?string $skuCode): self
  520.     {
  521.         $this->skuCode $skuCode;
  522.         return $this;
  523.     }
  524.     /**
  525.      * @return Collection|OrderItem[]
  526.      */
  527.     public function getOrderItems(): Collection
  528.     {
  529.         return $this->orderItems;
  530.     }
  531.     public function addOrderItem(OrderItem $orderItem): self
  532.     {
  533.         if (!$this->orderItems->contains($orderItem)) {
  534.             $this->orderItems[] = $orderItem;
  535.             $orderItem->setProduct($this);
  536.         }
  537.         return $this;
  538.     }
  539.     public function removeOrderItem(OrderItem $orderItem): self
  540.     {
  541.         if ($this->orderItems->removeElement($orderItem)) {
  542.             // set the owning side to null (unless already changed)
  543.             if ($orderItem->getProduct() === $this) {
  544.                 $orderItem->setProduct(null);
  545.             }
  546.         }
  547.         return $this;
  548.     }
  549.     public function getPromotion(): ?Promotion
  550.     {
  551.         return $this->promotion;
  552.     }
  553.     public function setPromotion(?Promotion $promotion): self
  554.     {
  555.         $this->promotion $promotion;
  556.         return $this;
  557.     }
  558.     #[Groups(['read''readDeep'])]
  559.     public function getFinalPrice(){
  560.         
  561.         $finalPrice $this->getPrice();
  562.         if($this->getTypeReduction() and $this->getValueReduction()){
  563.             if($this->getTypeReduction() == "percent"){
  564.                 $finalPrice $finalPrice - ($finalPrice $this->getValueReduction() / 100);
  565.                 
  566.                 return $finalPrice;
  567.             }else{
  568.                 $finalPrice $finalPrice $this->getValueReduction();
  569.                 return $finalPrice;
  570.             }
  571.         }
  572.         elseif($this->getPromotion()){
  573.             
  574.             if($this->getPromotion()->getType()=="percent"){
  575.                 
  576.                 $reduction = ($this->getPrice() / 100) * $this->getPromotion()->getValue();
  577.                 $finalPrice $this->getPrice() - $reduction;
  578.                 
  579.             }else{
  580.                 
  581.                 $finalPrice $this->getPrice() - $this->getPromotion()->getValue();
  582.                 
  583.             }
  584.             
  585.             return $finalPrice;
  586.             
  587.             
  588.         }
  589.        
  590.         return $this->price $this->getReduction() ;
  591.     }
  592.     public function getVendor(): ?Vendor
  593.     {
  594.         return $this->vendor;
  595.     }
  596.     public function setVendor(?Vendor $vendor): self
  597.     {
  598.         $this->vendor $vendor;
  599.         return $this;
  600.     }
  601.     public function getBrand(): ?Brand
  602.     {
  603.         return $this->brand;
  604.     }
  605.     public function setBrand(?Brand $brand): self
  606.     {
  607.         $this->brand $brand;
  608.         return $this;
  609.     }
  610.     public function getShortDescription(): ?string
  611.     {
  612.         return $this->shortDescription;
  613.     }
  614.     public function setShortDescription(?string $shortDescription): self
  615.     {
  616.         $this->shortDescription $shortDescription;
  617.         return $this;
  618.     }
  619.     public function getIsPublished(): ?bool
  620.     {
  621.         return $this->isPublished;
  622.     }
  623.     public function setIsPublished(?bool $isPublished): self
  624.     {
  625.         $this->isPublished $isPublished;
  626.         return $this;
  627.     }
  628.     /**
  629.      * @return Collection|Comment[]
  630.      */
  631.     public function getComments(): Collection
  632.     {
  633.         return $this->comments;
  634.     }
  635.     public function addComment(Comment $comment): self
  636.     {
  637.         if (!$this->comments->contains($comment)) {
  638.             $this->comments[] = $comment;
  639.             $comment->setProduct($this);
  640.         }
  641.         return $this;
  642.     }
  643.     public function removeComment(Comment $comment): self
  644.     {
  645.         if ($this->comments->removeElement($comment)) {
  646.             // set the owning side to null (unless already changed)
  647.             if ($comment->getProduct() === $this) {
  648.                 $comment->setProduct(null);
  649.             }
  650.         }
  651.         return $this;
  652.     }
  653.     public function getStars5(){
  654.         //for 5 stars
  655.         $stars5=0;
  656.         foreach($this->comments as $singleComment){
  657.             if($singleComment->getRating() == 5){
  658.                 $stars5 $stars5 1;
  659.             }
  660.             
  661.         }
  662.         return $stars5;
  663.     }
  664.     public function getStars4(){
  665.         //for 4 stars
  666.         $stars4=0;
  667.         foreach($this->comments as $singleComment){
  668.             if($singleComment->getRating() == 4){
  669.                 $stars4 $stars4 1;
  670.             }
  671.             
  672.         }
  673.         return $stars4;
  674.     }
  675.     public function getStars3(){
  676.         //for 3 stars
  677.         $stars3=0;
  678.         foreach($this->comments as $singleComment){
  679.             if($singleComment->getRating() == 3){
  680.                 $stars3 $stars3 1;
  681.             }
  682.             
  683.         }
  684.         return $stars3;
  685.     }
  686.     public function getStars2(){
  687.         //for 2 stars
  688.         $stars2=0;
  689.         foreach($this->comments as $singleComment){
  690.             if($singleComment->getRating() == 2){
  691.                 $stars2 $stars2 1;
  692.             }
  693.             
  694.         }
  695.         return $stars2;
  696.     }
  697.     public function getStars1(){
  698.         //for 5 stars
  699.         $stars1=0;
  700.         foreach($this->comments as $singleComment){
  701.             if($singleComment->getRating() == 1){
  702.                 $stars1 $stars1 1;
  703.             }
  704.             
  705.         }
  706.         return $stars1;
  707.     }
  708.     public function getRating(){
  709.         $topRating 0;
  710.         $totalRating=0;
  711.         $stars5 $this->getStars5();
  712.         $stars4 $this->getStars4();
  713.         $stars3 $this->getStars3();
  714.         $stars2 $this->getStars2();
  715.         $stars1 $this->getStars1();
  716.         $topRating = ($stars1 ) + ($stars2 ) + ($stars3 ) + ($stars4 )+ ($stars5 );
  717.         $totalRating $stars1 $stars2 +$stars3 $stars4 $stars5;
  718.         
  719.         $result 0;
  720.         if($totalRating 0){
  721.             $result $topRating $totalRating;
  722.         }
  723.         
  724.         return $result;
  725.         
  726.     }
  727.     public function getSkuCodeShop(): ?string
  728.     {
  729.         if(!$this->skuCodeShop){
  730.             return $this->skuCodeShop "OM".$this->createdAt->format("ymdhs").$this->id;
  731.         }
  732.         return $this->skuCodeShop;
  733.     }
  734.     public function setSkuCodeShop(?string $skuCodeShop): self
  735.     {
  736.         $this->skuCodeShop $skuCodeShop;
  737.         return $this;
  738.     }
  739.     public function addCategoriesProduct(CategoryProduct $categoriesProduct): self
  740.     {
  741.         if (!$this->categoriesProduct->contains($categoriesProduct)) {
  742.             $this->categoriesProduct[] = $categoriesProduct;
  743.         }
  744.         return $this;
  745.     }
  746.     public function removeCategoriesProduct(CategoryProduct $categoriesProduct): self
  747.     {
  748.         $this->categoriesProduct->removeElement($categoriesProduct);
  749.         return $this;
  750.     }
  751.     public function getEndAt(): ?\DateTimeImmutable
  752.     {
  753.         return $this->endAt;
  754.     }
  755.     public function setEndAt(?\DateTimeImmutable $endAt): self
  756.     {
  757.         $this->endAt $endAt;
  758.         return $this;
  759.     }
  760.     public function getParentCategory(): ?CategoryProduct
  761.     {
  762.         return $this->parentCategory;
  763.     }
  764.     public function setParentCategory(?CategoryProduct $parentCategory): self
  765.     {
  766.         $this->parentCategory $parentCategory;
  767.         return $this;
  768.     }
  769.     public function getClonedProduct(): ?self
  770.     {
  771.         return $this->clonedProduct;
  772.     }
  773.     public function setClonedProduct(?self $clonedProduct): self
  774.     {
  775.         $this->clonedProduct $clonedProduct;
  776.         return $this;
  777.     }
  778.     public function getTypeReduction(): ?string
  779.     {
  780.         return $this->typeReduction;
  781.     }
  782.     public function setTypeReduction(?string $typeReduction): self
  783.     {
  784.         $this->typeReduction $typeReduction;
  785.         return $this;
  786.     }
  787.     public function getValueReduction(): ?float
  788.     {
  789.         return $this->valueReduction;
  790.     }
  791.     public function setValueReduction(?float $valueReduction): self
  792.     {
  793.         $this->valueReduction $valueReduction;
  794.         return $this;
  795.     }
  796.     /**
  797.      * @return Collection<int, ProductSubscription>
  798.      */
  799.     public function getProductSubscriptions(): Collection
  800.     {
  801.         return $this->productSubscriptions;
  802.     }
  803.     public function addProductSubscription(ProductSubscription $productSubscription): self
  804.     {
  805.         if (!$this->productSubscriptions->contains($productSubscription)) {
  806.             $this->productSubscriptions->add($productSubscription);
  807.             $productSubscription->setProduct($this);
  808.         }
  809.         return $this;
  810.     }
  811.     public function removeProductSubscription(ProductSubscription $productSubscription): self
  812.     {
  813.         if ($this->productSubscriptions->removeElement($productSubscription)) {
  814.             // set the owning side to null (unless already changed)
  815.             if ($productSubscription->getProduct() === $this) {
  816.                 $productSubscription->setProduct(null);
  817.             }
  818.         }
  819.         return $this;
  820.     }
  821.     public function getSubscriptionMonthlyPrice(): ?float
  822.     {
  823.         return $this->subscriptionMonthlyPrice;
  824.     }
  825.     public function setSubscriptionMonthlyPrice(?float $subscriptionMonthlyPrice): self
  826.     {
  827.         $this->subscriptionMonthlyPrice $subscriptionMonthlyPrice;
  828.         return $this;
  829.     }
  830.     public function getSubscriptionYearlyPrice(): ?float
  831.     {
  832.         return $this->subscriptionYearlyPrice;
  833.     }
  834.     public function setSubscriptionYearlyPrice(?float $subscriptionYearlyPrice): self
  835.     {
  836.         $this->subscriptionYearlyPrice $subscriptionYearlyPrice;
  837.         return $this;
  838.     }
  839.     public function getStore(): ?Store
  840.     {
  841.         return $this->store;
  842.     }
  843.     public function setStore(?Store $store): self
  844.     {
  845.         $this->store $store;
  846.         return $this;
  847.     }
  848.    
  849.     /**
  850.      * Get the value of deletedAt
  851.      */ 
  852.     public function getDeletedAt()
  853.     {
  854.         return $this->deletedAt;
  855.     }
  856.     /**
  857.      * Set the value of deletedAt
  858.      *
  859.      * @return  self
  860.      */ 
  861.     public function setDeletedAt($deletedAt)
  862.     {
  863.         $this->deletedAt $deletedAt;
  864.         return $this;
  865.     }
  866.   
  867.     /**
  868.      * @return Collection<int, ProductPack>
  869.      */
  870.     public function getChildrenProductsPack(): Collection
  871.     {
  872.         return $this->childrenProductsPack;
  873.     }
  874.     public function addChildrenProductsPack(ProductPack $childrenPackProduct): self
  875.     {
  876.         if (!$this->childrenProductsPack->contains($childrenPackProduct)) {
  877.             $this->childrenProductsPack->add($childrenPackProduct);
  878.             $childrenPackProduct->setParentProduct($this);
  879.         }
  880.         return $this;
  881.     }
  882.     public function removeChildrenProductsPack(ProductPack $childrenPackProduct): self
  883.     {
  884.         if ($this->childrenProductsPack->removeElement($childrenPackProduct)) {
  885.             // set the owning side to null (unless already changed)
  886.             if ($childrenPackProduct->getParentProduct() === $this) {
  887.                 $childrenPackProduct->setParentProduct(null);
  888.             }
  889.         }
  890.         return $this;
  891.     }
  892.     public function isLabelPriceFrom(): ?bool
  893.     {
  894.         return $this->labelPriceFrom;
  895.     }
  896.     public function setLabelPriceFrom(?bool $labelPriceFrom): self
  897.     {
  898.         $this->labelPriceFrom $labelPriceFrom;
  899.         return $this;
  900.     }
  901.     
  902.     #[Groups(['read''readDeep'])]
  903.     public function getDefaultQuantity()
  904.     {
  905.         
  906.         if($this->getProductType() == "pack"){
  907.             $quantity 0;
  908.             foreach($this->getChildrenProductsPack() as $childrenProduct){
  909.                 
  910.                 $quantity $quantity $childrenProduct->getQuantity();
  911.                 
  912.             }
  913.             return $quantity;
  914.         }
  915.         
  916.         
  917.         return 1;
  918.     }
  919.     public function getAttributes(){
  920.         $attributes = [];
  921.         if($this->productType == "variable"){
  922.             
  923.             foreach($this->attributValues as $singleAttrValue){
  924.                 if(!in_array($singleAttrValue->getAttribut()->getName(),$attributes)){
  925.                     $attributes[] =$singleAttrValue->getAttribut()->getName();
  926.                 }
  927.                 
  928.             }
  929.         }
  930.        
  931.         return $attributes;
  932.     }
  933.     public function setTranslatableLocale($locale)
  934.     {
  935.         $this->locale $locale;
  936.     }
  937.     /**
  938.      * @return Collection<int, ShippingMethod>
  939.      */
  940.     public function getIncludedShippingMethods(): Collection
  941.     {
  942.         return $this->includedShippingMethods;
  943.     }
  944.     public function addIncludedShippingMethod(ShippingMethod $includedShippingMethod): static
  945.     {
  946.         if (!$this->includedShippingMethods->contains($includedShippingMethod)) {
  947.             $this->includedShippingMethods->add($includedShippingMethod);
  948.         }
  949.         return $this;
  950.     }
  951.     public function removeIncludedShippingMethod(ShippingMethod $includedShippingMethod): static
  952.     {
  953.         $this->includedShippingMethods->removeElement($includedShippingMethod);
  954.         return $this;
  955.     }
  956.     public function getMetaData(): ?array
  957.     {
  958.         return $this->metaData;
  959.     }
  960.     public function setMetaData(?array $metaData): static
  961.     {
  962.         $this->metaData $metaData;
  963.         return $this;
  964.     }
  965.     public function getDefaultCurrency(): ?string
  966.     {
  967.         return $this->defaultCurrency;
  968.     }
  969.     public function setDefaultCurrency(?string $defaultCurrency): static
  970.     {
  971.         $this->defaultCurrency $defaultCurrency;
  972.         return $this;
  973.     }
  974.     /**
  975.      * @return Collection<int, PaymentMethod>
  976.      */
  977.     public function getIncludedPaymentMethods(): Collection
  978.     {
  979.         return $this->includedPaymentMethods;
  980.     }
  981.     public function addIncludedPaymentMethod(PaymentMethod $includedPaymentMethod): static
  982.     {
  983.         if (!$this->includedPaymentMethods->contains($includedPaymentMethod)) {
  984.             $this->includedPaymentMethods->add($includedPaymentMethod);
  985.         }
  986.         return $this;
  987.     }
  988.     public function removeIncludedPaymentMethod(PaymentMethod $includedPaymentMethod): static
  989.     {
  990.         $this->includedPaymentMethods->removeElement($includedPaymentMethod);
  991.         return $this;
  992.     }
  993.     public function getVideo(): ?string
  994.     {
  995.         return $this->video;
  996.     }
  997.     public function setVideo(?string $video): static
  998.     {
  999.         $this->video $video;
  1000.         return $this;
  1001.     }
  1002.     public function getVideoThumbnail(): ?string
  1003.     {
  1004.         return $this->videoThumbnail;
  1005.     }
  1006.     public function setVideoThumbnail(?string $videoThumbnail): static
  1007.     {
  1008.         $this->videoThumbnail $videoThumbnail;
  1009.         return $this;
  1010.     }
  1011.     public function getCostPrice(): ?float
  1012.     {
  1013.         return $this->costPrice;
  1014.     }
  1015.     public function setCostPrice(?float $costPrice): static
  1016.     {
  1017.         $this->costPrice $costPrice;
  1018.         return $this;
  1019.     }
  1020.     /**
  1021.      * @return Collection<int, Country>
  1022.      */
  1023.     public function getShipToCountries(): Collection
  1024.     {
  1025.         return $this->shipToCountries;
  1026.     }
  1027.     public function addShipToCountry(Country $shipToCountry): static
  1028.     {
  1029.         if (!$this->shipToCountries->contains($shipToCountry)) {
  1030.             $this->shipToCountries->add($shipToCountry);
  1031.         }
  1032.         return $this;
  1033.     }
  1034.     public function removeShipToCountry(Country $shipToCountry): static
  1035.     {
  1036.         $this->shipToCountries->removeElement($shipToCountry);
  1037.         return $this;
  1038.     }
  1039.    
  1040.   
  1041.     /**
  1042.      * Get the value of position
  1043.      */ 
  1044.     public function getPosition()
  1045.     {
  1046.         return $this->position;
  1047.     }
  1048.     /**
  1049.      * Set the value of position
  1050.      *
  1051.      * @return  self
  1052.      */ 
  1053.     public function setPosition($position)
  1054.     {
  1055.         $this->position $position;
  1056.         return $this;
  1057.     }
  1058. }