<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Specials
*
* @ORM\Table(name="specials")
* @ORM\Entity(repositoryClass="App\Repository\SpecialPriceRepository")
* @ORM\HasLifecycleCallbacks()
*/
class SpecialPrice
{
/**
* @var int
*
* @ORM\Column(name="specials_id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/** *
* @ORM\ManyToOne(targetEntity="App\Entity\Product")
* @ORM\JoinColumn(name="products_id", referencedColumnName="products_id", onDelete="CASCADE")
*/
private $product;
/**
* @ORM\Column(name="specials_new_products_price", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
*/
private $price = 0;
/**
* @var \DateTime|null
*
* @ORM\Column(name="specials_date_added", type="datetime", nullable=true)
*/
private $dateAdded;
/**
* @var \DateTime|null
*
* @ORM\Column(name="specials_last_modified", type="datetime", nullable=true)
*/
private $lastModified;
/**
* @var \DateTime|null
*
* @ORM\Column(name="expires_date", type="datetime", nullable=true)
*/
private $expireDate;
/**
* @var \DateTime|null
*
* @ORM\Column(name="date_status_change", type="datetime", nullable=true)
*/
private $startDate;
/**
* @var int
*
* @ORM\Column(name="status", type="integer", nullable=false, options={"default"="1"})
*/
private $status;
/** *
* @ORM\ManyToOne(targetEntity="App\Entity\CustomerGroup")
* @ORM\JoinColumn(name="customers_group_id", referencedColumnName="customers_group_id", nullable=true)
*/
private $customersGroup;
public function getId(): int {
return $this->id;
}
public function getProduct() {
return $this->product;
}
public function getPrice($withEcotax = false) {
if($withEcotax){
return round($this->price, 2)+$this->product->getEcotax();
}
return $this->price;
}
public function getDateAdded(): ?\DateTime {
return $this->dateAdded;
}
public function getLastModified(): ?\DateTime {
return $this->lastModified;
}
public function getExpireDate(): ?\DateTime {
return $this->expireDate;
}
public function getStartDate(): ?\DateTime {
return $this->startDate;
}
public function getStatus(): ?int {
return $this->status;
}
public function getCustomersGroup(): ?CustomerGroup {
return $this->customersGroup;
}
public function setProduct($product) {
$this->product = $product;
}
public function setPrice($price) {
if(is_string($price) && strpos($price, ',')){
$price = floatval(str_replace(',', '.', $price));
}
$this->price = $price;
}
public function setDateAdded(?\DateTime $dateAdded) {
$this->dateAdded = $dateAdded;
}
public function setLastModified(?\DateTime $lastModified) {
$this->lastModified = $lastModified;
}
public function setExpireDate(?\DateTime $expireDate) {
$this->expireDate = $expireDate;
}
public function setStartDate(?\DateTime $startDate) {
$this->startDate = $startDate;
}
public function setStatus(int $status) {
$this->status = $status;
}
public function setCustomersGroup(?CustomerGroup $customersGroup) {
$this->customersGroup = $customersGroup;
}
public function toArray()
{
return [
'id'=>$this->getId(),
'product'=>$this->getProduct()->getName().' ('.$this->getProduct()->getModel().')',
'price'=>$this->getPrice(),
'startDate'=>empty($this->startDate)?null:$this->startDate->format('Y-m-d H:i:s'),
'expireDate'=>empty($this->expireDate)?null:$this->expireDate->format('Y-m-d H:i:s'),
'createdAt'=>empty($this->dateAdded)?null:$this->dateAdded->format('Y-m-d H:i:s')
];
}
/**
* @ORM\PostLoad
*
* @todo Remove once 0 values in the table are converted to NULL.
*/
public function postLoad(\Doctrine\ORM\Event\LifecycleEventArgs $args) {
if ($this->customersGroup && $this->customersGroup->getId() == 0) {
$this->customersGroup = null;
}
}
}