From 41d75b8196dfd9186ecb06c15f48d69b43b3783a Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Fri, 29 Jan 2016 18:02:44 +0300 Subject: [PATCH] eol --- admin/model/retailcrm/references.php | 276 +++++++++++++-------------- catalog/model/retailcrm/order.php | 194 +++++++++---------- 2 files changed, 235 insertions(+), 235 deletions(-) diff --git a/admin/model/retailcrm/references.php b/admin/model/retailcrm/references.php index 80f2854..d031250 100644 --- a/admin/model/retailcrm/references.php +++ b/admin/model/retailcrm/references.php @@ -1,138 +1,138 @@ - $this->getOpercartDeliveryTypes(), - 'retailcrm' => $this->getApiDeliveryTypes() - ); - } - - public function getOrderStatuses() - { - return array( - 'opencart' => $this->getOpercartOrderStatuses(), - 'retailcrm' => $this->getApiOrderStatuses() - ); - } - - public function getPaymentTypes() - { - return array( - 'opencart' => $this->getOpercartPaymentTypes(), - 'retailcrm' => $this->getApiPaymentTypes() - ); - } - - protected function getOpercartDeliveryTypes() - { - $deliveryMethods = array(); - $files = glob(DIR_APPLICATION . 'controller/shipping/*.php'); - - if ($files) { - foreach ($files as $file) { - $extension = basename($file, '.php'); - - $this->load->language('shipping/' . $extension); - - if ($this->config->get($extension . '_status')) { - $deliveryMethods[$extension.'.'.$extension] = strip_tags( - $this->language->get('heading_title') - ); - } - } - } - - return $deliveryMethods; - } - - protected function getOpercartOrderStatuses() - { - $this->load->model('localisation/order_status'); - - return $this->model_localisation_order_status - ->getOrderStatuses(array()); - } - - protected function getOpercartPaymentTypes() - { - $paymentTypes = array(); - $files = glob(DIR_APPLICATION . 'controller/payment/*.php'); - - if ($files) { - foreach ($files as $file) { - $extension = basename($file, '.php'); - - $this->load->language('payment/' . $extension); - - if ($this->config->get($extension . '_status')) { - $paymentTypes[$extension] = strip_tags( - $this->language->get('heading_title') - ); - } - } - } - - return $paymentTypes; - } - - protected function getApiDeliveryTypes() - { - $this->load->model('setting/setting'); - $settings = $this->model_setting_setting->getSetting('retailcrm'); - - if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) { - $this->retailcrm = new RetailcrmProxy( - $settings['retailcrm_url'], - $settings['retailcrm_apikey'], - DIR_SYSTEM . 'logs/retailcrm.log' - ); - - $response = $this->retailcrm->deliveryTypesList(); - - return ($response === false) ? array() : $response->deliveryTypes; - } - } - - protected function getApiOrderStatuses() - { - $this->load->model('setting/setting'); - $settings = $this->model_setting_setting->getSetting('retailcrm'); - - if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) { - $this->retailcrm = new RetailcrmProxy( - $settings['retailcrm_url'], - $settings['retailcrm_apikey'], - DIR_SYSTEM . 'logs/retailcrm.log' - ); - - $response = $this->retailcrm->statusesList(); - - return ($response === false) ? array() : $response->statuses; - } - } - - protected function getApiPaymentTypes() - { - $this->load->model('setting/setting'); - $settings = $this->model_setting_setting->getSetting('retailcrm'); - - if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) { - $this->retailcrm = new RetailcrmProxy( - $settings['retailcrm_url'], - $settings['retailcrm_apikey'], - DIR_SYSTEM . 'logs/retailcrm.log' - ); - - $response = $this->retailcrm->paymentTypesList(); - - return ($response === false) ? array() : $response->paymentTypes; - } - } -} + $this->getOpercartDeliveryTypes(), + 'retailcrm' => $this->getApiDeliveryTypes() + ); + } + + public function getOrderStatuses() + { + return array( + 'opencart' => $this->getOpercartOrderStatuses(), + 'retailcrm' => $this->getApiOrderStatuses() + ); + } + + public function getPaymentTypes() + { + return array( + 'opencart' => $this->getOpercartPaymentTypes(), + 'retailcrm' => $this->getApiPaymentTypes() + ); + } + + protected function getOpercartDeliveryTypes() + { + $deliveryMethods = array(); + $files = glob(DIR_APPLICATION . 'controller/shipping/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('shipping/' . $extension); + + if ($this->config->get($extension . '_status')) { + $deliveryMethods[$extension.'.'.$extension] = strip_tags( + $this->language->get('heading_title') + ); + } + } + } + + return $deliveryMethods; + } + + protected function getOpercartOrderStatuses() + { + $this->load->model('localisation/order_status'); + + return $this->model_localisation_order_status + ->getOrderStatuses(array()); + } + + protected function getOpercartPaymentTypes() + { + $paymentTypes = array(); + $files = glob(DIR_APPLICATION . 'controller/payment/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('payment/' . $extension); + + if ($this->config->get($extension . '_status')) { + $paymentTypes[$extension] = strip_tags( + $this->language->get('heading_title') + ); + } + } + } + + return $paymentTypes; + } + + protected function getApiDeliveryTypes() + { + $this->load->model('setting/setting'); + $settings = $this->model_setting_setting->getSetting('retailcrm'); + + if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) { + $this->retailcrm = new RetailcrmProxy( + $settings['retailcrm_url'], + $settings['retailcrm_apikey'], + DIR_SYSTEM . 'logs/retailcrm.log' + ); + + $response = $this->retailcrm->deliveryTypesList(); + + return ($response === false) ? array() : $response->deliveryTypes; + } + } + + protected function getApiOrderStatuses() + { + $this->load->model('setting/setting'); + $settings = $this->model_setting_setting->getSetting('retailcrm'); + + if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) { + $this->retailcrm = new RetailcrmProxy( + $settings['retailcrm_url'], + $settings['retailcrm_apikey'], + DIR_SYSTEM . 'logs/retailcrm.log' + ); + + $response = $this->retailcrm->statusesList(); + + return ($response === false) ? array() : $response->statuses; + } + } + + protected function getApiPaymentTypes() + { + $this->load->model('setting/setting'); + $settings = $this->model_setting_setting->getSetting('retailcrm'); + + if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) { + $this->retailcrm = new RetailcrmProxy( + $settings['retailcrm_url'], + $settings['retailcrm_apikey'], + DIR_SYSTEM . 'logs/retailcrm.log' + ); + + $response = $this->retailcrm->paymentTypesList(); + + return ($response === false) ? array() : $response->paymentTypes; + } + } +} diff --git a/catalog/model/retailcrm/order.php b/catalog/model/retailcrm/order.php index 62fa7c2..e021e30 100644 --- a/catalog/model/retailcrm/order.php +++ b/catalog/model/retailcrm/order.php @@ -1,97 +1,97 @@ -load->model('setting/setting'); - $settings = $this->model_setting_setting->getSetting('retailcrm'); - - if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) { - require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php'; - - $this->retailcrm = new RetailcrmProxy( - $settings['retailcrm_url'], - $settings['retailcrm_apikey'], - DIR_SYSTEM . 'logs/retailcrm.log' - ); - - $order = array(); - - $payment_code = $order_data['payment_code']; - $delivery_code = $order_data['shipping_code']; - - $customers = $this->retailcrm->customersList( - array( - 'name' => $order_data['telephone'], - 'email' => $order_data['email'] - ), - 1, - 100 - ); - - foreach($customers['customers'] as $customer) { - $order['customer']['id'] = $customer['id']; - } - - unset($customers); - - $order['externalId'] = $order_id; - $order['firstName'] = $order_data['firstname']; - $order['lastName'] = $order_data['lastname']; - $order['email'] = $order_data['email']; - $order['phone'] = $order_data['telephone']; - $order['customerComment'] = $order_data['comment']; - - $deliveryCost = 0; - $orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $order_data['order_total'] ; - - foreach ($orderTotals as $totals) { - if ($totals['code'] == 'shipping') { - $deliveryCost = $totals['value']; - } - } - - $order['createdAt'] = date('Y-m-d H:i:s'); - $order['paymentType'] = $settings['retailcrm_payment'][$payment_code]; - - $country = (isset($order_data['shipping_country'])) ? $order_data['shipping_country'] : '' ; - - $order['delivery'] = array( - 'code' => $settings['retailcrm_delivery'][$delivery_code], - 'cost' => $deliveryCost, - 'address' => array( - 'index' => $order_data['shipping_postcode'], - 'city' => $order_data['shipping_city'], - 'country' => $order_data['shipping_country_id'], - 'region' => $order_data['shipping_zone_id'], - 'text' => implode(', ', array( - $order_data['shipping_postcode'], - $country, - $order_data['shipping_city'], - $order_data['shipping_address_1'], - $order_data['shipping_address_2'] - )) - ) - ); - - $orderProducts = isset($order_data['products']) ? $order_data['products'] : $order_data['order_product']; - - foreach ($orderProducts as $product) { - $order['items'][] = array( - 'productId' => $product['product_id'], - 'productName' => $product['name'], - 'initialPrice' => $product['price'], - 'quantity' => $product['quantity'], - ); - } - - if (isset($order_data['order_status_id'])) { - $order['status'] = $settings['retailcrm_status'][$order_data['order_status_id']]; - } - - $this->retailcrm->ordersCreate($order); - } - } -} - +load->model('setting/setting'); + $settings = $this->model_setting_setting->getSetting('retailcrm'); + + if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) { + require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php'; + + $this->retailcrm = new RetailcrmProxy( + $settings['retailcrm_url'], + $settings['retailcrm_apikey'], + DIR_SYSTEM . 'logs/retailcrm.log' + ); + + $order = array(); + + $payment_code = $order_data['payment_code']; + $delivery_code = $order_data['shipping_code']; + + $customers = $this->retailcrm->customersList( + array( + 'name' => $order_data['telephone'], + 'email' => $order_data['email'] + ), + 1, + 100 + ); + + foreach($customers['customers'] as $customer) { + $order['customer']['id'] = $customer['id']; + } + + unset($customers); + + $order['externalId'] = $order_id; + $order['firstName'] = $order_data['firstname']; + $order['lastName'] = $order_data['lastname']; + $order['email'] = $order_data['email']; + $order['phone'] = $order_data['telephone']; + $order['customerComment'] = $order_data['comment']; + + $deliveryCost = 0; + $orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $order_data['order_total'] ; + + foreach ($orderTotals as $totals) { + if ($totals['code'] == 'shipping') { + $deliveryCost = $totals['value']; + } + } + + $order['createdAt'] = date('Y-m-d H:i:s'); + $order['paymentType'] = $settings['retailcrm_payment'][$payment_code]; + + $country = (isset($order_data['shipping_country'])) ? $order_data['shipping_country'] : '' ; + + $order['delivery'] = array( + 'code' => $settings['retailcrm_delivery'][$delivery_code], + 'cost' => $deliveryCost, + 'address' => array( + 'index' => $order_data['shipping_postcode'], + 'city' => $order_data['shipping_city'], + 'country' => $order_data['shipping_country_id'], + 'region' => $order_data['shipping_zone_id'], + 'text' => implode(', ', array( + $order_data['shipping_postcode'], + $country, + $order_data['shipping_city'], + $order_data['shipping_address_1'], + $order_data['shipping_address_2'] + )) + ) + ); + + $orderProducts = isset($order_data['products']) ? $order_data['products'] : $order_data['order_product']; + + foreach ($orderProducts as $product) { + $order['items'][] = array( + 'productId' => $product['product_id'], + 'productName' => $product['name'], + 'initialPrice' => $product['price'], + 'quantity' => $product['quantity'], + ); + } + + if (isset($order_data['order_status_id'])) { + $order['status'] = $settings['retailcrm_status'][$order_data['order_status_id']]; + } + + $this->retailcrm->ordersCreate($order); + } + } +} +