You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

516 satır
16KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Lc\ShopBundle\Context\DocumentInterface;
  8. use Lc\ShopBundle\Context\FilterMerchantInterface;
  9. /**
  10. * @ORM\MappedSuperclass()
  11. */
  12. abstract class OrderShop extends AbstractEntity implements FilterMerchantInterface
  13. {
  14. /**
  15. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="productFamilies")
  16. * @ORM\JoinColumn(nullable=false)
  17. */
  18. protected $merchant;
  19. /**
  20. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="orders")
  21. */
  22. protected $user;
  23. /**
  24. * @ORM\ManyToOne(targetEntity="App\Entity\Visitor", inversedBy="orders")
  25. */
  26. protected $visitor;
  27. /**
  28. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\AddressInterface")
  29. */
  30. protected $invoiceAddress;
  31. /**
  32. * @ORM\Column(type="text", nullable=true)
  33. */
  34. protected $invoiceAddressText;
  35. /**
  36. * @ORM\Column(type="datetime", nullable=true)
  37. */
  38. protected $validationDate;
  39. /**
  40. * @ORM\Column(type="text", nullable=true)
  41. */
  42. protected $comment;
  43. /**
  44. * @ORM\Column(type="boolean", nullable=true)
  45. */
  46. protected $autoPayment;
  47. /**
  48. * @ORM\Column(type="string", length=31, nullable=true)
  49. */
  50. protected $meanPayment;
  51. /**
  52. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderStatusHistoryInterface", mappedBy="orderShop", orphanRemoval=true)
  53. */
  54. protected $orderStatusHistories;
  55. /**
  56. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderPaymentInterface", mappedBy="orderShop", orphanRemoval=true)
  57. */
  58. protected $orderPayments;
  59. /**
  60. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderProductInterface", mappedBy="orderShop", cascade={"persist", "remove"}, orphanRemoval=true)
  61. */
  62. protected $orderProducts;
  63. /**
  64. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\CreditHistoryInterface", mappedBy="orderShop", orphanRemoval=true)
  65. */
  66. protected $creditHistories;
  67. /**
  68. * @ORM\Column(type="text", nullable=true)
  69. */
  70. protected $deliveryInfos;
  71. /**
  72. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderStatusInterface")
  73. * @ORM\JoinColumn(nullable=false)
  74. */
  75. protected $orderStatus;
  76. /**
  77. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderReductionCartInterface", mappedBy="orderShop", orphanRemoval=true)
  78. */
  79. protected $orderReductionCarts;
  80. /**
  81. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderReductionCreditInterface", mappedBy="orderShop", orphanRemoval=true)
  82. */
  83. protected $orderReductionCredits;
  84. /**
  85. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\DocumentInterface", inversedBy="orderShops")
  86. */
  87. protected $documents;
  88. /**
  89. * @Gedmo\Blameable(on="create")
  90. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  91. * @ORM\JoinColumn(nullable=true)
  92. */
  93. protected $createdBy;
  94. /**
  95. * @Gedmo\Blameable(on="update")
  96. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  97. * @ORM\JoinColumn(nullable=true)
  98. */
  99. protected $updatedBy;
  100. public function __construct()
  101. {
  102. $this->orderStatusHistories = new ArrayCollection();
  103. $this->orderPayments = new ArrayCollection();
  104. $this->orderProducts = new ArrayCollection();
  105. $this->creditHistories = new ArrayCollection();
  106. $this->orderReductionCarts = new ArrayCollection();
  107. $this->orderReductionCredits = new ArrayCollection();
  108. $this->documents = new ArrayCollection();
  109. }
  110. public function getValidationDate(): ?\DateTimeInterface
  111. {
  112. return $this->validationDate;
  113. }
  114. public function setValidationDate(\DateTimeInterface $validationDate): self
  115. {
  116. $this->validationDate = $validationDate;
  117. return $this;
  118. }
  119. public function getDateCreated()
  120. {
  121. $orderStatusHistory = $this->getOrderStatusHistory('new');
  122. if ($orderStatusHistory) {
  123. return $orderStatusHistory->getCreatedAt();
  124. }
  125. return null;
  126. }
  127. public function getOrderStatusHistory($status)
  128. {
  129. $orderStatusHistories = $this->getOrderStatusHistories();
  130. if (count($orderStatusHistories) > 0) {
  131. foreach ($orderStatusHistories as $orderStatusHistory) {
  132. if ($orderStatusHistory->getOrderStatus() == $status) {
  133. return $orderStatusHistory;
  134. }
  135. }
  136. }
  137. return null;
  138. }
  139. public function getMerchant(): ?Merchant
  140. {
  141. return $this->merchant;
  142. }
  143. public function setMerchant(?Merchant $merchant): self
  144. {
  145. $this->merchant = $merchant;
  146. return $this;
  147. }
  148. public function getUser(): ?User
  149. {
  150. return $this->user;
  151. }
  152. public function setUser(?User $user): self
  153. {
  154. $this->user = $user;
  155. return $this;
  156. }
  157. public function getInvoiceAddress(): ?Address
  158. {
  159. return $this->invoiceAddress;
  160. }
  161. public function setInvoiceAddress(?Address $invoiceAddress): self
  162. {
  163. $this->invoiceAddress = $invoiceAddress;
  164. return $this;
  165. }
  166. public function getInvoiceAddressText(): ?string
  167. {
  168. return $this->invoiceAddressText;
  169. }
  170. public function setInvoiceAddressText(string $invoiceAddressText): self
  171. {
  172. $this->invoiceAddressText = $invoiceAddressText;
  173. return $this;
  174. }
  175. public function getComment(): ?string
  176. {
  177. return $this->comment;
  178. }
  179. public function setComment(?string $comment): self
  180. {
  181. $this->comment = $comment;
  182. return $this;
  183. }
  184. public function getAutoPayment(): ?bool
  185. {
  186. return $this->autoPayment;
  187. }
  188. public function setAutoPayment(bool $autoPayment): self
  189. {
  190. $this->autoPayment = $autoPayment;
  191. return $this;
  192. }
  193. public function getMeanPayment(): ?string
  194. {
  195. return $this->meanPayment;
  196. }
  197. public function setMeanPayment(string $meanPayment): self
  198. {
  199. $this->meanPayment = $meanPayment;
  200. return $this;
  201. }
  202. /**
  203. * @return Collection|OrderStatusHistory[]
  204. */
  205. public function getOrderStatusHistories(): Collection
  206. {
  207. return $this->orderStatusHistories;
  208. }
  209. public function addOrderStatusHistory(OrderStatusHistory $orderStatusHistory): self
  210. {
  211. if (!$this->orderStatusHistories->contains($orderStatusHistory)) {
  212. $this->orderStatusHistories[] = $orderStatusHistory;
  213. $orderStatusHistory->setOrderShop($this);
  214. }
  215. return $this;
  216. }
  217. public function removeOrderStatusHistory(OrderStatusHistory $orderStatusHistory): self
  218. {
  219. if ($this->orderStatusHistories->contains($orderStatusHistory)) {
  220. $this->orderStatusHistories->removeElement($orderStatusHistory);
  221. // set the owning side to null (unless already changed)
  222. if ($orderStatusHistory->getOrderShop() === $this) {
  223. $orderStatusHistory->setOrderShop(null);
  224. }
  225. }
  226. return $this;
  227. }
  228. /**
  229. * @return Collection|OrderPayment[]
  230. */
  231. public function getOrderPayments(): Collection
  232. {
  233. return $this->orderPayments;
  234. }
  235. public function addOrderPayment(OrderPayment $orderPayment): self
  236. {
  237. if (!$this->orderPayments->contains($orderPayment)) {
  238. $this->orderPayments[] = $orderPayment;
  239. $orderPayment->setOrderShop($this);
  240. }
  241. return $this;
  242. }
  243. public function removeOrderPayment(OrderPayment $orderPayment): self
  244. {
  245. if ($this->orderPayments->contains($orderPayment)) {
  246. $this->orderPayments->removeElement($orderPayment);
  247. // set the owning side to null (unless already changed)
  248. if ($orderPayment->getOrderShop() === $this) {
  249. $orderPayment->setOrderShop(null);
  250. }
  251. }
  252. return $this;
  253. }
  254. /**
  255. * @return Collection|OrderProduct[]
  256. */
  257. public function getOrderProducts(): Collection
  258. {
  259. return $this->orderProducts;
  260. }
  261. public function addOrderProduct(OrderProduct $orderProduct): self
  262. {
  263. if (!$this->orderProducts->contains($orderProduct)) {
  264. $this->orderProducts[] = $orderProduct;
  265. $orderProduct->setOrderShop($this);
  266. }
  267. return $this;
  268. }
  269. public function removeOrderProduct(OrderProduct $orderProduct): self
  270. {
  271. if ($this->orderProducts->contains($orderProduct)) {
  272. $this->orderProducts->removeElement($orderProduct);
  273. // set the owning side to null (unless already changed)
  274. if ($orderProduct->getOrderShop() === $this) {
  275. $orderProduct->setOrderShop(null);
  276. }
  277. }
  278. return $this;
  279. }
  280. /**
  281. * @return Collection|CreditHistory[]
  282. */
  283. public function getCreditHistories(): Collection
  284. {
  285. return $this->creditHistories;
  286. }
  287. public function addCreditHistory(CreditHistory $creditHistory): self
  288. {
  289. if (!$this->creditHistories->contains($creditHistory)) {
  290. $this->creditHistories[] = $creditHistory;
  291. $creditHistory->setOrderShop($this);
  292. }
  293. return $this;
  294. }
  295. public function removeCreditHistory(CreditHistory $creditHistory): self
  296. {
  297. if ($this->creditHistories->contains($creditHistory)) {
  298. $this->creditHistories->removeElement($creditHistory);
  299. // set the owning side to null (unless already changed)
  300. if ($creditHistory->getOrderShop() === $this) {
  301. $creditHistory->setOrderShop(null);
  302. }
  303. }
  304. return $this;
  305. }
  306. public function getVisitor(): ?Visitor
  307. {
  308. return $this->visitor;
  309. }
  310. public function setVisitor(?Visitor $visitor): self
  311. {
  312. $this->visitor = $visitor;
  313. return $this;
  314. }
  315. public function getDeliveryInfos(): ?string
  316. {
  317. return $this->deliveryInfos;
  318. }
  319. public function setDeliveryInfos(?string $deliveryInfos): self
  320. {
  321. $this->deliveryInfos = $deliveryInfos;
  322. return $this;
  323. }
  324. public function getOrderStatus(): ?OrderStatus
  325. {
  326. return $this->orderStatus;
  327. }
  328. public function setOrderStatusProtected(?OrderStatus $orderStatus): self
  329. {
  330. $this->orderStatus = $orderStatus;
  331. return $this;
  332. }
  333. /**
  334. * @return Collection|OrderReductionCart[]
  335. */
  336. public function getOrderReductionCarts(): Collection
  337. {
  338. return $this->orderReductionCarts;
  339. }
  340. public function addOrderReductionCart(OrderReductionCart $orderReductionCart): self
  341. {
  342. if (!$this->orderReductionCarts->contains($orderReductionCart)) {
  343. $this->orderReductionCarts[] = $orderReductionCart;
  344. $orderReductionCart->setOrderShop($this);
  345. }
  346. return $this;
  347. }
  348. public function removeOrderReductionCart(OrderReductionCart $orderReductionCart): self
  349. {
  350. if ($this->orderReductionCarts->contains($orderReductionCart)) {
  351. $this->orderReductionCarts->removeElement($orderReductionCart);
  352. // set the owning side to null (unless already changed)
  353. if ($orderReductionCart->getOrderShop() === $this) {
  354. $orderReductionCart->setOrderShop(null);
  355. }
  356. }
  357. return $this;
  358. }
  359. /**
  360. * @return Collection|OrderReductionCart[]
  361. */
  362. public function getOrderReductionCredits(): Collection
  363. {
  364. return $this->orderReductionCredits;
  365. }
  366. public function addOrderReductionCredit(OrderReductionCredit $orderReductionCredit): self
  367. {
  368. if (!$this->orderReductionCredits->contains($orderReductionCredit)) {
  369. $this->orderReductionCredits[] = $orderReductionCredit;
  370. $orderReductionCredit->setOrderShop($this);
  371. }
  372. return $this;
  373. }
  374. public function removeOrderReductionCredit(OrderReductionCredit $orderReductionCredit): self
  375. {
  376. if ($this->orderReductionCredits->contains($orderReductionCredit)) {
  377. $this->orderReductionCredits->removeElement($orderReductionCredit);
  378. // set the owning side to null (unless already changed)
  379. if ($orderReductionCredit->getOrderShop() === $this) {
  380. $orderReductionCredit->setOrderShop(null);
  381. }
  382. }
  383. return $this;
  384. }
  385. public function hasOrderReductionCartFreeShipping()
  386. {
  387. foreach($this->getOrderReductionCarts() as $orderReductionCart) {
  388. if($orderReductionCart->getFreeShipping()) {
  389. return true ;
  390. }
  391. }
  392. return false ;
  393. }
  394. /**
  395. * @return Collection|Document[]
  396. */
  397. public function getDocuments(): Collection
  398. {
  399. return $this->documents;
  400. }
  401. public function addDocument(Document $document): self
  402. {
  403. if (!$this->documents->contains($document)) {
  404. $this->documents[] = $document;
  405. }
  406. return $this;
  407. }
  408. public function removeDocument(Document $document): self
  409. {
  410. if ($this->documents->contains($document)) {
  411. $this->documents->removeElement($document);
  412. }
  413. return $this;
  414. }
  415. }