OrderFactory.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace Core\App\Factory;
  3. class OrderFactory extends EntityFactory
  4. {
  5. public function createOrder(
  6. $order_id,
  7. $created_date,
  8. $currency,
  9. $customer_id,
  10. $customer_first_name,
  11. $customer_last_name,
  12. $billing_company,
  13. $email,
  14. $billing_address_first_name,
  15. $billing_address_last_name,
  16. $billing_address_address1,
  17. $billing_address_address2,
  18. $billing_address_zip,
  19. $billing_address_city,
  20. $billing_address_province,
  21. $billing_address_phone,
  22. $shipping_address_first_name,
  23. $shipping_address_last_name,
  24. $shipping_address_address1,
  25. $shipping_address_address2,
  26. $shipping_address_zip,
  27. $shipping_address_city,
  28. $shipping_address_province,
  29. $shipping_address_phone,
  30. $order_status,
  31. $payment_method,
  32. $comments,
  33. $fiscal_code,
  34. $company,
  35. $nr_inreg
  36. )
  37. {
  38. $order = new \Core\App\Entity\Order();
  39. $order->setFacturiIdExtern($order_id);
  40. $order->setFacturiNumar($order_id);
  41. $order->setFacturiData(date('Y-m-d H:i:s', strtotime($created_date)));
  42. $order->setFacturiMoneda($currency);
  43. $order->setFacturiClientId($customer_id);
  44. $order->setFacturiNumeClient($this->getPaymentName($customer_first_name, $customer_last_name, $billing_address_first_name, $billing_address_last_name, $billing_company, $company));
  45. $order->setFacturiTipPersoana(!empty($fiscal_code) ? 'juridica' : 'fizica');
  46. $order->setFacturiCodfClient($fiscal_code);
  47. $order->setFacturiNrregClient($nr_inreg);
  48. $order->setFacturiEmailClient($email);
  49. $order->setFacturiSediuClient($this->getPaymentAddress($billing_address_address1, $billing_address_address2, $billing_address_zip));
  50. $order->setFacturiOrasClient($this->stripSpecialChars($billing_address_city));
  51. $order->setFacturiJudetClient($this->stripSpecialChars($billing_address_province));
  52. $order->setFacturiTelClient($billing_address_phone);
  53. $order->setFacturiNumeLivrare($this->getShippingName($shipping_address_first_name, $shipping_address_last_name));
  54. $order->setFacturiClientiAdresaLivrare($this->getShippingAddress($shipping_address_address1, $shipping_address_address2, $shipping_address_zip));
  55. $order->setFacturiCodpostalLivrare($shipping_address_zip);
  56. $order->setFacturiOrasLivrare($this->stripSpecialChars($shipping_address_city));
  57. $order->setFacturiJudetLivrare($this->stripSpecialChars($shipping_address_province));
  58. $order->setFacturiTelLivrare($this->getShippingPhone($shipping_address_phone, $billing_address_phone));
  59. $order->setFacturiStatus($order_status);
  60. $order->setFacturiModPlata($payment_method);
  61. $order->setFacturiObs($this->getObs($order_id, $shipping_address_first_name, $shipping_address_last_name, $shipping_address_phone, $billing_address_phone, $comments));
  62. return $order;
  63. }
  64. protected function getPaymentName($customer_first_name, $customer_last_name, $billing_address_first_name, $billing_address_last_name, $billing_company, $company)
  65. {
  66. $name = $customer_first_name . ' ' . $customer_last_name;
  67. $billing_name = $billing_address_first_name . ' ' . $billing_address_last_name;
  68. $billing_name = trim($billing_name);
  69. if(!empty($billing_name))
  70. {
  71. $name = $billing_name;
  72. }
  73. if(!empty($billing_company))
  74. {
  75. $name = $billing_company;
  76. }
  77. if(!empty($company))
  78. {
  79. $name = $company;
  80. }
  81. return $this->stripSpecialChars($name);
  82. }
  83. protected function getPaymentAddress($billing_address_address1, $billing_address_address2, $billing_address_zip)
  84. {
  85. $address = array();
  86. $address[] = $billing_address_address1 . ' ' . $billing_address_address2;
  87. $address[] = $billing_address_zip;
  88. return $this->stripSpecialChars(implode(' ', $address));
  89. }
  90. protected function getShippingAddress($shipping_address_address1, $shipping_address_address2, $shipping_address_zip)
  91. {
  92. $address = array();
  93. $address[] = $shipping_address_address1;
  94. $address[] = $shipping_address_address2;
  95. $address[] = $shipping_address_zip;
  96. return $this->stripSpecialChars(implode(' ', $address));
  97. }
  98. protected function getShippingName($shipping_address_first_name, $shipping_address_last_name)
  99. {
  100. $result = $this->stripSpecialChars($shipping_address_first_name . ' ' . $shipping_address_last_name);
  101. return $result;
  102. }
  103. protected function getShippingPhone($shipping_address_phone, $billing_address_phone)
  104. {
  105. if(!empty($shipping_address_phone))
  106. {
  107. return $shipping_address_phone;
  108. }
  109. else
  110. {
  111. return $billing_address_phone;
  112. }
  113. }
  114. protected function getObs($order_id, $shipping_address_first_name, $shipping_address_last_name, $shipping_address_phone, $billing_address_phone, $comments)
  115. {
  116. $output = array();
  117. $output[] = 'Comanda nr: ' . $order_id;
  118. $output[] = 'Nume si prenume la livrare: ' . $this->getShippingName($shipping_address_first_name, $shipping_address_last_name);
  119. $output[] = 'Telefon la livrare: ' . $this->getShippingPhone($shipping_address_phone, $billing_address_phone);
  120. if(empty($comments))
  121. {
  122. $comments = '-';
  123. }
  124. $output[] = 'Comentarii la comanda: ' . $this->stripSpecialChars($comments);
  125. return implode('; ', $output);
  126. }
  127. }