src/Entity/Cart.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CartRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=CartRepository::class)
  9. * @ORM\EntityListeners({
  10. * "App\Listener\EntityListener"
  11. * })
  12. */
  13. class Cart
  14. {
  15. /**
  16. * @ORM\Id()
  17. * @ORM\GeneratedValue()
  18. * @ORM\Column(type="integer")
  19. */
  20. private $id;
  21. /**
  22. * @ORM\Column(type="string", length=190, nullable=true)
  23. */
  24. private $sid;
  25. /**
  26. * @ORM\Column(type="string", length=3, nullable=true)
  27. */
  28. private $countryDelivery;
  29. /**
  30. * @ORM\ManyToOne(targetEntity=Client::class, inversedBy="carts")
  31. */
  32. private $client;
  33. /**
  34. * @ORM\Column(type="datetime")
  35. */
  36. private $createts;
  37. /**
  38. * @ORM\OneToMany(targetEntity=CartItem::class, mappedBy="cart", orphanRemoval=true, cascade={"persist","remove"})
  39. */
  40. private $cartItems;
  41. /**
  42. * @ORM\Column(type="string", length=100, nullable=true)
  43. */
  44. protected $firstName;
  45. /**
  46. * @ORM\Column(type="string", length=100, nullable=true)
  47. */
  48. protected $lastName;
  49. /**
  50. * @ORM\Column(type="string", length=100, nullable=true)
  51. */
  52. protected $phone;
  53. /**
  54. * @ORM\Column(type="string", length=100, nullable=true)
  55. */
  56. protected $email;
  57. /**
  58. * @ORM\Column(type="text", nullable=true)
  59. */
  60. protected $note;
  61. /**
  62. * @ORM\ManyToOne(targetEntity=Transport::class)
  63. * @ORM\JoinColumn(nullable=true)
  64. */
  65. private $transport;
  66. /**
  67. * @ORM\Column(type="float", nullable=true)
  68. */
  69. protected $transportPrice;
  70. /**
  71. * @ORM\ManyToOne(targetEntity=Payment::class)
  72. * @ORM\JoinColumn(nullable=true)
  73. */
  74. private $payment;
  75. /**
  76. * @ORM\Column(type="float", nullable=true)
  77. */
  78. protected $paymentPrice;
  79. /**
  80. * @ORM\ManyToOne(targetEntity=CartAddress::class, cascade={"persist"})
  81. */
  82. private $billingAddress;
  83. /**
  84. * @ORM\ManyToOne(targetEntity=CartAddress::class, cascade={"persist"})
  85. */
  86. private $deliveryAddress;
  87. /**
  88. * @ORM\ManyToOne(targetEntity=Dealer::class)
  89. */
  90. private $dealer;
  91. /**
  92. * @ORM\Column(type="boolean")
  93. */
  94. protected $hasDeliveryAddress = false;
  95. public function __construct()
  96. {
  97. $this->cartItems = new ArrayCollection();
  98. }
  99. public function getSumPrice($currency)
  100. {
  101. $suma = 0;
  102. foreach ($this->getCartItems() as $cartItem) {
  103. $suma += $cartItem->getProduct()->getPricelists()[$currency]->getPrice()*$cartItem->getCount();
  104. }
  105. //$suma+= $this->getPaymentPrice() + $this->getTransportPrice();
  106. return $suma;
  107. }
  108. public function getId(): ?int
  109. {
  110. return $this->id;
  111. }
  112. public function getSid(): ?string
  113. {
  114. return $this->sid;
  115. }
  116. public function setSid(?string $sid): self
  117. {
  118. $this->sid = $sid;
  119. return $this;
  120. }
  121. public function getClient(): ?Client
  122. {
  123. return $this->client;
  124. }
  125. public function setClient(?Client $client): self
  126. {
  127. $this->client = $client;
  128. return $this;
  129. }
  130. public function getCreatets(): ?\DateTimeInterface
  131. {
  132. return $this->createts;
  133. }
  134. public function setCreatets(\DateTimeInterface $createts): self
  135. {
  136. $this->createts = $createts;
  137. return $this;
  138. }
  139. /**
  140. * @return Collection|CartItem[]
  141. */
  142. public function getCartItems(): Collection
  143. {
  144. return $this->cartItems;
  145. }
  146. public function addCartItem(CartItem $cartItem): self
  147. {
  148. if (!$this->cartItems->contains($cartItem)) {
  149. $this->cartItems[] = $cartItem;
  150. $cartItem->setCart($this);
  151. }
  152. return $this;
  153. }
  154. public function removeCartItem(CartItem $cartItem): self
  155. {
  156. if ($this->cartItems->contains($cartItem)) {
  157. $this->cartItems->removeElement($cartItem);
  158. // set the owning side to null (unless already changed)
  159. if ($cartItem->getCart() === $this) {
  160. $cartItem->setCart(null);
  161. }
  162. }
  163. return $this;
  164. }
  165. /**
  166. * Get FirstName
  167. *
  168. * @return mixed
  169. */
  170. public function getFirstName()
  171. {
  172. return $this->firstName;
  173. }
  174. /**
  175. * Set FirstName
  176. *
  177. * @param mixed $firstName
  178. */
  179. public function setFirstName( $firstName )
  180. {
  181. $this->firstName = $firstName;
  182. }
  183. /**
  184. * Get LastName
  185. *
  186. * @return mixed
  187. */
  188. public function getLastName()
  189. {
  190. return $this->lastName;
  191. }
  192. /**
  193. * Set LastName
  194. *
  195. * @param mixed $lastName
  196. */
  197. public function setLastName( $lastName )
  198. {
  199. $this->lastName = $lastName;
  200. }
  201. /**
  202. * Get Phone
  203. *
  204. * @return mixed
  205. */
  206. public function getPhone()
  207. {
  208. return $this->phone;
  209. }
  210. /**
  211. * Set Phone
  212. *
  213. * @param mixed $phone
  214. */
  215. public function setPhone( $phone )
  216. {
  217. $this->phone = $phone;
  218. }
  219. /**
  220. * Get Email
  221. *
  222. * @return mixed
  223. */
  224. public function getEmail()
  225. {
  226. return $this->email;
  227. }
  228. /**
  229. * Set Email
  230. *
  231. * @param mixed $email
  232. */
  233. public function setEmail( $email )
  234. {
  235. $this->email = $email;
  236. }
  237. /**
  238. * Get Note
  239. *
  240. * @return mixed
  241. */
  242. public function getNote()
  243. {
  244. return $this->note;
  245. }
  246. /**
  247. * Set Note
  248. *
  249. * @param mixed $note
  250. */
  251. public function setNote( $note )
  252. {
  253. $this->note = $note;
  254. }
  255. /**
  256. * Get Transport
  257. *
  258. * @return mixed
  259. */
  260. public function getTransport()
  261. {
  262. return $this->transport;
  263. }
  264. /**
  265. * Set Transport
  266. *
  267. * @param mixed $transport
  268. */
  269. public function setTransport( $transport )
  270. {
  271. $this->transport = $transport;
  272. }
  273. /**
  274. * Get Payment
  275. *
  276. * @return mixed
  277. */
  278. public function getPayment()
  279. {
  280. return $this->payment;
  281. }
  282. /**
  283. * Set Payment
  284. *
  285. * @param mixed $payment
  286. */
  287. public function setPayment( $payment )
  288. {
  289. $this->payment = $payment;
  290. }
  291. /**
  292. * Get BillingAddress
  293. *
  294. * @return mixed
  295. */
  296. public function getBillingAddress()
  297. {
  298. return $this->billingAddress;
  299. }
  300. /**
  301. * Set BillingAddress
  302. *
  303. * @param mixed $billingAddress
  304. */
  305. public function setBillingAddress( $billingAddress )
  306. {
  307. $this->billingAddress = $billingAddress;
  308. }
  309. /**
  310. * Get DeliveryAddress
  311. *
  312. * @return mixed
  313. */
  314. public function getDeliveryAddress()
  315. {
  316. return $this->deliveryAddress;
  317. }
  318. /**
  319. * Set DeliveryAddress
  320. *
  321. * @param mixed $deliveryAddress
  322. */
  323. public function setDeliveryAddress( $deliveryAddress )
  324. {
  325. $this->deliveryAddress = $deliveryAddress;
  326. }
  327. /**
  328. * Get HasDeliveryAddress
  329. *
  330. * @return mixed
  331. */
  332. public function getHasDeliveryAddress()
  333. {
  334. return $this->hasDeliveryAddress;
  335. }
  336. /**
  337. * Set HasDeliveryAddress
  338. *
  339. * @param mixed $hasDeliveryAddress
  340. */
  341. public function setHasDeliveryAddress( $hasDeliveryAddress )
  342. {
  343. $this->hasDeliveryAddress = $hasDeliveryAddress;
  344. }
  345. /**
  346. * Get TransportPrice
  347. *
  348. * @return mixed
  349. */
  350. public function getTransportPrice()
  351. {
  352. return $this->transportPrice;
  353. }
  354. /**
  355. * Set TransportPrice
  356. *
  357. * @param mixed $transportPrice
  358. */
  359. public function setTransportPrice( $transportPrice )
  360. {
  361. $this->transportPrice = $transportPrice;
  362. }
  363. /**
  364. * Get PaymentPrice
  365. *
  366. * @return mixed
  367. */
  368. public function getPaymentPrice()
  369. {
  370. return $this->paymentPrice;
  371. }
  372. /**
  373. * Set PaymentPrice
  374. *
  375. * @param mixed $paymentPrice
  376. */
  377. public function setPaymentPrice( $paymentPrice )
  378. {
  379. $this->paymentPrice = $paymentPrice;
  380. }
  381. /**
  382. * Get Dealer
  383. *
  384. * @return mixed
  385. */
  386. public function getDealer(): ?Dealer
  387. {
  388. return $this->dealer;
  389. }
  390. /**
  391. * Set Dealer
  392. *
  393. * @param mixed $dealer
  394. */
  395. public function setDealer( $dealer )
  396. {
  397. $this->dealer = $dealer;
  398. }
  399. /**
  400. * Get CountryDelivery
  401. *
  402. * @return mixed
  403. */
  404. public function getCountryDelivery()
  405. {
  406. return $this->countryDelivery;
  407. }
  408. /**
  409. * Set CountryDelivery
  410. *
  411. * @param mixed $countryDelivery
  412. */
  413. public function setCountryDelivery( $countryDelivery )
  414. {
  415. $this->countryDelivery = $countryDelivery;
  416. }
  417. }