<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Carrier
*
* @ORM\Table(name="carriers")
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
*/
class Carrier
{
public const VAT_RATE = 0.2;
public const TYPE_CLICKNCOLLECT = 'CLICKNCOLLECT';
public const TYPE_DELIVERY = 'DELIVERY';
public const TYPE_PARCELSHOP = 'PARCELSHOP';
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=50, nullable=false)
*/
private $name = '';
/**
* @var string|null
*
* @ORM\Column(name="code", type="string", length=50, nullable=true)
*/
private $code = '';
/**
* @var string|null
*
* @ORM\Column(name="type", type="string", length=50, nullable=true)
*/
private $type = '';
/**
* @var float
*
* @ORM\Column(name="price", type="float", nullable=false, options={"default":"0"})
*/
private $price = 0;
/**
* @var float
*
* @ORM\Column(name="free_from", type="float", nullable=false, options={"default":"0"})
*/
private $freeFrom = -1;
/**
* @var int
*
* @ORM\Column(name="rank", type="integer", nullable=false, options={"default":"0"})
*/
private $rank = 0;
/**
* @var integer
*
* @ORM\Column(name="elite", type="integer", nullable=false, options={"default":"0"})
*/
private $elite = 0;
/**
* @var string
*
* @ORM\Column(name="template", type="string", nullable=false, options={"default":""})
*/
private $template = 0;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\PriceGroup")
* @ORM\JoinColumn(name="price_group_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
*/
private $priceGroup;
public function getId(): int {
return $this->id;
}
public function getName(): string {
return $this->name;
}
public function getPrice(): float {
return $this->price;
}
public function getFreeFrom(): float {
return $this->freeFrom;
}
public function getCode(): ?string {
return $this->code;
}
public function getType(): ?string {
return $this->type;
}
public function getRank(): int {
return $this->rank;
}
public function getElite(): int {
return $this->elite;
}
public function getTemplate(): string {
return $this->template;
}
public function getPriceByCart(Cart $cart) {
if($this->getFreeFrom() && ($cart->getTotalProductsWithPaymentDiscount()>$this->getFreeFrom())){
return 0;
}
$shippingRate = $cart->getShippingRateByCarrier($this);
if(!empty($shippingRate)){
return $shippingRate->getPrice();
}
return $this->getPrice();
}
public function getPriceGroup() {
return $this->priceGroup;
}
public function setId(int $id): void {
$this->id = $id;
}
public function setName(string $name): void {
$this->name = $name;
}
public function setPrice(float $price): void {
$this->price = $price;
}
public function setFreeFrom(float $freeFrom): void {
$this->freeFrom = $freeFrom;
}
public function setCode(?string $code): void {
$this->code = $code;
}
public function setType(?string $type): void {
$this->type = $type;
}
public function setRank(int $rank): void {
$this->rank = $rank;
}
public function setElite(int $elite): void {
$this->elite = $elite;
}
public function setTemplate(string $template): void {
$this->template = $template;
}
public function setPriceGroup($priceGroup): void {
$this->priceGroup = $priceGroup;
}
public function toArray() : array{
$output = [
'id' => $this->getId(),
'name' => $this->getName(),
'code' => $this->getCode(),
'price' => $this->getPrice()
];
return $output;
}
}