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

Open in your IDE?
  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Product;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Brand;
  5. use App\Flexy\ShopBundle\Entity\Order\OrderItem;
  6. use App\Flexy\ShopBundle\Entity\Product\CategoryProduct;
  7. use App\Flexy\ShopBundle\Entity\Promotion\Promotion;
  8. use App\Flexy\ShopBundle\Entity\Vendor\Vendor;
  9. use App\Flexy\ShopBundle\Repository\Product\ProductRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Doctrine\ORM\Mapping\Table;
  14. use Doctrine\ORM\Mapping\Entity;
  15. use Doctrine\ORM\Mapping\InheritanceType;
  16. use Gedmo\Mapping\Annotation as Gedmo;
  17. use \App\Flexy\ShopBundle\Entity\Customer\Customer;
  18. use Artgris\Bundle\MediaBundle\Form\Validator\Constraint as MediaAssert;
  19.  
  20. /**
  21.  * @ORM\Entity(repositoryClass=ProductRepository::class)
  22.  * @Table(name="product")
  23.  * @Entity
  24.  * @InheritanceType("JOINED")
  25.  */
  26. #[ApiResource]
  27. class Product
  28. {
  29.     /**
  30.      * @ORM\Id
  31.      * @ORM\GeneratedValue
  32.      * @ORM\Column(type="integer")
  33.      */
  34.     private $id;
  35.     /**
  36.      * @ORM\Column(type="string", length=255)
  37.      */
  38.     private $name;
  39.     /**
  40.      * @ORM\Column(type="string", length=255, nullable=true)
  41.      */
  42.     private $image;
  43.     /**
  44.      * @ORM\Column(type="float")
  45.      */
  46.     private $price;
  47.     /**
  48.      * @ORM\Column(type="text", nullable=true)
  49.      */
  50.     private $description;
  51.     /**
  52.      * @ORM\ManyToMany(targetEntity=CategoryProduct::class, inversedBy="products",cascade={"persist"})
  53.      */
  54.     private $categoriesProduct;
  55.     /**
  56.      * @ORM\OneToMany(targetEntity=AttributValue::class, mappedBy="product", cascade={"persist"})
  57.      */
  58.     private $attributValues;
  59.     /**
  60.      * @ORM\Column(type="float", nullable=true)
  61.      */
  62.     private $oldPrice;
  63.     /**
  64.      * @ORM\Column(type="integer", nullable=true)
  65.      */
  66.     private $quantity;
  67.     /**
  68.      * @ORM\Column(type="string", length=255, nullable=true)
  69.      */
  70.     private $productType;
  71.     /**
  72.      * @ORM\Column(type="string", length=255, nullable=true)
  73.      */
  74.     private $metaTitle;
  75.     /**
  76.      * @ORM\Column(type="string", length=255, nullable=true)
  77.      */
  78.     private $metaDescription;
  79.     /**
  80.      * @ORM\Column(type="simple_array", nullable=true)
  81.      */
  82.     private $metaKeywords = [];
  83.     /**
  84.      * @ORM\OneToMany(targetEntity=ImageProduct::class, mappedBy="product", cascade={"persist"})
  85.      */
  86.     private $images;
  87.     /**
  88.      * @ORM\Column(type="string", length=255, unique=true)
  89.      * @Gedmo\Slug(fields={"name"})
  90.     */
  91.     
  92.     private $slug;
  93.     /**
  94.      * @ORM\Column(type="datetime_immutable", nullable=true)
  95.      */
  96.     private $createdAt;
  97.     /**
  98.      * @ORM\OneToMany(targetEntity=ProductVariant::class, mappedBy="product",cascade={"persist"})
  99.      */
  100.     private $productVariants;
  101.     /**
  102.      * @ORM\Column(type="boolean", nullable=true)
  103.      */
  104.     private $isPriceReducedPerPercent;
  105.     /**
  106.      * @ORM\Column(type="float", nullable=true)
  107.      */
  108.     private $percentReduction;
  109.     /**
  110.      * @ORM\Column(type="string", length=255, nullable=true)
  111.      */
  112.     private $skuCode;
  113.     /**
  114.      * @ORM\OneToMany(targetEntity=OrderItem::class, mappedBy="product")
  115.      */
  116.     private $orderItems;
  117.     /**
  118.      * @ORM\ManyToOne(targetEntity=Promotion::class, inversedBy="products")
  119.      */
  120.     private $promotion;
  121.     /**
  122.      * @ORM\ManyToOne(targetEntity=Vendor::class, inversedBy="products")
  123.      */
  124.     private $vendor;
  125.     /**
  126.      * @ORM\ManyToOne(targetEntity=Brand::class, inversedBy="products",cascade={"persist"})
  127.      */
  128.     private $brand;
  129.     /**
  130.      * @ORM\Column(type="text", nullable=true)
  131.      */
  132.     private $shortDescription;
  133.     /**
  134.      * @ORM\Column(type="boolean", nullable=true)
  135.      */
  136.     private $isPublished;
  137.     /**
  138.      * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="product")
  139.      */
  140.     private $comments;
  141.     /**
  142.      * @ORM\Column(type="string", length=255, nullable=true)
  143.      */
  144.     private $skuCodeShop;
  145.     /**
  146.      * @ORM\Column(type="datetime_immutable", nullable=true)
  147.      */
  148.     private $endAt;
  149.     /**
  150.      * @ORM\ManyToOne(targetEntity=CategoryProduct::class, inversedBy="productsChildrens")
  151.      */
  152.     private $parentCategory;
  153.     /**
  154.      * @ORM\ManyToOne(targetEntity=Customer::class, inversedBy="products")
  155.      */
  156.     private $customer;
  157.     /**
  158.      * @ORM\Column(type="boolean", nullable=true)
  159.      */
  160.     private $isDeals;
  161.     /**
  162.      * @ORM\Column(type="float", nullable=true)
  163.      */
  164.     private $weight;
  165.      
  166.     
  167.     public function __construct()
  168.     {
  169.         $this->categoriesProduct = new ArrayCollection();
  170.         $this->attributValues = new ArrayCollection();
  171.         $this->productType "simple";
  172.         $this->createdAt = new \DateTimeImmutable();
  173.         $this->images = new ArrayCollection();
  174.         $this->productVariants = new ArrayCollection();
  175.         $this->orderItems = new ArrayCollection();
  176.         $this->comments = new ArrayCollection();
  177.   
  178.     }
  179.     public function __toString()
  180.     {
  181.         return $this->name;
  182.     }
  183.     public function getId(): ?int
  184.     {
  185.         return $this->id;
  186.     }
  187.     public function getName(): ?string
  188.     {
  189.         return $this->name;
  190.     }
  191.     public function setName(string $name): self
  192.     {
  193.         $this->name $name;
  194.         return $this;
  195.     }
  196.     public function getPrice(): ?float
  197.     {
  198.         return $this->price;
  199.     }
  200.     public function setPrice(float $price): self
  201.     {
  202.         $this->price $price;
  203.         return $this;
  204.     }
  205.     public function getDescription(): ?string
  206.     {
  207.         return $this->description;
  208.     }
  209.     public function setDescription(?string $description): self
  210.     {
  211.         $this->description $description;
  212.         return $this;
  213.     }
  214.     /**
  215.      * Get the value of image
  216.      */ 
  217.     public function getImage(): ?string
  218.     {
  219.         return $this->image;
  220.     }
  221.     /**
  222.      * Set the value of image
  223.      *
  224.      * @return  self
  225.      */ 
  226.     public function setImage(string $image): self
  227.     {
  228.         $this->image $image;
  229.         return $this;
  230.     }
  231.     /**
  232.      * @return Collection|CategoryProduct[]
  233.      */
  234.     public function getCategoriesProduct(): Collection
  235.     {
  236.         return $this->categoriesProduct;
  237.     }
  238.     public function addCategoryProduct(CategoryProduct $categoryProduct): self
  239.     {
  240.         if (!$this->categoriesProduct->contains($categoryProduct)) {
  241.             $this->categoriesProduct[] = $categoryProduct;
  242.             $categoryProduct->addProduct($this);
  243.         }
  244.         return $this;
  245.     }
  246.     public function removeCategoryProduct(CategoryProduct $categoryProduct): self
  247.     {
  248.         if ($this->categoriesProduct->removeElement($categoryProduct)) {
  249.             $categoryProduct->removeProduct($this);
  250.         }
  251.         return $this;
  252.     }
  253.     /**
  254.      * @return Collection|AttributValue[]
  255.      */
  256.     public function getAttributValues(): Collection
  257.     {
  258.         return $this->attributValues;
  259.     }
  260.     public function addAttributValue(AttributValue $attributValue): self
  261.     {
  262.         if (!$this->attributValues->contains($attributValue)) {
  263.             $this->attributValues[] = $attributValue;
  264.             $attributValue->setProduct($this);
  265.         }
  266.         return $this;
  267.     }
  268.     public function removeAttributValue(AttributValue $attributValue): self
  269.     {
  270.         if ($this->attributValues->removeElement($attributValue)) {
  271.             // set the owning side to null (unless already changed)
  272.             if ($attributValue->getProduct() === $this) {
  273.                 $attributValue->setProduct(null);
  274.             }
  275.         }
  276.         return $this;
  277.     }
  278.     public function getOldPrice(): ?float
  279.     {
  280.         return $this->oldPrice;
  281.     }
  282.     public function setOldPrice(?float $oldPrice): self
  283.     {
  284.         $this->oldPrice $oldPrice;
  285.         return $this;
  286.     }
  287.     public function getQuantity(): ?int
  288.     {
  289.         return $this->quantity;
  290.     }
  291.     public function setQuantity(?int $quantity): self
  292.     {
  293.         $this->quantity $quantity;
  294.         return $this;
  295.     }
  296.     public function getProductType(): ?string
  297.     {
  298.         return $this->productType;
  299.     }
  300.     public function setProductType(?string $productType): self
  301.     {
  302.         $this->productType $productType;
  303.         return $this;
  304.     }
  305.     public function getMetaTitle(): ?string
  306.     {
  307.         return $this->metaTitle;
  308.     }
  309.     public function setMetaTitle(?string $metaTitle): self
  310.     {
  311.         $this->metaTitle $metaTitle;
  312.         return $this;
  313.     }
  314.     public function getMetaDescription(): ?string
  315.     {
  316.         return $this->metaDescription;
  317.     }
  318.     public function setMetaDescription(?string $metaDescription): self
  319.     {
  320.         $this->metaDescription $metaDescription;
  321.         return $this;
  322.     }
  323.     public function getMetaKeywords(): ?array
  324.     {
  325.         return $this->metaKeywords;
  326.     }
  327.     public function setMetaKeywords(?array $metaKeywords): self
  328.     {
  329.         $this->metaKeywords $metaKeywords;
  330.         return $this;
  331.     }
  332.     /**
  333.      * @return Collection|ImageProduct[]
  334.      */
  335.     public function getImages(): Collection
  336.     {
  337.         return $this->images;
  338.     }
  339.     public function addImage(ImageProduct $image): self
  340.     {
  341.         if (!$this->images->contains($image)) {
  342.             $this->images[] = $image;
  343.             $image->setProduct($this);
  344.         }
  345.         return $this;
  346.     }
  347.     public function removeImage(ImageProduct $image): self
  348.     {
  349.         if ($this->images->removeElement($image)) {
  350.             // set the owning side to null (unless already changed)
  351.             if ($image->getProduct() === $this) {
  352.                 $image->setProduct(null);
  353.             }
  354.         }
  355.         return $this;
  356.     }
  357.     public function getSlug(): ?string
  358.     {
  359.         return $this->slug;
  360.     }
  361.     public function setSlug(string $slug): self
  362.     {
  363.         $this->slug $slug;
  364.         return $this;
  365.     }
  366.     public function getCreatedAt(): ?\DateTimeImmutable
  367.     {
  368.         return $this->createdAt;
  369.     }
  370.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  371.     {
  372.         $this->createdAt $createdAt;
  373.         return $this;
  374.     }
  375.     /**
  376.      * @return Collection|ProductVariant[]
  377.      */
  378.     public function getProductVariants(): Collection
  379.     {
  380.         return $this->productVariants;
  381.     }
  382.     public function addProductVariant(ProductVariant $productVariant): self
  383.     {
  384.         if (!$this->productVariants->contains($productVariant)) {
  385.             $this->productVariants[] = $productVariant;
  386.             $productVariant->setProduct($this);
  387.         }
  388.         return $this;
  389.     }
  390.     public function removeProductVariant(ProductVariant $productVariant): self
  391.     {
  392.         if ($this->productVariants->removeElement($productVariant)) {
  393.             // set the owning side to null (unless already changed)
  394.             if ($productVariant->getProduct() === $this) {
  395.                 $productVariant->setProduct(null);
  396.             }
  397.         }
  398.         return $this;
  399.     }
  400.     public function getIsPriceReducedPerPercent(): ?bool
  401.     {
  402.         return $this->isPriceReducedPerPercent;
  403.     }
  404.     public function setIsPriceReducedPerPercent(?bool $isPriceReducedPerPercent): self
  405.     {
  406.         $this->isPriceReducedPerPercent $isPriceReducedPerPercent;
  407.         return $this;
  408.     }
  409.     public function getPercentReduction(): ?float
  410.     {
  411.         return $this->percentReduction;
  412.     }
  413.     public function setPercentReduction(?float $percentReduction): self
  414.     {
  415.         $this->percentReduction $percentReduction;
  416.         return $this;
  417.     }
  418.     public function getSkuCode(): ?string
  419.     {
  420.         return $this->skuCode;
  421.     }
  422.     public function setSkuCode(?string $skuCode): self
  423.     {
  424.         $this->skuCode $skuCode;
  425.         return $this;
  426.     }
  427.     /**
  428.      * @return Collection|OrderItem[]
  429.      */
  430.     public function getOrderItems(): Collection
  431.     {
  432.         return $this->orderItems;
  433.     }
  434.     public function addOrderItem(OrderItem $orderItem): self
  435.     {
  436.         if (!$this->orderItems->contains($orderItem)) {
  437.             $this->orderItems[] = $orderItem;
  438.             $orderItem->setProduct($this);
  439.         }
  440.         return $this;
  441.     }
  442.     public function removeOrderItem(OrderItem $orderItem): self
  443.     {
  444.         if ($this->orderItems->removeElement($orderItem)) {
  445.             // set the owning side to null (unless already changed)
  446.             if ($orderItem->getProduct() === $this) {
  447.                 $orderItem->setProduct(null);
  448.             }
  449.         }
  450.         return $this;
  451.     }
  452.     public function getPromotion(): ?Promotion
  453.     {
  454.         return $this->promotion;
  455.     }
  456.     public function setPromotion(?Promotion $promotion): self
  457.     {
  458.         $this->promotion $promotion;
  459.         return $this;
  460.     }
  461.     public function getFormattedPrice(){
  462.         return $this->price 100;
  463.     }
  464.     public function getCommissionProduit(){
  465.           $total=0;
  466.             foreach($this->categoriesProduct as $commi){
  467.                 $total =  $commi->getCommission();
  468.     
  469.             }
  470.             return  $total;
  471.     
  472.     } 
  473.   public function getNameVendor(){
  474.     
  475.           return   $this->getVendor() ;
  476.   
  477.   } 
  478.     public function getVendor(): ?Vendor
  479.     {
  480.         return $this->vendor;
  481.     }
  482.     public function setVendor(?Vendor $vendor): self
  483.     {
  484.         $this->vendor $vendor;
  485.         return $this;
  486.     }
  487.     public function getBrand(): ?Brand
  488.     {
  489.         return $this->brand;
  490.     }
  491.     public function setBrand(?Brand $brand): self
  492.     {
  493.         $this->brand $brand;
  494.         return $this;
  495.     }
  496.     public function getShortDescription(): ?string
  497.     {
  498.         return $this->shortDescription;
  499.     }
  500.     public function setShortDescription(?string $shortDescription): self
  501.     {
  502.         $this->shortDescription $shortDescription;
  503.         return $this;
  504.     }
  505.     public function getIsPublished(): ?bool
  506.     {
  507.         return $this->isPublished;
  508.     }
  509.     public function setIsPublished(?bool $isPublished): self
  510.     {
  511.         $this->isPublished $isPublished;
  512.         return $this;
  513.     }
  514.     /**
  515.      * @return Collection|Comment[]
  516.      */
  517.     public function getComments(): Collection
  518.     {
  519.         return $this->comments;
  520.     }
  521.     public function addComment(Comment $comment): self
  522.     {
  523.         if (!$this->comments->contains($comment)) {
  524.             $this->comments[] = $comment;
  525.             $comment->setProduct($this);
  526.         }
  527.         return $this;
  528.     }
  529.     public function removeComment(Comment $comment): self
  530.     {
  531.         if ($this->comments->removeElement($comment)) {
  532.             // set the owning side to null (unless already changed)
  533.             if ($comment->getProduct() === $this) {
  534.                 $comment->setProduct(null);
  535.             }
  536.         }
  537.         return $this;
  538.     }
  539.     public function getStars5(){
  540.         //for 5 stars
  541.         $stars5=0;
  542.         foreach($this->comments as $singleComment){
  543.             if($singleComment->getRating() == 5){
  544.                 $stars5 $stars5 1;
  545.             }
  546.             
  547.         }
  548.         return $stars5;
  549.     }
  550.     public function getStars4(){
  551.         //for 4 stars
  552.         $stars4=0;
  553.         foreach($this->comments as $singleComment){
  554.             if($singleComment->getRating() == 4){
  555.                 $stars4 $stars4 1;
  556.             }
  557.             
  558.         }
  559.         return $stars4;
  560.     }
  561.     public function getStars3(){
  562.         //for 3 stars
  563.         $stars3=0;
  564.         foreach($this->comments as $singleComment){
  565.             if($singleComment->getRating() == 3){
  566.                 $stars3 $stars3 1;
  567.             }
  568.             
  569.         }
  570.         return $stars3;
  571.     }
  572.     public function getStars2(){
  573.         //for 2 stars
  574.         $stars2=0;
  575.         foreach($this->comments as $singleComment){
  576.             if($singleComment->getRating() == 2){
  577.                 $stars2 $stars2 1;
  578.             }
  579.             
  580.         }
  581.         return $stars2;
  582.     }
  583.     public function getStars1(){
  584.         //for 5 stars
  585.         $stars1=0;
  586.         foreach($this->comments as $singleComment){
  587.             if($singleComment->getRating() == 1){
  588.                 $stars1 $stars1 1;
  589.             }
  590.             
  591.         }
  592.         return $stars1;
  593.     }
  594.     public function getRating(){
  595.         $topRating 0;
  596.         $totalRating=0;
  597.         $stars5 $this->getStars5();
  598.         $stars4 $this->getStars4();
  599.         $stars3 $this->getStars3();
  600.         $stars2 $this->getStars2();
  601.         $stars1 $this->getStars1();
  602.         $topRating = ($stars1 ) + ($stars2 ) + ($stars3 ) + ($stars4 )+ ($stars5 );
  603.         $totalRating $stars1 $stars2 +$stars3 $stars4 $stars5;
  604.         
  605.         $result 0;
  606.         if($totalRating 0){
  607.             $result $topRating $totalRating;
  608.         }
  609.         
  610.         return $result;
  611.         
  612.     }
  613.     public function getSkuCodeShop(): ?string
  614.     {
  615.         if(!$this->skuCodeShop){
  616.             return $this->skuCodeShop "OM".$this->createdAt->format("ymdhs").$this->id;
  617.         }
  618.         return $this->skuCodeShop;
  619.     }
  620.     public function setSkuCodeShop(?string $skuCodeShop): self
  621.     {
  622.         $this->skuCodeShop $skuCodeShop;
  623.         return $this;
  624.     }
  625.     public function addCategoriesProduct(CategoryProduct $categoriesProduct): self
  626.     {
  627.         if (!$this->categoriesProduct->contains($categoriesProduct)) {
  628.             $this->categoriesProduct[] = $categoriesProduct;
  629.         }
  630.         return $this;
  631.     }
  632.     public function removeCategoriesProduct(CategoryProduct $categoriesProduct): self
  633.     {
  634.         $this->categoriesProduct->removeElement($categoriesProduct);
  635.         return $this;
  636.     }
  637.     public function getEndAt(): ?\DateTimeImmutable
  638.     {
  639.         return $this->endAt;
  640.     }
  641.     public function setEndAt(?\DateTimeImmutable $endAt): self
  642.     {
  643.         $this->endAt $endAt;
  644.         return $this;
  645.     }
  646.     public function getParentCategory(): ?CategoryProduct
  647.     {
  648.         return $this->parentCategory;
  649.     }
  650.     public function setParentCategory(?CategoryProduct $parentCategory): self
  651.     {
  652.         $this->parentCategory $parentCategory;
  653.         return $this;
  654.     }
  655.     public function getCustomer(): ?Customer
  656.     {
  657.         return $this->customer;
  658.     }
  659.     public function setCustomer(?Customer $customer): self
  660.     {
  661.         $this->customer $customer;
  662.         return $this;
  663.     }
  664.     public function getIsDeals(): ?bool
  665.     {
  666.         return $this->isDeals;
  667.     }
  668.     public function setIsDeals(?bool $isDeals): self
  669.     {
  670.         $this->isDeals $isDeals;
  671.         return $this;
  672.     }
  673.     public function getWeight(): ?float
  674.     {
  675.         return $this->weight;
  676.     }
  677.     public function setWeight(?float $weight): self
  678.     {
  679.         $this->weight $weight;
  680.         return $this;
  681.     }
  682.  
  683.  
  684.    
  685. }