123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- namespace Core\App\Factory;
- class OrderFactory extends EntityFactory
- {
- public function createOrder(
- $order_id,
- $created_date,
- $currency,
- $customer_id,
- $customer_first_name,
- $customer_last_name,
- $billing_company,
- $email,
- $billing_address_first_name,
- $billing_address_last_name,
- $billing_address_address1,
- $billing_address_address2,
- $billing_address_zip,
- $billing_address_city,
- $billing_address_province,
- $billing_address_phone,
-
- $shipping_address_first_name,
- $shipping_address_last_name,
- $shipping_address_address1,
- $shipping_address_address2,
- $shipping_address_zip,
- $shipping_address_city,
- $shipping_address_province,
- $shipping_address_phone,
- $order_status,
- $payment_method,
- $comments,
- $fiscal_code,
- $company,
- $nr_inreg
- )
- {
-
- $order = new \Core\App\Entity\Order();
- $order->setFacturiIdExtern($order_id);
- $order->setFacturiNumar($order_id);
- $order->setFacturiData(date('Y-m-d H:i:s', strtotime($created_date)));
- $order->setFacturiMoneda($currency);
- $order->setFacturiClientId($customer_id);
- $order->setFacturiNumeClient($this->getPaymentName($customer_first_name, $customer_last_name, $billing_address_first_name, $billing_address_last_name, $billing_company, $company));
- $order->setFacturiTipPersoana(!empty($fiscal_code) ? 'juridica' : 'fizica');
- $order->setFacturiCodfClient($fiscal_code);
- $order->setFacturiNrregClient($nr_inreg);
- $order->setFacturiEmailClient($email);
- $order->setFacturiSediuClient($this->getPaymentAddress($billing_address_address1, $billing_address_address2, $billing_address_zip));
- $order->setFacturiOrasClient($this->stripSpecialChars($billing_address_city));
- $order->setFacturiJudetClient($this->stripSpecialChars($billing_address_province));
- $order->setFacturiTelClient($billing_address_phone);
-
- $order->setFacturiNumeLivrare($this->getShippingName($shipping_address_first_name, $shipping_address_last_name));
- $order->setFacturiClientiAdresaLivrare($this->getShippingAddress($shipping_address_address1, $shipping_address_address2, $shipping_address_zip));
- $order->setFacturiCodpostalLivrare($shipping_address_zip);
- $order->setFacturiOrasLivrare($this->stripSpecialChars($shipping_address_city));
- $order->setFacturiJudetLivrare($this->stripSpecialChars($shipping_address_province));
- $order->setFacturiTelLivrare($this->getShippingPhone($shipping_address_phone, $billing_address_phone));
- $order->setFacturiStatus($order_status);
- $order->setFacturiModPlata($payment_method);
- $order->setFacturiObs($this->getObs($order_id, $shipping_address_first_name, $shipping_address_last_name, $shipping_address_phone, $billing_address_phone, $comments));
- return $order;
- }
- protected function getPaymentName($customer_first_name, $customer_last_name, $billing_address_first_name, $billing_address_last_name, $billing_company, $company)
- {
- $name = $customer_first_name . ' ' . $customer_last_name;
-
- $billing_name = $billing_address_first_name . ' ' . $billing_address_last_name;
- $billing_name = trim($billing_name);
- if(!empty($billing_name))
- {
- $name = $billing_name;
- }
- if(!empty($billing_company))
- {
- $name = $billing_company;
- }
- if(!empty($company))
- {
- $name = $company;
- }
- return $this->stripSpecialChars($name);
- }
-
- protected function getPaymentAddress($billing_address_address1, $billing_address_address2, $billing_address_zip)
- {
- $address = array();
- $address[] = $billing_address_address1 . ' ' . $billing_address_address2;
- $address[] = $billing_address_zip;
-
- return $this->stripSpecialChars(implode(' ', $address));
- }
- protected function getShippingAddress($shipping_address_address1, $shipping_address_address2, $shipping_address_zip)
- {
- $address = array();
- $address[] = $shipping_address_address1;
- $address[] = $shipping_address_address2;
- $address[] = $shipping_address_zip;
-
- return $this->stripSpecialChars(implode(' ', $address));
- }
- protected function getShippingName($shipping_address_first_name, $shipping_address_last_name)
- {
- $result = $this->stripSpecialChars($shipping_address_first_name . ' ' . $shipping_address_last_name);
- return $result;
- }
- protected function getShippingPhone($shipping_address_phone, $billing_address_phone)
- {
- if(!empty($shipping_address_phone))
- {
- return $shipping_address_phone;
- }
- else
- {
- return $billing_address_phone;
- }
- }
- protected function getObs($order_id, $shipping_address_first_name, $shipping_address_last_name, $shipping_address_phone, $billing_address_phone, $comments)
- {
- $output = array();
- $output[] = 'Comanda nr: ' . $order_id;
- $output[] = 'Nume si prenume la livrare: ' . $this->getShippingName($shipping_address_first_name, $shipping_address_last_name);
- $output[] = 'Telefon la livrare: ' . $this->getShippingPhone($shipping_address_phone, $billing_address_phone);
- if(empty($comments))
- {
- $comments = '-';
- }
-
- $output[] = 'Comentarii la comanda: ' . $this->stripSpecialChars($comments);
- return implode('; ', $output);
- }
-
- }
|