From 6875bc5f611031b3b81757b7d823a6f8f5e2cd15 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Thu, 21 Sep 2017 10:09:26 +0300 Subject: [PATCH] Custom fields for v5, default payment and shipping methods for history upload --- .../controller/extension/module/retailcrm.php | 16 ++- .../en-gb/extension/module/retailcrm.php | 18 ++- .../ru-ru/extension/module/retailcrm.php | 10 +- admin/model/extension/retailcrm/customer.php | 10 +- .../model/extension/retailcrm/history/v3.php | 32 ++--- .../extension/retailcrm/history/v4_5.php | 66 +++++++--- admin/model/extension/retailcrm/order.php | 14 +++ .../model/extension/retailcrm/references.php | 25 ++-- .../template/extension/module/retailcrm.tpl | 72 +++++++++-- .../template/extension/module/retailcrm.twig | 116 +++++++++++++----- .../extension/analytics/daemon_collector.php | 26 ++-- .../model/extension/retailcrm/customer.php | 8 +- catalog/model/extension/retailcrm/order.php | 20 ++- .../library/retailcrm/OpencartApiClient.php | 7 +- system/library/retailcrm/objects.xml | 2 +- 15 files changed, 321 insertions(+), 121 deletions(-) diff --git a/admin/controller/extension/module/retailcrm.php b/admin/controller/extension/module/retailcrm.php index 8ff26b7..4b77e6d 100644 --- a/admin/controller/extension/module/retailcrm.php +++ b/admin/controller/extension/module/retailcrm.php @@ -107,7 +107,7 @@ class ControllerExtensionModuleRetailcrm extends Controller $moduleTitle = $this->getModuleTitle(); $this->loadModels(); $this->load->model('setting/setting'); - $this->{'model_' . $this->modelExtension}->install('analytics', $collector); + $this->{'model_' . $this->modelExtension}->install('analytics', 'daemon_collector'); $this->model_setting_setting->editSetting($collector, array($collector . '_status' => 1)); } @@ -122,7 +122,7 @@ class ControllerExtensionModuleRetailcrm extends Controller $this->loadModels(); $this->load->model('setting/setting'); $this->model_setting_setting->editSetting($collector, array($collector . '_status' => 0)); - $this->{'model_' . $this->modelExtension}->uninstall('analytics', $collector); + $this->{'model_' . $this->modelExtension}->uninstall('analytics', 'daemon_collector'); } /** @@ -161,6 +161,10 @@ class ControllerExtensionModuleRetailcrm extends Controller $this->request->post[$moduleTitle . '_url'] = 'https://'.$crm_url; } + if ($this->request->post[$moduleTitle . '_custom_field_active'] == 0) { + unset($this->request->post[$moduleTitle . '_custom_field']); + } + $this->model_setting_setting->editSetting( $moduleTitle, $this->request->post @@ -263,7 +267,13 @@ class ControllerExtensionModuleRetailcrm extends Controller 'text_error_custom_field', 'text_error_cf_opencart', 'text_error_cf_retailcrm', - 'retailcrm_dict_custom_fields' + 'retailcrm_dict_custom_fields', + 'text_payment', + 'text_shipping', + 'retailcrm_dict_default', + 'text_custom_field_activity', + 'text_orders_custom_fields', + 'text_customers_custom_fields' ); $_data = &$data; diff --git a/admin/language/en-gb/extension/module/retailcrm.php b/admin/language/en-gb/extension/module/retailcrm.php index 4f9451e..ae9447f 100644 --- a/admin/language/en-gb/extension/module/retailcrm.php +++ b/admin/language/en-gb/extension/module/retailcrm.php @@ -17,7 +17,7 @@ $_['general_tab_text'] = 'General'; $_['references_tab_text'] = 'References'; $_['collector_tab_text'] = 'Daemon Collector'; $_['collector_custom_text'] = 'Custom form'; -$_['custom_fields_tab_text'] = 'Пользовательские поля'; +$_['custom_fields_tab_text'] = 'Custom fields'; $_['retailcrm_apiversion'] = 'API Version'; $_['retailcrm_url'] = 'RetailCRM URL'; $_['retailcrm_apikey'] = 'RetailCRM API Key'; @@ -32,6 +32,7 @@ $_['text_success_catalog'] = 'Catalog successfully unloaded'; $_['text_error_order'] = 'Error! Order is not unloaded!'; $_['text_error_order_id'] = 'Error! Enter the correct order number!'; $_['text_collector_activity'] = 'Use Daemon Collector'; +$_['text_custom_field_activity'] = 'Send custom fields'; $_['text_collector_form_capture']= 'Show capture form'; $_['text_collector_period'] = 'Form show period (in minutes)'; $_['text_label_promo'] = 'Text form title'; @@ -40,17 +41,22 @@ $_['field_name'] = 'Name'; $_['field_email'] = 'Email'; $_['field_phone'] = 'Phone'; $_['text_require'] = 'Require'; +$_['text_payment'] = 'Payment'; +$_['text_shipping'] = 'Shipping'; +$_['text_orders_custom_fields'] = 'Orders custom fields'; +$_['text_customers_custom_fields'] = 'Customers custom fields'; $_['text_error_collector_fields']= 'Fill in the field names Daemon Collector'; $_['text_error_api'] = 'The selected version of the API is unavailable'; -$_['text_error_custom_field'] = 'Создайте пользовательские поля в карточке клиента в Opencart и RetailCRM, чтобы настроить их передачу'; -$_['text_error_cf_opencart'] = 'Отсутствуют пользовательские поля в Opencart'; -$_['text_error_cf_retailcrm'] = 'Отсутствуют пользовательские поля в RetailCRM'; -$_['text_error_save'] = 'Ошибка сохранения настроек'; +$_['text_error_custom_field'] = 'Create custom fields for customer in Opencart and RetailCRM, that to configure their transmission'; +$_['text_error_cf_opencart'] = 'None custom fields in Opencart'; +$_['text_error_cf_retailcrm'] = 'None custom fields in RetailCRM'; +$_['text_error_save'] = 'Error saving settings'; $_['retailcrm_dict_delivery'] = 'Shipment methods'; $_['retailcrm_dict_status'] = 'Order statuses'; $_['retailcrm_dict_payment'] = 'Payment methods'; -$_['retailcrm_dict_custom_fields'] = 'Настройка пользовательских полей'; +$_['retailcrm_dict_custom_fields'] = 'Configure custom fields'; +$_['retailcrm_dict_default'] = 'Default'; $_['column_total'] = 'Total'; $_['product_summ'] = 'Amount'; diff --git a/admin/language/ru-ru/extension/module/retailcrm.php b/admin/language/ru-ru/extension/module/retailcrm.php index 15656f5..5a86671 100644 --- a/admin/language/ru-ru/extension/module/retailcrm.php +++ b/admin/language/ru-ru/extension/module/retailcrm.php @@ -32,6 +32,7 @@ $_['text_success_catalog'] = 'Каталог успешно выгруже $_['text_error_order'] = 'Ошибка! Заказ не выгружен!'; $_['text_error_order_id'] = 'Ошибка! Введите корректный номер заказа!'; $_['text_collector_activity'] = 'Использовать Демон Collector'; +$_['text_custom_field_activity'] = 'Передавать кастомые поля'; $_['text_collector_form_capture']= 'Показывать форму захвата'; $_['text_collector_period'] = 'Периодичность всплывания формы (в минутах)'; $_['text_label_promo'] = 'Текст заголовка формы'; @@ -40,17 +41,22 @@ $_['field_name'] = 'Имя'; $_['field_email'] = 'Email'; $_['field_phone'] = 'Телефон'; $_['text_require'] = 'Обязательно для заполнения'; +$_['text_payment'] = 'Оплата'; +$_['text_shipping'] = 'Доставка'; +$_['text_orders_custom_fields'] = 'Кастомные поля заказов'; +$_['text_customers_custom_fields'] = 'Кастомные поля клиентов'; $_['text_error_collector_fields']= 'Заполните названия полей формы Демон Collector'; $_['text_error_api'] = 'Недоступна выбранная версия API.'; $_['text_error_custom_field'] = 'Создайте пользовательские поля в карточке клиента в Opencart и RetailCRM, чтобы настроить их передачу'; $_['text_error_cf_opencart'] = 'Отсутствуют пользовательские поля в Opencart'; $_['text_error_cf_retailcrm'] = 'Отсутствуют пользовательские поля в RetailCRM'; -$_['text_error_save'] = 'Ошибка сохранения настроек'; - +$_['text_error_save'] = 'Ошибка сохранения настроек'; + $_['retailcrm_dict_delivery'] = 'Способы доставки'; $_['retailcrm_dict_status'] = 'Статусы'; $_['retailcrm_dict_payment'] = 'Способы оплаты'; $_['retailcrm_dict_custom_fields'] = 'Настройка пользовательских полей'; +$_['retailcrm_dict_default'] = 'По умалчанию'; $_['column_total'] = 'Итого'; $_['product_summ'] = 'Сумма'; diff --git a/admin/model/extension/retailcrm/customer.php b/admin/model/extension/retailcrm/customer.php index 7e5f320..ab1b6e1 100644 --- a/admin/model/extension/retailcrm/customer.php +++ b/admin/model/extension/retailcrm/customer.php @@ -65,12 +65,14 @@ class ModelExtensionRetailcrmCustomer extends Model { $customFields = json_decode($customer['custom_field']); foreach ($customFields as $key => $value) { - if (isset($this->settings[$moduleTitle . '_custom_field'][$key])) { - $customFieldsToCrm[$this->settings[$moduleTitle . '_custom_field'][$key]] = $value; + if (isset($this->settings[$moduleTitle . '_custom_field']['c_' . $key])) { + $customFieldsToCrm[$this->settings[$moduleTitle . '_custom_field']['c_' . $key]] = $value; } } - - $customerToCrm['customFields'] = $customFieldsToCrm; + + if (isset($customFieldsToCrm)) { + $customerToCrm['customFields'] = $customFieldsToCrm; + } } return $customerToCrm; diff --git a/admin/model/extension/retailcrm/history/v3.php b/admin/model/extension/retailcrm/history/v3.php index 7128e3b..5500944 100644 --- a/admin/model/extension/retailcrm/history/v3.php +++ b/admin/model/extension/retailcrm/history/v3.php @@ -58,16 +58,15 @@ class ModelExtensionRetailcrmHistoryV3 extends Model $this->subtotalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'sub_total'); $this->totalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'total'); $this->shippingSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'shipping'); - $this->delivery = array_flip($settings[$moduleTitle . '_delivery']); $this->payment = array_flip($settings[$moduleTitle . '_payment']); $this->status = array_flip($settings[$moduleTitle . '_status']); - + $this->payment_default = $settings[$moduleTitle . '_default_payment']; + $this->delivery_default = $settings[$moduleTitle . '_default_shipping']; $this->ocPayment = $this->model_extension_retailcrm_references ->getOpercartPaymentTypes(); $this->ocDelivery = $settings[$moduleTitle . '_delivery']; - $this->zones = $this->model_localisation_zone->getZones(); $updatedOrders = array(); @@ -180,12 +179,13 @@ class ModelExtensionRetailcrmHistoryV3 extends Model $paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']); } + $delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : null; + $payment = isset($order['paymentType']) ? $order['paymentType'] : null; + $data['payment_country_id'] = isset($paymentCountry) ? $paymentCountry['country_id'] : 0; $data['payment_zone_id'] = $payment_zone_id; - $data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : 0; $data['shipping_zone_id'] = $shipping_zone_id; - $data['shipping_address'] = '0'; $data['shipping_firstname'] = $order['firstName']; $data['shipping_lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName']; @@ -195,14 +195,12 @@ class ModelExtensionRetailcrmHistoryV3 extends Model $data['shipping_company_id'] = ''; $data['shipping_city'] = $order['delivery']['address']['city']; $data['shipping_postcode'] = $order['delivery']['address']['index']; - - $data['shipping'] = $this->delivery[$order['delivery']['code']]; + $data['shipping'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default; $data['shipping_method'] = $this->ocDelivery[$data['shipping']]; - $data['shipping_code'] = $this->delivery[$order['delivery']['code']]; - - $data['payment'] = $this->payment[$order['paymentType']]; + $data['shipping_code'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default; + $data['payment'] = $payment != null ? $this->payment[$payment] : $this->payment_default; $data['payment_method'] = $this->ocPayment[$data['payment']]; - $data['payment_code'] = $this->payment[$order['paymentType']]; + $data['payment_code'] = $payment != null ? $this->payment[$payment] : $this->payment_default; // this data will not retrive from crm for now $data['tax'] = ''; @@ -428,6 +426,9 @@ class ModelExtensionRetailcrmHistoryV3 extends Model $paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']); } + $delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : null; + $payment = isset($order['paymentType']) ? $order['paymentType'] : null; + $data['payment_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : 0; $data['payment_zone_id'] = $payment_zone_id; $data['shipping_country_id'] = $shippingCountry ? $shippingCountry['country_id'] : 0; @@ -441,13 +442,12 @@ class ModelExtensionRetailcrmHistoryV3 extends Model $data['shipping_company_id'] = ''; $data['shipping_city'] = $order['delivery']['address']['city']; $data['shipping_postcode'] = $order['delivery']['address']['index']; - - $data['shipping'] = $this->delivery[$order['delivery']['code']]; + $data['shipping'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default; $data['shipping_method'] = $this->ocDelivery[$data['shipping']]; - $data['shipping_code'] = $this->delivery[$order['delivery']['code']]; - $data['payment'] = $this->payment[$order['paymentType']]; + $data['shipping_code'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default; + $data['payment'] = $payment != null ? $this->payment[$payment] : $this->payment_default; $data['payment_method'] = $this->ocPayment[$data['payment']]; - $data['payment_code'] = $this->payment[$order['paymentType']]; + $data['payment_code'] = $payment != null ? $this->payment[$payment] : $this->payment_default; // this data will not retrive from crm for now $data['tax'] = ''; diff --git a/admin/model/extension/retailcrm/history/v4_5.php b/admin/model/extension/retailcrm/history/v4_5.php index 0e3ee02..4463cf3 100644 --- a/admin/model/extension/retailcrm/history/v4_5.php +++ b/admin/model/extension/retailcrm/history/v4_5.php @@ -5,6 +5,7 @@ class ModelExtensionRetailcrmHistoryV45 extends Model protected $createResult; private $opencartApiClient; + private $customFieldSetting; public function request() { @@ -82,7 +83,8 @@ class ModelExtensionRetailcrmHistoryV45 extends Model $this->delivery = array_flip($settings[$this->moduleTitle . '_delivery']); $this->payment = array_flip($settings[$this->moduleTitle . '_payment']); $this->status = array_flip($settings[$this->moduleTitle . '_status']); - + $this->delivery_default = $settings[$this->moduleTitle . '_default_shipping']; + $this->payment_default = $settings[$this->moduleTitle . '_default_payment']; $this->ocPayment = $this->model_extension_retailcrm_references ->getOpercartPaymentTypes(); @@ -90,6 +92,10 @@ class ModelExtensionRetailcrmHistoryV45 extends Model $this->zones = $this->model_localisation_zone->getZones(); + if (isset($settings[$this->moduleTitle . '_custom_field'])) { + $this->customFieldSetting = array_flip($settings[$this->moduleTitle . '_custom_field']); + } + $updatedOrders = array(); $newOrders = array(); @@ -163,7 +169,7 @@ class ModelExtensionRetailcrmHistoryV45 extends Model foreach ($orders as $order) { $store = $this->config->get('config_store_id'); - if (isset($order['payments'])) { + if ($order['payments']) { foreach ($order['payments'] as $orderPayment) { if (isset($orderPayment['externalId'])) { $payment = $orderPayment; @@ -239,7 +245,8 @@ class ModelExtensionRetailcrmHistoryV45 extends Model if (isset($order['customer']['address']['countryIso'])) { $paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']); } - + + $delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : null; $data['payment_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : 0; $data['payment_zone_id'] = $payment_zone_id; $data['shipping_country_id'] = $shippingCountry ? $shippingCountry['country_id'] : 0; @@ -253,9 +260,9 @@ class ModelExtensionRetailcrmHistoryV45 extends Model $data['shipping_company_id'] = ''; $data['shipping_city'] = $order['delivery']['address']['city']; $data['shipping_postcode'] = $order['delivery']['address']['index']; - $data['shipping'] = $this->delivery[$order['delivery']['code']]; + $data['shipping'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default; $data['shipping_method'] = $this->ocDelivery[$data['shipping']]; - $data['shipping_code'] = $this->delivery[$order['delivery']['code']]; + $data['shipping_code'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default; if (isset($payment)) { $data['payment'] = $this->payment[$payment['type']]; @@ -318,6 +325,17 @@ class ModelExtensionRetailcrmHistoryV45 extends Model ); } + if (isset($this->customFieldSetting) && $order['customFields']) { + foreach ($order['customFields'] as $code => $value) { + if (array_key_exists($code, $this->customFieldSetting)) { + $fieldCode = str_replace('o_', '', $this->customFieldSetting[$code]); + $customFields[$fieldCode] = $value; + } + } + + $data['custom_field'] = isset($customFields) ? $customFields : ''; + } + $deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0; if(isset($order['discount']) && $order['discount'] > 0) { @@ -377,7 +395,7 @@ class ModelExtensionRetailcrmHistoryV45 extends Model foreach ($orders as $order) { $store = $this->config->get('config_store_id'); - if (isset($order['payments'])) { + if ($order['payments']) { $payment = end($order['payments']); } elseif (isset($order['paymentType'])) { $payment['type'] = $order['paymentType']; @@ -498,6 +516,7 @@ class ModelExtensionRetailcrmHistoryV45 extends Model $paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']); } + $delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : null; $data['payment_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : 0; $data['payment_zone_id'] = $payment_zone_id; $data['shipping_country_id'] = $shippingCountry ? $shippingCountry['country_id'] : 0; @@ -511,15 +530,18 @@ class ModelExtensionRetailcrmHistoryV45 extends Model $data['shipping_company_id'] = ''; $data['shipping_city'] = $order['delivery']['address']['city']; $data['shipping_postcode'] = $order['delivery']['address']['index']; - - $data['shipping'] = $this->delivery[$order['delivery']['code']]; + $data['shipping'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default; $data['shipping_method'] = $this->ocDelivery[$data['shipping']]; - $data['shipping_code'] = $this->delivery[$order['delivery']['code']]; + $data['shipping_code'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default; if (isset($payment)) { $data['payment'] = $this->payment[$payment['type']]; $data['payment_method'] = $this->ocPayment[$data['payment']]; $data['payment_code'] = $this->payment[$payment['type']]; + } else { + $data['payment'] = $this->payment_default; + $data['payment_method'] = $this->ocPayment[$data['payment']]; + $data['payment_code'] = $this->payment_default; } // this data will not retrive from crm for now @@ -572,6 +594,17 @@ class ModelExtensionRetailcrmHistoryV45 extends Model ); } + if (isset($this->customFieldSetting) && $order['customFields']) { + foreach ($order['customFields'] as $code => $value) { + if (array_key_exists($code, $this->customFieldSetting)) { + $fieldCode = str_replace('o_', '', $this->customFieldSetting[$code]); + $customFields[$fieldCode] = $value; + } + } + + $data['custom_field'] = isset($customFields) ? $customFields : ''; + } + $deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0; $data['order_total'] = array( @@ -613,13 +646,7 @@ class ModelExtensionRetailcrmHistoryV45 extends Model } protected function updateCustomers($customers) - { - $settings = $this->model_setting_setting->getSetting($this->moduleTitle); - - if (isset($settings[$this->moduleTitle . '_custom_field'])) { - $settings = array_flip($settings[$this->moduleTitle . '_custom_field']); - } - + { foreach ($customers as $customer) { $customer_id = $customer['externalId']; @@ -656,10 +683,11 @@ class ModelExtensionRetailcrmHistoryV45 extends Model $customerData['address'] = array($customerAddress); - if ($settings && $customer['customFields']) { + if (isset($this->customFieldSetting) && $customer['customFields']) { foreach ($customer['customFields'] as $code => $value) { - if (array_key_exists($code, $settings)) { - $customFields[$settings[$code]] = $value; + if (array_key_exists($code, $this->customFieldSetting)) { + $fieldCode = str_replace('c_', '', $this->customFieldSetting[$code]); + $customFields[$fieldCode] = $value; } } diff --git a/admin/model/extension/retailcrm/order.php b/admin/model/extension/retailcrm/order.php index b848aa4..75e90c4 100644 --- a/admin/model/extension/retailcrm/order.php +++ b/admin/model/extension/retailcrm/order.php @@ -172,6 +172,20 @@ class ModelExtensionRetailcrmOrder extends Model { $order['items'][] = $item; } + if (isset($this->settings[$this->moduleTitle . '_custom_field']) && $order_data['custom_field']) { + $customFields = json_decode($order_data['custom_field']); + + foreach ($customFields as $key => $value) { + if (isset($this->settings[$moduleTitle . '_custom_field']['o_' . $key])) { + $customFieldsToCrm[$this->settings[$this->moduleTitle . '_custom_field']['o_' . $key]] = $value; + } + } + + if (isset($customFieldsToCrm)) { + $order['customFields'] = $customFieldsToCrm; + } + } + return $order; } diff --git a/admin/model/extension/retailcrm/references.php b/admin/model/extension/retailcrm/references.php index b6ae835..8f9f832 100644 --- a/admin/model/extension/retailcrm/references.php +++ b/admin/model/extension/retailcrm/references.php @@ -18,7 +18,7 @@ class ModelExtensionRetailcrmReferences extends Model public function getDeliveryTypes() { $this->load->model('setting/store'); - + return array( 'opencart' => $this->getOpercartDeliveryTypes(), 'retailcrm' => $this->getApiDeliveryTypes() @@ -40,15 +40,15 @@ class ModelExtensionRetailcrmReferences extends Model 'retailcrm' => $this->getApiPaymentTypes() ); } - + public function getCustomFields() { return array( 'opencart' => $this->getOpencartCustomFields(), - 'retailcrm' => $this->getApiCustomerCustomFields() + 'retailcrm' => $this->getApiCustomFields() ); } - + public function getOpercartOrderStatuses() { $this->load->model('localisation/order_status'); @@ -119,14 +119,21 @@ class ModelExtensionRetailcrmReferences extends Model return (!$response->isSuccessful()) ? array() : $response->paymentTypes; } - public function getApiCustomerCustomFields() + public function getApiCustomFields() { $this->initApi(); + + $customers = $this->retailcrm->customFieldsList(array('entity' => 'customer')); + $orders = $this->retailcrm->customFieldsList(array('entity' => 'order')); + + $customFieldsCustomers = (!$customers->isSuccessful()) ? array() : $customers->customFields; + $customFieldsOrders = (!$orders->isSuccessful()) ? array() : $orders->customFields; + + if (!$customFieldsCustomers && !$customFieldsOrders) { + return array(); + } - $filter = array('entity' => 'customer'); - $response = $this->retailcrm->customFieldsList($filter); - - return (!$response->isSuccessful()) ? array() : $response->customFields; + return array('customers' => $customFieldsCustomers, 'orders' => $customFieldsOrders); } protected function initApi() diff --git a/admin/view/template/extension/module/retailcrm.tpl b/admin/view/template/extension/module/retailcrm.tpl index 3648f36..2726cfb 100644 --- a/admin/view/template/extension/module/retailcrm.tpl +++ b/admin/view/template/extension/module/retailcrm.tpl @@ -149,7 +149,32 @@ - +

+
+ + +
+
+ + +
@@ -176,8 +201,6 @@ -
-
@@ -222,8 +243,6 @@
- $label) : ?>
@@ -234,19 +253,46 @@
- - -
-

+

+
+ + + +
+

- +
+ +
+ +

+ + +
+ - {% for k, v in delivery.retailcrm %} - - {% endfor %} - + {% for k, v in delivery.retailcrm %} + + {% endfor %} +
- {% endif %} + {% endif %} {% endfor %} {% endfor %} @@ -147,7 +150,33 @@
{% endfor %} - +

{{ retailcrm_dict_default }}

+
+ + +
+
+ + +
{% endif %} {% endif %} @@ -174,8 +203,6 @@ - {% if saved_settings.module_retailcrm_collector.site_key is not empty and - saved_settings.module_retailcrm_collector_active == 1 %}
- {% if saved_settings.module_retailcrm_collector.form_capture is defined and - saved_settings.module_retailcrm_collector.form_capture == 1 %}
- - + +
- - + +
- - + +
- +
- {% if saved_settings.module_retailcrm_collector.custom_form is defined and - saved_settings.module_retailcrm_collector.custom_form == 1 %} {% for field, label in collectorFields %}
- {# #} - + +
{% endfor %} - {% endif %} - {% endif %} - {% endif %} - {% if saved_settings.retailcrm_apiversion is defined and saved_settings.retailcrm_apiversion == 'v5' and customFields is defined %} + {% if saved_settings.module_retailcrm_apiversion is defined and saved_settings.module_retailcrm_apiversion == 'v5' and customFields is defined %}

{{ retailcrm_dict_custom_fields }}

{% if customFields.retailcrm is not empty and customFields.opencart is not empty %} +
+ + + +
+

{{ text_customers_custom_fields }}

{% for customField in customFields.opencart %} - {% set fid = customField.custom_field_id %} + {% set fid = 'c_' ~ customField.custom_field_id %}
- + {% for v in customFields.retailcrm.customers %} + {% endfor %} - + +
+ {% endfor %} +

{{ text_orders_custom_fields }}

+ {% for customField in customFields.opencart %} + {% set fid = 'o_' ~ customField.custom_field_id %} +
+ +
{% endfor %} {% elseif customFields.retailcrm is empty and customFields.opencart is empty %} diff --git a/catalog/controller/extension/analytics/daemon_collector.php b/catalog/controller/extension/analytics/daemon_collector.php index 623a31a..bbfb5a9 100644 --- a/catalog/controller/extension/analytics/daemon_collector.php +++ b/catalog/controller/extension/analytics/daemon_collector.php @@ -20,7 +20,11 @@ class ControllerExtensionAnalyticsDaemonCollector extends Controller { $cntEmpty = 0; foreach ($setting['custom'] as $field => $label) { - if (empty($label)) { $cntEmpty += 1; continue; } + if (empty($label)) { + $cntEmpty += 1; + + continue; + } if (isset($setting['require'][$field . '_require'])) { $customForm .= "\n\t'$field': { required: true, label: '$label' },"; @@ -46,7 +50,7 @@ class ControllerExtensionAnalyticsDaemonCollector extends Controller { });"; } else { $captureForm = "_rc('require', 'capture-form', { - 'period': " . $settings['retailcrm_collector']['period'] . ", + 'period': " . $settings[$moduleTitle . '_collector']['period'] . ", " . $customForm . " });"; } @@ -67,14 +71,18 @@ class ControllerExtensionAnalyticsDaemonCollector extends Controller { $captureForm = ""; } - $js = ""; return html_entity_decode($js, ENT_QUOTES, 'UTF-8'); diff --git a/catalog/model/extension/retailcrm/customer.php b/catalog/model/extension/retailcrm/customer.php index 4f7700c..1676907 100644 --- a/catalog/model/extension/retailcrm/customer.php +++ b/catalog/model/extension/retailcrm/customer.php @@ -55,12 +55,14 @@ class ModelExtensionRetailcrmCustomer extends Model { $customFields = json_decode($customer['custom_field']); foreach ($customFields as $key => $value) { - if (isset($this->settings[$moduleTitle . '_custom_field'][$key])) { - $customFieldsToCrm[$this->settings[$moduleTitle . '_custom_field'][$key]] = $value; + if (isset($this->settings[$moduleTitle . '_custom_field']['c_' . $key])) { + $customFieldsToCrm[$this->settings[$moduleTitle . '_custom_field']['c_' . $key]] = $value; } } - $customerToCrm['customFields'] = $customFieldsToCrm; + if (isset($customFieldsToCrm)) { + $customerToCrm['customFields'] = $customFieldsToCrm; + } } return $customerToCrm; diff --git a/catalog/model/extension/retailcrm/order.php b/catalog/model/extension/retailcrm/order.php index e9fafaa..fba3af0 100644 --- a/catalog/model/extension/retailcrm/order.php +++ b/catalog/model/extension/retailcrm/order.php @@ -63,10 +63,12 @@ class ModelExtensionRetailcrmOrder extends Model { if ($this->settings[$this->moduleTitle . '_apiversion'] == 'v5' && $response->isSuccessful()) { $response_order = $this->retailcrm->ordersGet($order_id); - if ($response_order->isSuccessful()) $order_info = $response_order['order']; + if ($response_order->isSuccessful()) { + $order_info = $response_order['order']; + } foreach ($order_info['payments'] as $payment_data) { - if ($payment_data['externalId'] == $order_id) { + if (isset($payment_data['externalId']) && $payment_data['externalId'] == $order_id) { $payment = $payment_data; } } @@ -234,6 +236,20 @@ class ModelExtensionRetailcrmOrder extends Model { } } } + + if (isset($this->settings[$this->moduleTitle . '_custom_field']) && $order_data['custom_field']) { + $customFields = $order_data['custom_field']; + + foreach ($customFields as $key => $value) { + if (isset($this->settings[$this->moduleTitle . '_custom_field']['o_' . $key])) { + $customFieldsToCrm[$this->settings[$this->moduleTitle . '_custom_field']['o_' . $key]] = $value; + } + } + + if (isset($customFieldsToCrm)) { + $order['customFields'] = $customFieldsToCrm; + } + } } return $order; diff --git a/system/library/retailcrm/OpencartApiClient.php b/system/library/retailcrm/OpencartApiClient.php index 514dbda..0d33f7a 100644 --- a/system/library/retailcrm/OpencartApiClient.php +++ b/system/library/retailcrm/OpencartApiClient.php @@ -138,8 +138,13 @@ class OpencartApiClient { 'lastname' => $data['lastname'], 'email' => $data['email'], 'telephone' => !empty($data['telephone']) ? $data['telephone'] : '0000', - 'fax' => $data['fax'], + 'fax' => $data['fax'] ); + + if (isset($data['custom_field'])) { + $customer['custom_field'] = $data['custom_field']; + } + $this->request('customer', array(), $customer); $products = array(); diff --git a/system/library/retailcrm/objects.xml b/system/library/retailcrm/objects.xml index 45068e7..a3faa5a 100644 --- a/system/library/retailcrm/objects.xml +++ b/system/library/retailcrm/objects.xml @@ -63,7 +63,7 @@ shipmentDate shipped - payments + payment amount paidAt comment