src/Entity/Carrier.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * Carrier
  6. *
  7. * @ORM\Table(name="carriers")
  8. * @ORM\Entity
  9. * @ORM\HasLifecycleCallbacks()
  10. */
  11. class Carrier
  12. {
  13. public const VAT_RATE = 0.2;
  14. public const TYPE_CLICKNCOLLECT = 'CLICKNCOLLECT';
  15. public const TYPE_DELIVERY = 'DELIVERY';
  16. public const TYPE_PARCELSHOP = 'PARCELSHOP';
  17. /**
  18. * @var int
  19. *
  20. * @ORM\Column(name="id", type="integer", nullable=false)
  21. * @ORM\Id
  22. * @ORM\GeneratedValue(strategy="IDENTITY")
  23. */
  24. private $id;
  25. /**
  26. * @var string
  27. *
  28. * @ORM\Column(name="name", type="string", length=50, nullable=false)
  29. */
  30. private $name = '';
  31. /**
  32. * @var string|null
  33. *
  34. * @ORM\Column(name="code", type="string", length=50, nullable=true)
  35. */
  36. private $code = '';
  37. /**
  38. * @var string|null
  39. *
  40. * @ORM\Column(name="type", type="string", length=50, nullable=true)
  41. */
  42. private $type = '';
  43. /**
  44. * @var float
  45. *
  46. * @ORM\Column(name="price", type="float", nullable=false, options={"default":"0"})
  47. */
  48. private $price = 0;
  49. /**
  50. * @var float
  51. *
  52. * @ORM\Column(name="free_from", type="float", nullable=false, options={"default":"0"})
  53. */
  54. private $freeFrom = -1;
  55. /**
  56. * @var int
  57. *
  58. * @ORM\Column(name="rank", type="integer", nullable=false, options={"default":"0"})
  59. */
  60. private $rank = 0;
  61. /**
  62. * @var integer
  63. *
  64. * @ORM\Column(name="elite", type="integer", nullable=false, options={"default":"0"})
  65. */
  66. private $elite = 0;
  67. /**
  68. * @var string
  69. *
  70. * @ORM\Column(name="template", type="string", nullable=false, options={"default":""})
  71. */
  72. private $template = 0;
  73. /**
  74. * @ORM\ManyToOne(targetEntity="App\Entity\PriceGroup")
  75. * @ORM\JoinColumn(name="price_group_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
  76. */
  77. private $priceGroup;
  78. public function getId(): int {
  79. return $this->id;
  80. }
  81. public function getName(): string {
  82. return $this->name;
  83. }
  84. public function getPrice(): float {
  85. return $this->price;
  86. }
  87. public function getFreeFrom(): float {
  88. return $this->freeFrom;
  89. }
  90. public function getCode(): ?string {
  91. return $this->code;
  92. }
  93. public function getType(): ?string {
  94. return $this->type;
  95. }
  96. public function getRank(): int {
  97. return $this->rank;
  98. }
  99. public function getElite(): int {
  100. return $this->elite;
  101. }
  102. public function getTemplate(): string {
  103. return $this->template;
  104. }
  105. public function getPriceByCart(Cart $cart) {
  106. if($this->getFreeFrom() && ($cart->getTotalProductsWithPaymentDiscount()>$this->getFreeFrom())){
  107. return 0;
  108. }
  109. $shippingRate = $cart->getShippingRateByCarrier($this);
  110. if(!empty($shippingRate)){
  111. return $shippingRate->getPrice();
  112. }
  113. return $this->getPrice();
  114. }
  115. public function getPriceGroup() {
  116. return $this->priceGroup;
  117. }
  118. public function setId(int $id): void {
  119. $this->id = $id;
  120. }
  121. public function setName(string $name): void {
  122. $this->name = $name;
  123. }
  124. public function setPrice(float $price): void {
  125. $this->price = $price;
  126. }
  127. public function setFreeFrom(float $freeFrom): void {
  128. $this->freeFrom = $freeFrom;
  129. }
  130. public function setCode(?string $code): void {
  131. $this->code = $code;
  132. }
  133. public function setType(?string $type): void {
  134. $this->type = $type;
  135. }
  136. public function setRank(int $rank): void {
  137. $this->rank = $rank;
  138. }
  139. public function setElite(int $elite): void {
  140. $this->elite = $elite;
  141. }
  142. public function setTemplate(string $template): void {
  143. $this->template = $template;
  144. }
  145. public function setPriceGroup($priceGroup): void {
  146. $this->priceGroup = $priceGroup;
  147. }
  148. public function toArray() : array{
  149. $output = [
  150. 'id' => $this->getId(),
  151. 'name' => $this->getName(),
  152. 'code' => $this->getCode(),
  153. 'price' => $this->getPrice()
  154. ];
  155. return $output;
  156. }
  157. }