<?php
namespace MLDev\CatalogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="MLDev_Product_Item_Stock")
* @ORM\Entity()
*/
class ProductItemStock implements \JsonSerializable
{
/**
* @ORM\Id()
* @ORM\ManyToOne(targetEntity=Stock::class)
* @ORM\JoinColumn(name="stock_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $stock;
/**
* @ORM\Id()
* @ORM\ManyToOne(targetEntity=ProductItem::class, inversedBy="stocks")
* @ORM\JoinColumn(name="product_item_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $productItem;
/**
* @ORM\Column(type="integer", name="value", nullable=true)
*/
private $value = 0;
/**
* ProductItemStock constructor.
*/
public function __construct(?Stock $stock, ?ProductItem $productItem, ?int $value = 0)
{
$this->stock = $stock;
$this->productItem = $productItem;
$this->value = $value;
}
public function getStock(): ?Stock
{
return $this->stock;
}
public function setStock(?Stock $stock): void
{
$this->stock = $stock;
}
public function getProductItem(): ?ProductItem
{
return $this->productItem;
}
public function setProductItem(?ProductItem $productItem): void
{
$this->productItem = $productItem;
}
public function getValue(): ?int
{
return $this->value;
}
public function setValue(?int $value): void
{
$this->value = $value;
}
public function isBasicStock(): bool
{
return $this->getStock() ? $this->getStock()->getBasic() : false;
}
public function jsonSerialize(): array
{
return [
'stockId' => $this->getStock()->getId(),
'productItem' => $this->getProductItem()->getId(),
'value' => $this->getValue(),
];
}
}