src/Entity/Gos/SalesManagoProductVariant.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use App\Repository\SalesManagoProductVariantRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Component\Validator\Mapping\ClassMetadata;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. /**
  12.  * @ORM\Entity(repositoryClass=SalesManagoProductVariantRepository::class)
  13.  * @Vich\Uploadable
  14.  */
  15. class SalesManagoProductVariant
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\OneToOne(targetEntity=ProductVariant::class, inversedBy="salesManagoProductVariant", cascade={"persist", "remove"})
  25.      * @ORM\JoinColumn(nullable=false)
  26.      */
  27.     private $productVariant;
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      */
  31.     private $name;
  32.     /**
  33.      * @ORM\Column(type="string", length=255)
  34.      */
  35.     private $category;
  36.     /**
  37.      * @ORM\Column(type="text", nullable=true)
  38.      */
  39.     private $description;
  40.     /**
  41.      * @ORM\Column(type="string", length=512)
  42.      */
  43.     private $productUrl;
  44.     /**
  45.      * @ORM\Column(type="boolean", nullable=true)
  46.      */
  47.     private $bestseller;
  48.     /**
  49.      * @ORM\Column(type="boolean")
  50.      */
  51.     private $newProduct;
  52.     /**
  53.      * @ORM\Column(type="float", nullable=true)
  54.      */
  55.     private $discountPrice;
  56.     /**
  57.      * @ORM\Column(type="string", length=255, nullable=true)
  58.      */
  59.     private $mainImageUrl;
  60.     /**
  61.      * @ORM\Column(type="boolean", nullable=true)
  62.      */
  63.     private $useUploadedMainImage;
  64.     /**
  65.      * @ORM\Column(type="string", length=255, nullable=true)
  66.      * @var string
  67.      */
  68.     private $uploadedMainImage;
  69.     /**
  70.      * @Vich\UploadableField(mapping="sales_manago_product_variant_image", fileNameProperty="uploadedMainImage")
  71.      */
  72.     private $mainImageFile;
  73.     /**
  74.      * @ORM\OneToMany(targetEntity=SalesManagoProductVariantImage::class, mappedBy="productVariant", orphanRemoval=true, cascade={"persist"})
  75.      * @Assert\Count(max=2, maxMessage="You can upload maximum {{ limit }} images")
  76.      */
  77.     private $images;
  78.     /**
  79.      * @ORM\Column(type="datetime", nullable=true)
  80.      */
  81.     private $updatedAt;
  82.     public function __construct()
  83.     {
  84.         $this->images = new ArrayCollection();
  85.     }
  86.     public static function loadValidatorMetadata(ClassMetadata $metadata): void
  87.     {
  88.         $metadata->addPropertyConstraint('images', new Assert\Count([
  89.             'max' => 2,
  90.             'maxMessage' => 'You cannot specify more than {{ limit }} emails',
  91.         ]));
  92.     }
  93.     public function getId(): ?int
  94.     {
  95.         return $this->id;
  96.     }
  97.     public function getProductVariant(): ?ProductVariant
  98.     {
  99.         return $this->productVariant;
  100.     }
  101.     public function setProductVariant(ProductVariant $productVariant): self
  102.     {
  103.         $this->productVariant $productVariant;
  104.         return $this;
  105.     }
  106.     public function getName(): ?string
  107.     {
  108.         return $this->name;
  109.     }
  110.     public function setName(?string $name): self
  111.     {
  112.         $this->name $name;
  113.         return $this;
  114.     }
  115.     public function getCategory(): ?string
  116.     {
  117.         return $this->category;
  118.     }
  119.     public function setCategory(?string $category): self
  120.     {
  121.         $this->category $category;
  122.         return $this;
  123.     }
  124.     public function getDescription(): ?string
  125.     {
  126.         return $this->description;
  127.     }
  128.     public function setDescription(?string $description): self
  129.     {
  130.         $this->description $description;
  131.         return $this;
  132.     }
  133.     public function getProductUrl(): ?string
  134.     {
  135.         return $this->productUrl;
  136.     }
  137.     public function setProductUrl(?string $productUrl): self
  138.     {
  139.         $this->productUrl $productUrl;
  140.         return $this;
  141.     }
  142.     public function getBestseller(): ?bool
  143.     {
  144.         return $this->bestseller;
  145.     }
  146.     public function setBestseller(?bool $bestseller): self
  147.     {
  148.         $this->bestseller $bestseller;
  149.         return $this;
  150.     }
  151.     public function getNewProduct(): ?bool
  152.     {
  153.         return $this->newProduct;
  154.     }
  155.     public function setNewProduct(bool $newProduct): self
  156.     {
  157.         $this->newProduct $newProduct;
  158.         return $this;
  159.     }
  160.     public function getDiscountPrice(): ?float
  161.     {
  162.         return $this->discountPrice;
  163.     }
  164.     public function setDiscountPrice(?float $discountPrice): self
  165.     {
  166.         $this->discountPrice $discountPrice;
  167.         return $this;
  168.     }
  169.     public function getMainImageUrl(): ?string
  170.     {
  171.         return $this->mainImageUrl;
  172.     }
  173.     public function setMainImageUrl(?string $mainImageUrl): self
  174.     {
  175.         $this->mainImageUrl $mainImageUrl;
  176.         return $this;
  177.     }
  178.     public function getUseUploadedMainImage(): ?bool
  179.     {
  180.         return $this->useUploadedMainImage;
  181.     }
  182.     public function setUseUploadedMainImage(?bool $useUploadedMainImage): self
  183.     {
  184.         $this->useUploadedMainImage $useUploadedMainImage;
  185.         return $this;
  186.     }
  187.     public function getUploadedMainImage(): ?string
  188.     {
  189.         return $this->uploadedMainImage;
  190.     }
  191.     public function setUploadedMainImage(?string $uploadedMainImage): self
  192.     {
  193.         $this->uploadedMainImage $uploadedMainImage;
  194.         return $this;
  195.     }
  196.     public function setMainImageFile(?File $mainImageFile null)
  197.     {
  198.         $this->mainImageFile $mainImageFile;
  199.         // VERY IMPORTANT:
  200.         // It is required that at least one field changes if you are using Doctrine,
  201.         // otherwise the event listeners won't be called and the file is lost
  202.         if ($mainImageFile)
  203.         {
  204.             // if 'updatedAt' is not defined in your entity, use another property
  205.             $this->updatedAt = new \DateTime('now');
  206.         }
  207.     }
  208.     public function getMainImageFile(): ?File
  209.     {
  210.         return $this->mainImageFile;
  211.     }
  212.     public function getImages(): Collection
  213.     {
  214.         return $this->images;
  215.     }
  216.     public function addImage(SalesManagoProductVariantImage $image): self
  217.     {
  218.         if (!$this->images->contains($image)) {
  219.             $this->images[] = $image;
  220.             $image->setProductVariant($this);
  221.         }
  222.         return $this;
  223.     }
  224.     public function removeImage(SalesManagoProductVariantImage $image): self
  225.     {
  226.         if ($this->images->contains($image)) {
  227.             $this->images->removeElement($image);
  228.             // set the owning side to null (unless already changed)
  229.             if ($image->getProductVariant() === $this) {
  230.                 $image->setProductVariant(null);
  231.             }
  232.         }
  233.         return $this;
  234.     }
  235.     public function setUpdatedAt($updatedAt)
  236.     {
  237.         $this->updatedAt $updatedAt;
  238.         return $this;
  239.     }
  240.     public function getUpdatedAt()
  241.     {
  242.         return $this->updatedAt;
  243.     }
  244. }