<?php
namespace App\Entity;
use App\Repository\ProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=ProductRepository::class)
*/
class Product
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $moreInformation;
/**
* @Assert\Type(type="float", message="Type a float (eg 10.25)")
* @ORM\Column(type="float")
*/
private $price;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isBestSeller = false;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isNewArrival = false;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isFeatured = false;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isSpecialOffer = false;
/**
* @ORM\Column(type="string", length=255)
*/
private $image;
/**
* @ORM\Column(type="integer")
*/
private $quantity;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $tags;
/**
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\ManyToMany(targetEntity=Shop::class, inversedBy="produit")
*/
private $shops;
/**
* @ORM\OneToMany(targetEntity=ProductImages::class, mappedBy="product", cascade={"persist"})
*/
private $productImages;
/**
* @ORM\Column(type="boolean")
*/
private $isPromotionalPrice;
/**
* @ORM\Column(type="float")
*/
private $promotionalPrice;
/**
* @ORM\Column(type="integer")
*/
private $pourcentagePromotionalPrice;
/**
* @ORM\Column(type="boolean")
*/
private $etat;
/**
* @ORM\Column(type="bigint")
*/
private $nombreVue;
/**
* @ORM\ManyToMany(targetEntity=Categories::class, inversedBy="products")
*/
private $category;
/**
* @ORM\OneToMany(targetEntity=RelatedProduct::class, mappedBy="product")
*/
private $relatedProducts;
/**
* @ORM\OneToMany(targetEntity=ReviewsProduct::class, mappedBy="product")
*/
private $reviewsProducts;
/**
* @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="product")
*/
private $tag;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $poidNet;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $longueur;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $largeur;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $hauteur;
/**
* @ORM\Column(type="integer")
*/
private $minCommande;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $pieceInPackage;
/**
* @ORM\ManyToMany(targetEntity=Colors::class, inversedBy="products")
*/
private $colors;
/**
* @ORM\ManyToMany(targetEntity=Size::class, inversedBy="products")
*/
private $sizes;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="products")
*/
private $user;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $ImageDeSpecification;
/**
* @ORM\Column(type="float")
*/
private $maxPrice;
/**
* @ORM\Column(type="integer")
*/
private $maxCommande;
/**
* @ORM\ManyToMany(targetEntity=Emballage::class, inversedBy="products")
*/
private $emballage;
/**
* @ORM\OneToMany(targetEntity=PriceInterval::class, cascade={"persist","remove"} ,mappedBy="product")
*/
private $priceIntervals;
private $reelPrice;
private $reelMaxPrice;
private $reelPriceRmb;
private $reelMaxPriceRmb;
/**
* @var SessionInterface
*/
private $session;
public function __construct()
{
$this->category = new ArrayCollection();
$this->tagsProducts = new ArrayCollection();
$this->relatedProducts = new ArrayCollection();
$this->reviewsProducts = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->quantity = 0;
$this->price = 0;
$this->maxPrice = 0;
$this->shops = new ArrayCollection();
$this->productImages = new ArrayCollection();
$this->setIsPromotionalPrice(false);
$this->tag = new ArrayCollection();
$this->description = '
<div style="width:80%">
<h2>Product All description</h2>
<table border="1" cellpadding="0" cellspacing="0" style="float:right; height:111px; width:270px">
<caption><strong>Specification</strong></caption>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
<p>Type the text here</p>
</div>
';
$this->longueur = 0;
$this->largeur = 0;
$this->hauteur = 0;
$this->poidNet = 0;
$this->minCommande = 1;
$this->maxCommande = 10;
$this->pieceInPackage = 1;
$this->colors = new ArrayCollection();
$this->sizes = new ArrayCollection();
$this->emballage = new ArrayCollection();
$this->priceIntervals = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getMoreInformation(): ?string
{
return $this->moreInformation;
}
public function setMoreInformation(?string $moreInformation): self
{
$this->moreInformation = $moreInformation;
return $this;
}
public function getPrice(): ?float
{
$price = $this->price;
//dd($_SESSION['_sf2_attributes']['devise']);
/* convertion taux */
if(isset($_SESSION['_sf2_attributes']['devise'])){
if($_SESSION['_sf2_attributes']['devise'] == '$'){
$price = $this->price / 6.48;
}
}
/* Pourcentage de reduction pour le prix promotionnel */
if($this->getIsPromotionalPrice() === true){
$price = $price - (($price/100) * $this->getPourcentagePromotionalPrice());
return round($price,2);
}
return round($price,2);
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function getMaxPrice(): ?float
{
$price = $this->maxPrice;
if(isset($_SESSION['_sf2_attributes']['devise'])){
if($_SESSION['_sf2_attributes']['devise'] === '$'){
$price = $this->maxPrice / 6.48;
}
}
if($this->getIsPromotionalPrice() === true){
$price = $this->maxPrice - (($this->maxPrice/100) * $this->getPourcentagePromotionalPrice());
return round($price,2);
}
return round($price,2);
}
public function setMaxPrice(float $maxPrice): self
{
$this->maxPrice = $maxPrice;
return $this;
}
public function getIsBestSeller(): ?bool
{
return $this->isBestSeller;
}
public function setIsBestSeller(?bool $isBestSeller): self
{
$this->isBestSeller = $isBestSeller;
return $this;
}
public function getIsNewArrival(): ?bool
{
return $this->isNewArrival;
}
public function setIsNewArrival(?bool $isNewArrival): self
{
$this->isNewArrival = $isNewArrival;
return $this;
}
public function getIsFeatured(): ?bool
{
return $this->isFeatured;
}
public function setIsFeatured(?bool $isFeatured): self
{
$this->isFeatured = $isFeatured;
return $this;
}
public function getIsSpecialOffer(): ?bool
{
return $this->isSpecialOffer;
}
public function setIsSpecialOffer(?bool $isSpecialOffer): self
{
$this->isSpecialOffer = $isSpecialOffer;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(string $image): self
{
$this->image = $image;
return $this;
}
/**
* @return Collection|RelatedProduct[]
*/
public function getRelatedProducts(): Collection
{
return $this->relatedProducts;
}
public function addRelatedProduct(RelatedProduct $relatedProduct): self
{
if (!$this->relatedProducts->contains($relatedProduct)) {
$this->relatedProducts[] = $relatedProduct;
$relatedProduct->setProduct($this);
}
return $this;
}
public function removeRelatedProduct(RelatedProduct $relatedProduct): self
{
if ($this->relatedProducts->removeElement($relatedProduct)) {
// set the owning side to null (unless already changed)
if ($relatedProduct->getProduct() === $this) {
$relatedProduct->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|ReviewsProduct[]
*/
public function getReviewsProducts(): Collection
{
return $this->reviewsProducts;
}
public function addReviewsProduct(ReviewsProduct $reviewsProduct): self
{
if (!$this->reviewsProducts->contains($reviewsProduct)) {
$this->reviewsProducts[] = $reviewsProduct;
$reviewsProduct->setProduct($this);
}
return $this;
}
public function removeReviewsProduct(ReviewsProduct $reviewsProduct): self
{
if ($this->reviewsProducts->removeElement($reviewsProduct)) {
// set the owning side to null (unless already changed)
if ($reviewsProduct->getProduct() === $this) {
$reviewsProduct->setProduct(null);
}
}
return $this;
}
public function __toString(){
return $this->name;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getTags(): ?string
{
return $this->tags;
}
public function setTags(?string $tags): self
{
$this->tags = $tags;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return Collection|Shop[]
*/
public function getShops(): Collection
{
return $this->shops;
}
public function addShop(Shop $shop): self
{
if (!$this->shops->contains($shop)) {
$this->shops[] = $shop;
}
return $this;
}
public function removeShop(Shop $shop): self
{
$this->shops->removeElement($shop);
return $this;
}
/**
* @return Collection|Categories[]
*/
public function getCategory(): Collection
{
return $this->category;
}
public function addCategory(Categories $category): self
{
if (!$this->category->contains($category)) {
$this->category[] = $category;
}
return $this;
}
public function removeCategory(Categories $category): self
{
$this->category->removeElement($category);
return $this;
}
/**
* @return Collection|ProductImages[]
*/
public function getProductImages(): Collection
{
return $this->productImages;
}
public function addProductImage(ProductImages $productImage): self
{
if (!$this->productImages->contains($productImage)) {
$this->productImages[] = $productImage;
$productImage->setProduct($this);
}
return $this;
}
public function removeProductImage(ProductImages $productImage): self
{
if ($this->productImages->removeElement($productImage)) {
// set the owning side to null (unless already changed)
if ($productImage->getProduct() === $this) {
$productImage->setProduct(null);
}
}
return $this;
}
public function getIsPromotionalPrice(): ?bool
{
return $this->isPromotionalPrice;
}
public function setIsPromotionalPrice(bool $isPromotionalPrice): self
{
$this->isPromotionalPrice = $isPromotionalPrice;
return $this;
}
public function getPromotionalPrice(): ?float
{
return $this->promotionalPrice;
}
public function setPromotionalPrice(float $promotionalPrice): self
{
$this->promotionalPrice = $promotionalPrice;
return $this;
}
public function getPourcentagePromotionalPrice(): ?int
{
return $this->pourcentagePromotionalPrice;
}
public function setPourcentagePromotionalPrice(int $pourcentagePromotionalPrice): self
{
$this->pourcentagePromotionalPrice = $pourcentagePromotionalPrice;
return $this;
}
public function getEtat(): ?bool
{
return $this->etat;
}
public function setEtat(bool $etat): self
{
$this->etat = $etat;
return $this;
}
public function getNombreVue(): ?string
{
return $this->nombreVue;
}
public function setNombreVue(int $nombreVue): self
{
$this->nombreVue = $this->nombreVue + $nombreVue;
return $this;
}
/**
* @return Collection|Tag[]
*/
public function getTag(): Collection
{
return $this->tag;
}
public function addTag(Tag $tag): self
{
if (!$this->tag->contains($tag)) {
$this->tag[] = $tag;
$tag->addProduct($this);
}
return $this;
}
public function removeTag(Tag $tag): self
{
if ($this->tag->removeElement($tag)) {
$tag->removeProduct($this);
}
return $this;
}
public function getPoidNet(): ?int
{
return $this->poidNet;
}
public function setPoidNet(?int $poidNet): self
{
$this->poidNet = $poidNet;
return $this;
}
public function getLongueur(): ?float
{
return $this->longueur;
}
public function setLongueur(?float $longueur): self
{
$this->longueur = $longueur;
return $this;
}
public function getLargeur(): ?float
{
return $this->largeur;
}
public function setLargeur(?float $largeur): self
{
$this->largeur = $largeur;
return $this;
}
public function getHauteur(): ?float
{
return $this->hauteur;
}
public function setHauteur(?float $hauteur): self
{
$this->hauteur = $hauteur;
return $this;
}
public function getMinCommande(): ?float
{
return $this->minCommande;
}
public function setMinCommande(float $minCommande): self
{
$this->minCommande = $minCommande;
return $this;
}
public function getPieceInPackage(): ?int
{
return $this->pieceInPackage;
}
public function setPieceInPackage(?int $pieceInPackage): self
{
$this->pieceInPackage = $pieceInPackage;
return $this;
}
/**
* @return Collection|Colors[]
*/
public function getColors(): Collection
{
return $this->colors;
}
public function addColor(Colors $color): self
{
if (!$this->colors->contains($color)) {
$this->colors[] = $color;
}
return $this;
}
public function removeColor(Colors $color): self
{
$this->colors->removeElement($color);
return $this;
}
/**
* @return Collection|Size[]
*/
public function getSizes(): Collection
{
return $this->sizes;
}
public function addSize(Size $size): self
{
if (!$this->sizes->contains($size)) {
$this->sizes[] = $size;
}
return $this;
}
public function removeSize(Size $size): self
{
$this->sizes->removeElement($size);
return $this;
}
public function getUser(): ?user
{
return $this->user;
}
public function setUser(?user $user): self
{
$this->user = $user;
return $this;
}
public function getImageDeSpecification(): ?string
{
return $this->ImageDeSpecification;
}
public function setImageDeSpecification(?string $ImageDeSpecification): self
{
$this->ImageDeSpecification = $ImageDeSpecification;
return $this;
}
/**
* @return Collection|Emballage[]
*/
public function getEmballage(): Collection
{
return $this->emballage;
}
public function addEmballage(Emballage $emballage): self
{
if (!$this->emballage->contains($emballage)) {
$this->emballage[] = $emballage;
}
return $this;
}
public function removeEmballage(Emballage $emballage): self
{
$this->emballage->removeElement($emballage);
return $this;
}
/**
* @return mixed
*/
public function getMaxCommande()
{
return $this->maxCommande;
}
public function setMaxCommande(float $maxCommande): self
{
$this->maxCommande = $maxCommande;
return $this;
}
/**
* @return Collection|PriceInterval[]
*/
public function getPriceIntervals(): Collection
{
return $this->priceIntervals;
}
public function addPriceInterval(PriceInterval $priceInterval): self
{
if (!$this->priceIntervals->contains($priceInterval)) {
$this->priceIntervals[] = $priceInterval;
$priceInterval->setProduct($this);
}
return $this;
}
public function removePriceInterval(PriceInterval $priceInterval): self
{
if ($this->priceIntervals->removeElement($priceInterval)) {
// set the owning side to null (unless already changed)
if ($priceInterval->getProduct() === $this) {
$priceInterval->setProduct(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getReelPrice()
{
$price = $this->price;
if(isset($_SESSION['_sf2_attributes']['devise'])){
if($_SESSION['_sf2_attributes']['devise'] == '$'){
$price = round( $this->price / 6.48,2);
}
}
return $this->reelPrice = $price;
}
/**
* @return mixed
*/
public function getReelMaxPrice()
{
$price = $this->maxPrice;
if(isset($_SESSION['_sf2_attributes']['devise'])){
if($_SESSION['_sf2_attributes']['devise'] == '$'){
$price = round($this->maxPrice / 6.48,2);
}
}
return $this->reelMaxPrice = $price;
}
/**
* @return mixed
*/
public function getReelPriceRmb()
{
return $this->reelPriceRmb = $this->price;
}
/**
* @return mixed
*/
public function getReelMaxPriceRmb()
{
return $this->reelMaxPriceRmb = $this->maxPrice;
}
}