lib/composer/OrderBundle/src/VisualMedia/OrderBundle/Model/BaseOrderItemModel.php line 127

Open in your IDE?
  1. <?php
  2. /**
  3. * Base Order Item Model
  4. *
  5. * @author Bertin van den Ham <b.vandenham@visualmedia.nl>
  6. * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
  7. */
  8. namespace VisualMedia\OrderBundle\Model;
  9. use VisualMedia\LisaBundle\Component\Interfaces\EntityInterface;
  10. use VisualMedia\OrderBundle\Entity\BaseOrderItem;
  11. use VisualMedia\ProductBundle\Entity\BaseProduct;
  12. /**
  13. * Base Order Item Model
  14. */
  15. abstract class BaseOrderItemModel
  16. {
  17. /**
  18. * Entity
  19. * @var EntityInterface
  20. */
  21. protected $entity;
  22. /**
  23. * Get Item Hash
  24. *
  25. * @return string
  26. */
  27. public function getItemHash(): string
  28. {
  29. return md5(implode('-', array(
  30. $this->getEntity()->getId(),
  31. )));
  32. }
  33. /**
  34. * Get Total
  35. *
  36. * @return float
  37. */
  38. public function getTotal(): float
  39. {
  40. return $this->getAmount() * $this->getPrice();
  41. }
  42. /**
  43. * Get Entity
  44. *
  45. * @return EntityInterface
  46. */
  47. public function getEntity(): ?EntityInterface
  48. {
  49. return $this->entity;
  50. }
  51. /**
  52. * Set Entity
  53. *
  54. * @param EntityInterface $entity
  55. *
  56. * @return void
  57. */
  58. public function setEntity(?EntityInterface $entity): void
  59. {
  60. $this->entity = $entity;
  61. }
  62. /**
  63. * Get Order
  64. *
  65. * @return BaseOrderModel
  66. */
  67. public function getOrder(): ?BaseOrderModel
  68. {
  69. return $this->order;
  70. }
  71. /**
  72. * Set Order
  73. *
  74. * @param BaseOrderModel $order
  75. *
  76. * @return void
  77. */
  78. public function setOrder(?BaseOrderModel $order): void
  79. {
  80. $this->order = $order;
  81. }
  82. /**
  83. * Get Reference
  84. *
  85. * @return string|null
  86. */
  87. public function getReference(): ?string
  88. {
  89. return $this->reference;
  90. }
  91. /**
  92. * Set Reference
  93. *
  94. * @param string|null $reference
  95. */
  96. public function setReference(?string $reference): void
  97. {
  98. $this->reference = $reference;
  99. }
  100. /**
  101. * Get Product
  102. *
  103. * @return BaseProduct|null
  104. */
  105. public function getProduct(): ?BaseProduct
  106. {
  107. return $this->product;
  108. }
  109. /**
  110. * Set Product
  111. *
  112. * @param BaseProduct|null $product
  113. */
  114. public function setProduct(BaseProduct $product = null): void
  115. {
  116. $this->product = $product;
  117. }
  118. /**
  119. * Get Reference Data
  120. *
  121. * @return array|null
  122. */
  123. public function getReferenceData(): ?array
  124. {
  125. if(null !== $data = $this->referenceData) {
  126. return json_decode($data, true);
  127. }
  128. return $data;
  129. }
  130. /**
  131. * Set Reference Data
  132. *
  133. * @param array $referenceData
  134. */
  135. public function setReferenceData(?array $referenceData): void
  136. {
  137. if($referenceData !== null) {
  138. $referenceData = json_encode($referenceData);
  139. }
  140. $this->referenceData = $referenceData;
  141. }
  142. /**
  143. * Get Amount
  144. *
  145. * @return int|null
  146. */
  147. public function getAmount(): ?int
  148. {
  149. return $this->amount;
  150. }
  151. /**
  152. * Set Amount
  153. *
  154. * @param int $amount
  155. */
  156. public function setAmount(int $amount): void
  157. {
  158. $this->amount = $amount;
  159. }
  160. /**
  161. * Get Price
  162. *
  163. * @return float
  164. */
  165. public function getPrice(): ?float
  166. {
  167. return $this->price;
  168. }
  169. /**
  170. * Set Price
  171. *
  172. * @param float $price
  173. */
  174. public function setPrice(?float $price): void
  175. {
  176. $this->price = $price;
  177. }
  178. /**
  179. * Get Vat
  180. *
  181. * @return float
  182. */
  183. public function getVat(): ?float
  184. {
  185. return $this->vat;
  186. }
  187. /**
  188. * Set Vat
  189. *
  190. * @param float $vat
  191. */
  192. public function setVat(?float $vat): void
  193. {
  194. $this->vat = $vat;
  195. }
  196. /**
  197. * IsFree
  198. *
  199. * @return bool
  200. */
  201. public function isFree(): bool
  202. {
  203. return $this->free;
  204. }
  205. /**
  206. * SetFree
  207. *
  208. * @param bool $free
  209. */
  210. public function setFree(bool $free): void
  211. {
  212. $this->free = $free;
  213. }
  214. /**
  215. * GetFree
  216. *
  217. * @return bool
  218. */
  219. public function getFree(): bool
  220. {
  221. return $this->isFree();
  222. }
  223. }