<?php
namespace App\Entity;
use App\Interfaces\ProductInterface;
use App\Repository\CustomerProductRepository;
use App\Traits\DateTrait;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=CustomerProductRepository::class)
* @ORM\HasLifecycleCallbacks()
*
* @Vich\Uploadable
* @Serializer\ExclusionPolicy("ALL")
*/
class CustomerProduct implements ProductInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Expose()
* @Groups({"id"})
*/
private ?int $id = null;
/**
* Référence
* @ORM\Column(type="string", length=255)
*
* @Expose
* @Groups({"sku"})
*/
private ?string $sku = null;
/**
* @ORM\Column(type="string", length=255)
*
* @Expose()
* @Groups({"name"})
*/
private ?string $name = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $description = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @Expose()
* @Serializer\Groups({"image"})
*/
private ?string $image = null;
// Vich Uploader
/**
* @Vich\UploadableField(mapping="customer_product_images", fileNameProperty="image")
* @var File
*/
private $imageFile;
/**
* @ORM\Column(type="float", nullable=true)
*/
private ?float $ratePrice = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $categoryValues = null;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*
* @Expose()
* @Serializer\Groups({"category"})
*/
private ?string $category = null;
/**
* @ORM\Column(type="boolean")
*
* @Expose()
* @Serializer\Groups({"enabled"})
*/
private $enabled = true;
use DateTrait;
/**
* @Serializer\VirtualProperty()
* @Serializer\SerializedName("array_category_values")
*
* @Expose()
* @Groups({"array_category_values"})
* @return mixed
*/
public function getArrayCategoryValues()
{
return json_decode($this->categoryValues, TRUE) ?? [];
}
/**
* @param string $slug
* @param int $value
*
* @return $this
*/
public function modifyValueToCategory(string $slug, int $value): self
{
$newArray = $this->getArrayCategoryValues();
$newArray[ $slug ] = $value;
$this->categoryValues = json_encode($newArray);
return $this;
}
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 getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param File $imageFile
*
* @return void
*/
public function setImageFile(File $imageFile): void
{
$this->imageFile = $imageFile;
if (NULL !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new DateTime();
}
}
public function getRatePrice(): ?float
{
return $this->ratePrice;
}
public function setRatePrice(?float $ratePrice): self
{
$this->ratePrice = $ratePrice;
return $this;
}
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory(?string $category): self
{
$this->category = $category;
return $this;
}
public function getCategoryValues()
{
return $this->categoryValues;
}
public function setCategoryValues($categoryValues): CustomerProduct
{
$this->categoryValues = $categoryValues;
return $this;
}
/**
* @return mixed
*/
public function getEnabled()
{
return $this->enabled;
}
/**
* @param mixed $enabled
*
* @return CustomerProduct
*/
public function setEnabled($enabled): CustomerProduct
{
$this->enabled = $enabled;
return $this;
}
// methode pour matcher avec la mise au panier du customerProduct
public function getPriceHT(): ?float
{
return $this->getRatePrice();
}
// methode pour matcher avec la mise au panier du customerProduct
public function getPriceTTC(): ?float
{
return $this->getRatePrice();
}
// methode pour matcher avec la mise au panier du customerProduct
public function getPrice(): ?float
{
return $this->getRatePrice();
}
public function getSku(): string
{
return $this->sku;
}
public function setSku(string $sku): self
{
$this->sku = $sku;
return $this;
}
}