src/IlaveU/ShopBundle/Entity/Product/AttributValue.php line 19
<?phpnamespace App\IlaveU\ShopBundle\Entity\Product;use ApiPlatform\Core\Annotation\ApiResource;use App\IlaveU\ShopBundle\Repository\Product\AttributValueRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Serializer\Annotation\Groups;#[ApiResource(normalizationContext: ['groups' => ['read']],denormalizationContext: ['groups' => ['write']],)]#[ORM\Entity(repositoryClass: AttributValueRepository::class)]#[ORM\Cache(usage:"NONSTRICT_READ_WRITE",region:"append_depend")]class AttributValue implements \Stringable{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column(type: 'integer')]#[Groups(['read', 'write'])]private $id;#[Groups(['read', 'write'])]#[ORM\Column(type: 'text', nullable: true)]private ?string $description = null;#[ORM\Column(type: 'datetime_immutable', nullable: true)]private ?\DateTimeImmutable $createdAt = null;#[ORM\ManyToOne(targetEntity: Attribut::class, inversedBy: 'attributValues',cascade:[ "persist" ])]#[Groups(['read', 'write'])]private ?\App\IlaveU\ShopBundle\Entity\Product\Attribut $attribut = null;#[ORM\Column(type: 'string', length: 255,nullable:true)]private ?string $value = null;#[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'attributValues', cascade: ['persist'])]private ?\App\IlaveU\ShopBundle\Entity\Product\Product $product = null;#[ORM\Column(type: 'float', nullable: true)]#[Groups(['read', 'write'])]private ?float $price = null;#[ORM\Column(type: 'integer', nullable: true)]#[Groups(['read', 'write'])]private ?int $quantity = null;#[ORM\ManyToMany(targetEntity: ProductVariant::class, mappedBy: 'attributeValues')]private \Doctrine\Common\Collections\Collection|array $productVariants;#[ORM\Column(length: 255, nullable: true)]private ?string $image = null;#[ORM\Column(length: 255, nullable: true)]private ?string $skuCode = null;#[ORM\Column(nullable: true)]private ?float $costPrice = null;public function __construct(){$this->productVariants = new ArrayCollection();}public function __toString(): string{return $this->attribut ." : ". $this->value;}public function getId(): ?int{return $this->id;}public function getDescription(): ?string{return $this->description;}public function setDescription(?string $description): self{$this->description = $description;return $this;}public function getCreatedAt(): ?\DateTimeImmutable{return $this->createdAt;}public function setCreatedAt(?\DateTimeImmutable $createdAt): self{$this->createdAt = $createdAt;return $this;}public function getAttribut(): ?Attribut{return $this->attribut;}public function setAttribut(?Attribut $attribut): self{$this->attribut = $attribut;return $this;}public function getValue(): ?string{return $this->value;}public function setValue(string $value): self{$this->value = $value;return $this;}public function getProduct(): ?Product{return $this->product;}public function setProduct(?Product $product): self{$this->product = $product;return $this;}public function getPrice(): ?float{return $this->price;}public function setPrice(?float $price): self{$this->price = $price;return $this;}public function getQuantity(): ?int{return $this->quantity;}public function setQuantity(?int $quantity): self{$this->quantity = $quantity;return $this;}/*** @return Collection|ProductVariant[]*/public function getProductVariants(): Collection{return $this->productVariants;}public function addProductVariant(ProductVariant $productVariant): self{if (!$this->productVariants->contains($productVariant)) {$this->productVariants[] = $productVariant;$productVariant->addAttributeValue($this);}return $this;}public function removeProductVariant(ProductVariant $productVariant): self{if ($this->productVariants->removeElement($productVariant)) {$productVariant->removeAttributeValue($this);}return $this;}#[Groups(['read', 'write'])]public function getAttributName(){if($this->getAttribut()){return $this->getAttribut()->getName();}return "";}public function getImage(): ?string{return $this->image;}public function setImage(?string $image): static{$this->image = $image;return $this;}public function getSkuCode(): ?string{return $this->skuCode;}public function setSkuCode(?string $skuCode): static{$this->skuCode = $skuCode;return $this;}public function getFinalPrice(){$price = 0;if($this->getProduct()){if($this->getProduct()->getPromotion()){if($this->getProduct()->getPromotion()->getType()=="percent"){$reduction = ($this->getPrice() / 100) * $this->getProduct()->getPromotion()->getValue();$finalPrice = $this->getPrice() - $reduction;}else{$finalPrice = $this->getPrice() - $this->getProduct()->getPromotion()->getValue();}return $finalPrice;}}return $this->getPrice();}public function getCostPrice(): ?float{return $this->costPrice;}public function setCostPrice(?float $costPrice): static{$this->costPrice = $costPrice;return $this;}}