<?php
namespace MLDev\CatalogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
/**
* @ORM\Table(name="MLDev_Product_Item_Price")
* @ORM\Entity()
*/
class ProductItemPrice implements JsonSerializable
{
/**
* @ORM\Id()
* @ORM\ManyToOne(targetEntity=Price::class)
* @ORM\JoinColumn(name="price_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $price;
/**
* @ORM\Id()
* @ORM\ManyToOne(targetEntity=ProductItem::class, inversedBy="prices")
* @ORM\JoinColumn(name="product_item_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $productItem;
/**
* @ORM\Column(type="float", name="value", nullable=true)
*/
private $value;
/**
* @ORM\Column(type="float", name="old_value", nullable=true)
*/
private $oldValue;
/**
* ProductItemPrice constructor.
*/
public function __construct(?Price $price, ?ProductItem $productItem, ?float $value = null, ?float $oldValue = null)
{
$this->price = $price;
$this->productItem = $productItem;
$this->value = $value;
$this->oldValue = $oldValue;
}
public function getPrice(): ?Price
{
return $this->price;
}
public function setPrice(?Price $price): void
{
$this->price = $price;
}
public function getProductItem(): ?ProductItem
{
return $this->productItem;
}
public function setProductItem(?ProductItem $productItem): void
{
$this->productItem = $productItem;
}
public function getValue(): ?float
{
return $this->value;
}
public function setValue(?float $value): void
{
$this->value = $value;
}
public function getOldValue(): ?float
{
return $this->oldValue;
}
public function setOldValue(?float $oldValue): void
{
$this->oldValue = $oldValue;
}
public function getPriceAlias(): ?string
{
return $this->getPrice() ? $this->getPrice()->getAlias() : null;
}
public function getPriceBasic(): ?bool
{
return $this->getPrice() ? $this->getPrice()->getBasic() : null;
}
public function jsonSerialize(): array
{
return [
'priceId' => $this->getPrice()->getId(),
'productItem' => $this->getProductItem()->getId(),
'value' => $this->getValue(),
'oldValue' => $this->getOldValue(),
];
}
}