Custom fields for v5, default payment and shipping methods for history upload

This commit is contained in:
Akolzin Dmitry 2017-09-21 10:09:26 +03:00
parent cdc1c9cf6b
commit 6875bc5f61
15 changed files with 321 additions and 121 deletions

View File

@ -107,7 +107,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
$moduleTitle = $this->getModuleTitle(); $moduleTitle = $this->getModuleTitle();
$this->loadModels(); $this->loadModels();
$this->load->model('setting/setting'); $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)); $this->model_setting_setting->editSetting($collector, array($collector . '_status' => 1));
} }
@ -122,7 +122,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
$this->loadModels(); $this->loadModels();
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->model_setting_setting->editSetting($collector, array($collector . '_status' => 0)); $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; $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( $this->model_setting_setting->editSetting(
$moduleTitle, $moduleTitle,
$this->request->post $this->request->post
@ -263,7 +267,13 @@ class ControllerExtensionModuleRetailcrm extends Controller
'text_error_custom_field', 'text_error_custom_field',
'text_error_cf_opencart', 'text_error_cf_opencart',
'text_error_cf_retailcrm', '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; $_data = &$data;

View File

@ -17,7 +17,7 @@ $_['general_tab_text'] = 'General';
$_['references_tab_text'] = 'References'; $_['references_tab_text'] = 'References';
$_['collector_tab_text'] = 'Daemon Collector'; $_['collector_tab_text'] = 'Daemon Collector';
$_['collector_custom_text'] = 'Custom form'; $_['collector_custom_text'] = 'Custom form';
$_['custom_fields_tab_text'] = 'Пользовательские поля'; $_['custom_fields_tab_text'] = 'Custom fields';
$_['retailcrm_apiversion'] = 'API Version'; $_['retailcrm_apiversion'] = 'API Version';
$_['retailcrm_url'] = 'RetailCRM URL'; $_['retailcrm_url'] = 'RetailCRM URL';
$_['retailcrm_apikey'] = 'RetailCRM API Key'; $_['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'] = 'Error! Order is not unloaded!';
$_['text_error_order_id'] = 'Error! Enter the correct order number!'; $_['text_error_order_id'] = 'Error! Enter the correct order number!';
$_['text_collector_activity'] = 'Use Daemon Collector'; $_['text_collector_activity'] = 'Use Daemon Collector';
$_['text_custom_field_activity'] = 'Send custom fields';
$_['text_collector_form_capture']= 'Show capture form'; $_['text_collector_form_capture']= 'Show capture form';
$_['text_collector_period'] = 'Form show period (in minutes)'; $_['text_collector_period'] = 'Form show period (in minutes)';
$_['text_label_promo'] = 'Text form title'; $_['text_label_promo'] = 'Text form title';
@ -40,17 +41,22 @@ $_['field_name'] = 'Name';
$_['field_email'] = 'Email'; $_['field_email'] = 'Email';
$_['field_phone'] = 'Phone'; $_['field_phone'] = 'Phone';
$_['text_require'] = 'Require'; $_['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_collector_fields']= 'Fill in the field names Daemon Collector';
$_['text_error_api'] = 'The selected version of the API is unavailable'; $_['text_error_api'] = 'The selected version of the API is unavailable';
$_['text_error_custom_field'] = 'Создайте пользовательские поля в карточке клиента в Opencart и RetailCRM, чтобы настроить их передачу'; $_['text_error_custom_field'] = 'Create custom fields for customer in Opencart and RetailCRM, that to configure their transmission';
$_['text_error_cf_opencart'] = 'Отсутствуют пользовательские поля в Opencart'; $_['text_error_cf_opencart'] = 'None custom fields in Opencart';
$_['text_error_cf_retailcrm'] = 'Отсутствуют пользовательские поля в RetailCRM'; $_['text_error_cf_retailcrm'] = 'None custom fields in RetailCRM';
$_['text_error_save'] = 'Ошибка сохранения настроек'; $_['text_error_save'] = 'Error saving settings';
$_['retailcrm_dict_delivery'] = 'Shipment methods'; $_['retailcrm_dict_delivery'] = 'Shipment methods';
$_['retailcrm_dict_status'] = 'Order statuses'; $_['retailcrm_dict_status'] = 'Order statuses';
$_['retailcrm_dict_payment'] = 'Payment methods'; $_['retailcrm_dict_payment'] = 'Payment methods';
$_['retailcrm_dict_custom_fields'] = 'Настройка пользовательских полей'; $_['retailcrm_dict_custom_fields'] = 'Configure custom fields';
$_['retailcrm_dict_default'] = 'Default';
$_['column_total'] = 'Total'; $_['column_total'] = 'Total';
$_['product_summ'] = 'Amount'; $_['product_summ'] = 'Amount';

View File

@ -32,6 +32,7 @@ $_['text_success_catalog'] = 'Каталог успешно выгруже
$_['text_error_order'] = 'Ошибка! Заказ не выгружен!'; $_['text_error_order'] = 'Ошибка! Заказ не выгружен!';
$_['text_error_order_id'] = 'Ошибка! Введите корректный номер заказа!'; $_['text_error_order_id'] = 'Ошибка! Введите корректный номер заказа!';
$_['text_collector_activity'] = 'Использовать Демон Collector'; $_['text_collector_activity'] = 'Использовать Демон Collector';
$_['text_custom_field_activity'] = 'Передавать кастомые поля';
$_['text_collector_form_capture']= 'Показывать форму захвата'; $_['text_collector_form_capture']= 'Показывать форму захвата';
$_['text_collector_period'] = 'Периодичность всплывания формы (в минутах)'; $_['text_collector_period'] = 'Периодичность всплывания формы (в минутах)';
$_['text_label_promo'] = 'Текст заголовка формы'; $_['text_label_promo'] = 'Текст заголовка формы';
@ -40,17 +41,22 @@ $_['field_name'] = 'Имя';
$_['field_email'] = 'Email'; $_['field_email'] = 'Email';
$_['field_phone'] = 'Телефон'; $_['field_phone'] = 'Телефон';
$_['text_require'] = 'Обязательно для заполнения'; $_['text_require'] = 'Обязательно для заполнения';
$_['text_payment'] = 'Оплата';
$_['text_shipping'] = 'Доставка';
$_['text_orders_custom_fields'] = 'Кастомные поля заказов';
$_['text_customers_custom_fields'] = 'Кастомные поля клиентов';
$_['text_error_collector_fields']= 'Заполните названия полей формы Демон Collector'; $_['text_error_collector_fields']= 'Заполните названия полей формы Демон Collector';
$_['text_error_api'] = 'Недоступна выбранная версия API.'; $_['text_error_api'] = 'Недоступна выбранная версия API.';
$_['text_error_custom_field'] = 'Создайте пользовательские поля в карточке клиента в Opencart и RetailCRM, чтобы настроить их передачу'; $_['text_error_custom_field'] = 'Создайте пользовательские поля в карточке клиента в Opencart и RetailCRM, чтобы настроить их передачу';
$_['text_error_cf_opencart'] = 'Отсутствуют пользовательские поля в Opencart'; $_['text_error_cf_opencart'] = 'Отсутствуют пользовательские поля в Opencart';
$_['text_error_cf_retailcrm'] = 'Отсутствуют пользовательские поля в RetailCRM'; $_['text_error_cf_retailcrm'] = 'Отсутствуют пользовательские поля в RetailCRM';
$_['text_error_save'] = 'Ошибка сохранения настроек'; $_['text_error_save'] = 'Ошибка сохранения настроек';
$_['retailcrm_dict_delivery'] = 'Способы доставки'; $_['retailcrm_dict_delivery'] = 'Способы доставки';
$_['retailcrm_dict_status'] = 'Статусы'; $_['retailcrm_dict_status'] = 'Статусы';
$_['retailcrm_dict_payment'] = 'Способы оплаты'; $_['retailcrm_dict_payment'] = 'Способы оплаты';
$_['retailcrm_dict_custom_fields'] = 'Настройка пользовательских полей'; $_['retailcrm_dict_custom_fields'] = 'Настройка пользовательских полей';
$_['retailcrm_dict_default'] = 'По умалчанию';
$_['column_total'] = 'Итого'; $_['column_total'] = 'Итого';
$_['product_summ'] = 'Сумма'; $_['product_summ'] = 'Сумма';

View File

@ -65,12 +65,14 @@ class ModelExtensionRetailcrmCustomer extends Model {
$customFields = json_decode($customer['custom_field']); $customFields = json_decode($customer['custom_field']);
foreach ($customFields as $key => $value) { foreach ($customFields as $key => $value) {
if (isset($this->settings[$moduleTitle . '_custom_field'][$key])) { if (isset($this->settings[$moduleTitle . '_custom_field']['c_' . $key])) {
$customFieldsToCrm[$this->settings[$moduleTitle . '_custom_field'][$key]] = $value; $customFieldsToCrm[$this->settings[$moduleTitle . '_custom_field']['c_' . $key]] = $value;
} }
} }
$customerToCrm['customFields'] = $customFieldsToCrm; if (isset($customFieldsToCrm)) {
$customerToCrm['customFields'] = $customFieldsToCrm;
}
} }
return $customerToCrm; return $customerToCrm;

View File

@ -58,16 +58,15 @@ class ModelExtensionRetailcrmHistoryV3 extends Model
$this->subtotalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'sub_total'); $this->subtotalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'sub_total');
$this->totalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'total'); $this->totalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'total');
$this->shippingSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'shipping'); $this->shippingSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'shipping');
$this->delivery = array_flip($settings[$moduleTitle . '_delivery']); $this->delivery = array_flip($settings[$moduleTitle . '_delivery']);
$this->payment = array_flip($settings[$moduleTitle . '_payment']); $this->payment = array_flip($settings[$moduleTitle . '_payment']);
$this->status = array_flip($settings[$moduleTitle . '_status']); $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 $this->ocPayment = $this->model_extension_retailcrm_references
->getOpercartPaymentTypes(); ->getOpercartPaymentTypes();
$this->ocDelivery = $settings[$moduleTitle . '_delivery']; $this->ocDelivery = $settings[$moduleTitle . '_delivery'];
$this->zones = $this->model_localisation_zone->getZones(); $this->zones = $this->model_localisation_zone->getZones();
$updatedOrders = array(); $updatedOrders = array();
@ -180,12 +179,13 @@ class ModelExtensionRetailcrmHistoryV3 extends Model
$paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']); $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_country_id'] = isset($paymentCountry) ? $paymentCountry['country_id'] : 0;
$data['payment_zone_id'] = $payment_zone_id; $data['payment_zone_id'] = $payment_zone_id;
$data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : 0; $data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : 0;
$data['shipping_zone_id'] = $shipping_zone_id; $data['shipping_zone_id'] = $shipping_zone_id;
$data['shipping_address'] = '0'; $data['shipping_address'] = '0';
$data['shipping_firstname'] = $order['firstName']; $data['shipping_firstname'] = $order['firstName'];
$data['shipping_lastname'] = isset($order['lastName']) ? $order['lastName'] : $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_company_id'] = '';
$data['shipping_city'] = $order['delivery']['address']['city']; $data['shipping_city'] = $order['delivery']['address']['city'];
$data['shipping_postcode'] = $order['delivery']['address']['index']; $data['shipping_postcode'] = $order['delivery']['address']['index'];
$data['shipping'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default;
$data['shipping'] = $this->delivery[$order['delivery']['code']];
$data['shipping_method'] = $this->ocDelivery[$data['shipping']]; $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;
$data['payment'] = $payment != null ? $this->payment[$payment] : $this->payment_default;
$data['payment'] = $this->payment[$order['paymentType']];
$data['payment_method'] = $this->ocPayment[$data['payment']]; $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 // this data will not retrive from crm for now
$data['tax'] = ''; $data['tax'] = '';
@ -428,6 +426,9 @@ class ModelExtensionRetailcrmHistoryV3 extends Model
$paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']); $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_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : 0;
$data['payment_zone_id'] = $payment_zone_id; $data['payment_zone_id'] = $payment_zone_id;
$data['shipping_country_id'] = $shippingCountry ? $shippingCountry['country_id'] : 0; $data['shipping_country_id'] = $shippingCountry ? $shippingCountry['country_id'] : 0;
@ -441,13 +442,12 @@ class ModelExtensionRetailcrmHistoryV3 extends Model
$data['shipping_company_id'] = ''; $data['shipping_company_id'] = '';
$data['shipping_city'] = $order['delivery']['address']['city']; $data['shipping_city'] = $order['delivery']['address']['city'];
$data['shipping_postcode'] = $order['delivery']['address']['index']; $data['shipping_postcode'] = $order['delivery']['address']['index'];
$data['shipping'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default;
$data['shipping'] = $this->delivery[$order['delivery']['code']];
$data['shipping_method'] = $this->ocDelivery[$data['shipping']]; $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;
$data['payment'] = $this->payment[$order['paymentType']]; $data['payment'] = $payment != null ? $this->payment[$payment] : $this->payment_default;
$data['payment_method'] = $this->ocPayment[$data['payment']]; $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 // this data will not retrive from crm for now
$data['tax'] = ''; $data['tax'] = '';

View File

@ -5,6 +5,7 @@ class ModelExtensionRetailcrmHistoryV45 extends Model
protected $createResult; protected $createResult;
private $opencartApiClient; private $opencartApiClient;
private $customFieldSetting;
public function request() public function request()
{ {
@ -82,7 +83,8 @@ class ModelExtensionRetailcrmHistoryV45 extends Model
$this->delivery = array_flip($settings[$this->moduleTitle . '_delivery']); $this->delivery = array_flip($settings[$this->moduleTitle . '_delivery']);
$this->payment = array_flip($settings[$this->moduleTitle . '_payment']); $this->payment = array_flip($settings[$this->moduleTitle . '_payment']);
$this->status = array_flip($settings[$this->moduleTitle . '_status']); $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 $this->ocPayment = $this->model_extension_retailcrm_references
->getOpercartPaymentTypes(); ->getOpercartPaymentTypes();
@ -90,6 +92,10 @@ class ModelExtensionRetailcrmHistoryV45 extends Model
$this->zones = $this->model_localisation_zone->getZones(); $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(); $updatedOrders = array();
$newOrders = array(); $newOrders = array();
@ -163,7 +169,7 @@ class ModelExtensionRetailcrmHistoryV45 extends Model
foreach ($orders as $order) { foreach ($orders as $order) {
$store = $this->config->get('config_store_id'); $store = $this->config->get('config_store_id');
if (isset($order['payments'])) { if ($order['payments']) {
foreach ($order['payments'] as $orderPayment) { foreach ($order['payments'] as $orderPayment) {
if (isset($orderPayment['externalId'])) { if (isset($orderPayment['externalId'])) {
$payment = $orderPayment; $payment = $orderPayment;
@ -240,6 +246,7 @@ class ModelExtensionRetailcrmHistoryV45 extends Model
$paymentCountry = $this->getCountryByIsoCode($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_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : 0;
$data['payment_zone_id'] = $payment_zone_id; $data['payment_zone_id'] = $payment_zone_id;
$data['shipping_country_id'] = $shippingCountry ? $shippingCountry['country_id'] : 0; $data['shipping_country_id'] = $shippingCountry ? $shippingCountry['country_id'] : 0;
@ -253,9 +260,9 @@ class ModelExtensionRetailcrmHistoryV45 extends Model
$data['shipping_company_id'] = ''; $data['shipping_company_id'] = '';
$data['shipping_city'] = $order['delivery']['address']['city']; $data['shipping_city'] = $order['delivery']['address']['city'];
$data['shipping_postcode'] = $order['delivery']['address']['index']; $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_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)) { if (isset($payment)) {
$data['payment'] = $this->payment[$payment['type']]; $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; $deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0;
if(isset($order['discount']) && $order['discount'] > 0) { if(isset($order['discount']) && $order['discount'] > 0) {
@ -377,7 +395,7 @@ class ModelExtensionRetailcrmHistoryV45 extends Model
foreach ($orders as $order) { foreach ($orders as $order) {
$store = $this->config->get('config_store_id'); $store = $this->config->get('config_store_id');
if (isset($order['payments'])) { if ($order['payments']) {
$payment = end($order['payments']); $payment = end($order['payments']);
} elseif (isset($order['paymentType'])) { } elseif (isset($order['paymentType'])) {
$payment['type'] = $order['paymentType']; $payment['type'] = $order['paymentType'];
@ -498,6 +516,7 @@ class ModelExtensionRetailcrmHistoryV45 extends Model
$paymentCountry = $this->getCountryByIsoCode($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_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : 0;
$data['payment_zone_id'] = $payment_zone_id; $data['payment_zone_id'] = $payment_zone_id;
$data['shipping_country_id'] = $shippingCountry ? $shippingCountry['country_id'] : 0; $data['shipping_country_id'] = $shippingCountry ? $shippingCountry['country_id'] : 0;
@ -511,15 +530,18 @@ class ModelExtensionRetailcrmHistoryV45 extends Model
$data['shipping_company_id'] = ''; $data['shipping_company_id'] = '';
$data['shipping_city'] = $order['delivery']['address']['city']; $data['shipping_city'] = $order['delivery']['address']['city'];
$data['shipping_postcode'] = $order['delivery']['address']['index']; $data['shipping_postcode'] = $order['delivery']['address']['index'];
$data['shipping'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default;
$data['shipping'] = $this->delivery[$order['delivery']['code']];
$data['shipping_method'] = $this->ocDelivery[$data['shipping']]; $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)) { if (isset($payment)) {
$data['payment'] = $this->payment[$payment['type']]; $data['payment'] = $this->payment[$payment['type']];
$data['payment_method'] = $this->ocPayment[$data['payment']]; $data['payment_method'] = $this->ocPayment[$data['payment']];
$data['payment_code'] = $this->payment[$payment['type']]; $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 // 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; $deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0;
$data['order_total'] = array( $data['order_total'] = array(
@ -614,12 +647,6 @@ class ModelExtensionRetailcrmHistoryV45 extends Model
protected function updateCustomers($customers) 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) { foreach ($customers as $customer) {
$customer_id = $customer['externalId']; $customer_id = $customer['externalId'];
@ -656,10 +683,11 @@ class ModelExtensionRetailcrmHistoryV45 extends Model
$customerData['address'] = array($customerAddress); $customerData['address'] = array($customerAddress);
if ($settings && $customer['customFields']) { if (isset($this->customFieldSetting) && $customer['customFields']) {
foreach ($customer['customFields'] as $code => $value) { foreach ($customer['customFields'] as $code => $value) {
if (array_key_exists($code, $settings)) { if (array_key_exists($code, $this->customFieldSetting)) {
$customFields[$settings[$code]] = $value; $fieldCode = str_replace('c_', '', $this->customFieldSetting[$code]);
$customFields[$fieldCode] = $value;
} }
} }

View File

@ -172,6 +172,20 @@ class ModelExtensionRetailcrmOrder extends Model {
$order['items'][] = $item; $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; return $order;
} }

View File

@ -45,7 +45,7 @@ class ModelExtensionRetailcrmReferences extends Model
{ {
return array( return array(
'opencart' => $this->getOpencartCustomFields(), 'opencart' => $this->getOpencartCustomFields(),
'retailcrm' => $this->getApiCustomerCustomFields() 'retailcrm' => $this->getApiCustomFields()
); );
} }
@ -119,14 +119,21 @@ class ModelExtensionRetailcrmReferences extends Model
return (!$response->isSuccessful()) ? array() : $response->paymentTypes; return (!$response->isSuccessful()) ? array() : $response->paymentTypes;
} }
public function getApiCustomerCustomFields() public function getApiCustomFields()
{ {
$this->initApi(); $this->initApi();
$filter = array('entity' => 'customer'); $customers = $this->retailcrm->customFieldsList(array('entity' => 'customer'));
$response = $this->retailcrm->customFieldsList($filter); $orders = $this->retailcrm->customFieldsList(array('entity' => 'order'));
return (!$response->isSuccessful()) ? array() : $response->customFields; $customFieldsCustomers = (!$customers->isSuccessful()) ? array() : $customers->customFields;
$customFieldsOrders = (!$orders->isSuccessful()) ? array() : $orders->customFields;
if (!$customFieldsCustomers && !$customFieldsOrders) {
return array();
}
return array('customers' => $customFieldsCustomers, 'orders' => $customFieldsOrders);
} }
protected function initApi() protected function initApi()

View File

@ -149,7 +149,32 @@
<label for="retailcrm_payment_<?php echo $key; ?>"><?php echo $value; ?></label> <label for="retailcrm_payment_<?php echo $key; ?>"><?php echo $value; ?></label>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
<h4><?php echo $retailcrm_dict_default; ?></h4>
<div class="retailcrm_unit">
<select id="retailcrm_default_payment" name="retailcrm_default_payment" >
<?php foreach ($payments['opencart'] as $k => $v): ?>
<option value="<?php echo $k;?>" <?php if(isset($saved_settings['retailcrm_default_payment']) && $k == $saved_settings['retailcrm_default_payment']):?>selected="selected"<?php endif;?>>
<?php echo $v;?>
</option>
<?php endforeach; ?>
</select>
<label for="retailcrm_default_payment"><?php echo $text_payment; ?></label>
</div>
<div class="retailcrm_unit">
<select id="retailcrm_default_shipping" name="retailcrm_default_shipping" >
<?php foreach ($delivery['opencart'] as $key => $value): ?>
<optgroup label="<?php echo $value['title']; ?>">
<?php unset($value['title']); ?>
<?php foreach ($value as $v): ?>
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_default_shipping']) && $v['code'] == $saved_settings['retailcrm_default_shipping']):?>selected="selected"<?php endif;?>>
<?php echo $v['title'];?>
</option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
</select>
<label for="retailcrm_default_payment"><?php echo $text_shipping; ?></label>
</div>
<?php endif; ?> <?php endif; ?>
<?php endif; ?> <?php endif; ?>
@ -176,8 +201,6 @@
<label for="retailcrm_collector" class="col-md-4"><?php echo $collector_site_key; ?></label> <label for="retailcrm_collector" class="col-md-4"><?php echo $collector_site_key; ?></label>
<input id="retailcrm_collector_site_key" type="text" name="retailcrm_collector[site_key]" value="<?php if (isset($saved_settings['retailcrm_collector']['site_key'])): echo $saved_settings['retailcrm_collector']['site_key']; endif; ?>"> <input id="retailcrm_collector_site_key" type="text" name="retailcrm_collector[site_key]" value="<?php if (isset($saved_settings['retailcrm_collector']['site_key'])): echo $saved_settings['retailcrm_collector']['site_key']; endif; ?>">
</div> </div>
<?php if (!empty($saved_settings['retailcrm_collector']['site_key']) &&
$saved_settings['retailcrm_collector_active'] == 1) :?>
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4"><?php echo $text_collector_form_capture; ?></label> <label for="retailcrm_collector" class="col-md-4"><?php echo $text_collector_form_capture; ?></label>
<label class="radio-inline"> <label class="radio-inline">
@ -193,8 +216,6 @@
<?php echo $text_no; ?> <?php echo $text_no; ?>
</label> </label>
</div> </div>
<?php if (isset($saved_settings['retailcrm_collector']['form_capture']) &&
$saved_settings['retailcrm_collector']['form_capture'] == 1) :?>
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4"><?php echo $text_collector_period; ?></label> <label for="retailcrm_collector" class="col-md-4"><?php echo $text_collector_period; ?></label>
<input id="retailcrm_collector_period" type="text" name="retailcrm_collector[period]" value="<?php if (isset($saved_settings['retailcrm_collector']['period'])): echo $saved_settings['retailcrm_collector']['period']; endif; ?>"> <input id="retailcrm_collector_period" type="text" name="retailcrm_collector[period]" value="<?php if (isset($saved_settings['retailcrm_collector']['period'])): echo $saved_settings['retailcrm_collector']['period']; endif; ?>">
@ -222,8 +243,6 @@
<?php echo $text_no; ?> <?php echo $text_no; ?>
</label> </label>
</div> </div>
<?php if (isset($saved_settings['retailcrm_collector']['custom_form']) &&
$saved_settings['retailcrm_collector']['custom_form'] == 1) :?>
<?php foreach ($collectorFields as $field => $label) : ?> <?php foreach ($collectorFields as $field => $label) : ?>
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4"><?php echo $label; ?></label> <label for="retailcrm_collector" class="col-md-4"><?php echo $label; ?></label>
@ -234,19 +253,46 @@
</div> </div>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</div> </div>
<?php if (isset($saved_settings['retailcrm_apiversion']) && $saved_settings['retailcrm_apiversion'] == 'v5' && isset($customFields)) : ?> <?php if (isset($saved_settings['retailcrm_apiversion']) && $saved_settings['retailcrm_apiversion'] == 'v5' && isset($customFields)) : ?>
<div class="tab-pane" id="tab-custom_fields"> <div class="tab-pane" id="tab-custom_fields">
<h4><?php echo $retailcrm_dict_custom_fields; ?></h4> <h3><?php echo $retailcrm_dict_custom_fields; ?></h3>
<?php if ($customFields['retailcrm'] && $customFields['opencart']) : ?> <?php if ($customFields['retailcrm'] && $customFields['opencart']) : ?>
<div class="retailcrm_unit">
<label for="retailcrm_custom_field_active"><?php echo $text_custom_field_activity; ?></label>
<label class="radio-inline">
<input type="radio" name="retailcrm_custom_field_active" value="1" <?php if (isset($saved_settings['retailcrm_custom_field_active']) &&
$saved_settings['retailcrm_custom_field_active'] == 1) :
echo 'checked'; endif; ?>>
<?php echo $text_yes; ?>
</label>
<label class="radio-inline">
<input type="radio" name="retailcrm_custom_field_active" value="0" <?php if (!isset($saved_settings['retailcrm_custom_field_active']) ||
$saved_settings['retailcrm_custom_field_active'] == 0) :
echo 'checked'; endif; ?>>
<?php echo $text_no; ?>
</label>
</div>
<h4><?php echo $text_customers_custom_fields; ?></h4>
<?php foreach ($customFields['opencart'] as $customField) : ?> <?php foreach ($customFields['opencart'] as $customField) : ?>
<?php $fid = $customField['custom_field_id'] ?> <?php $fid = 'c_' . $customField['custom_field_id'] ?>
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<select id="retailcrm_custom_field_<?php echo $fid; ?>" name="retailcrm_custom_field[<?php echo $fid; ?>]" > <select id="retailcrm_custom_field_<?php echo $fid; ?>" name="retailcrm_custom_field[<?php echo $fid; ?>]" >
<?php foreach ($customFields['retailcrm'] as $v): ?> <?php foreach ($customFields['retailcrm']['customers'] as $v): ?>
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_custom_field'][$fid]) && $v['code'] == $saved_settings['retailcrm_custom_field'][$fid]):?>selected="selected"<?php endif;?>>
<?php echo $v['name'];?>
</option>
<?php endforeach; ?>
</select>
<label for="retailcrm_custom_field_<?php echo $fid; ?>"><?php echo $customField['name']; ?></label>
</div>
<?php endforeach; ?>
<h4><?php echo $text_orders_custom_fields; ?></h4>
<?php foreach ($customFields['opencart'] as $customField) : ?>
<?php $fid = 'o_' . $customField['custom_field_id'] ?>
<div class="retailcrm_unit">
<select id="retailcrm_custom_field_<?php echo $fid; ?>" name="retailcrm_custom_field[<?php echo $fid; ?>]" >
<?php foreach ($customFields['retailcrm']['orders'] as $v): ?>
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_custom_field'][$fid]) && $v['code'] == $saved_settings['retailcrm_custom_field'][$fid]):?>selected="selected"<?php endif;?>> <option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_custom_field'][$fid]) && $v['code'] == $saved_settings['retailcrm_custom_field'][$fid]):?>selected="selected"<?php endif;?>>
<?php echo $v['name'];?> <?php echo $v['name'];?>
</option> </option>

View File

@ -42,6 +42,9 @@
{% if saved_settings.module_retailcrm_apikey is defined and saved_settings.module_retailcrm_apikey and saved_settings.module_retailcrm_url is defined and saved_settings.module_retailcrm_url %} {% if saved_settings.module_retailcrm_apikey is defined and saved_settings.module_retailcrm_apikey and saved_settings.module_retailcrm_url is defined and saved_settings.module_retailcrm_url %}
<li><a href="#tab-references" data-toggle="tab">{{ references_tab_text }}</a></li> <li><a href="#tab-references" data-toggle="tab">{{ references_tab_text }}</a></li>
<li><a href="#tab-collector" data-toggle="tab">{{ collector_tab_text }}</a></li> <li><a href="#tab-collector" data-toggle="tab">{{ collector_tab_text }}</a></li>
{% if saved_settings.module_retailcrm_apiversion == 'v5' %}
<li><a href="#tab-custom_fields" data-toggle="tab"> {{ custom_fields_tab_text }} </a></li>
{% endif %}
{% endif %} {% endif %}
</ul> </ul>
@ -107,15 +110,15 @@
{% if key != 'title' %} {% if key != 'title' %}
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<select id="retailcrm_delivery_{{ val.code }}" name="module_retailcrm_delivery[{{ val.code }}]" > <select id="retailcrm_delivery_{{ val.code }}" name="module_retailcrm_delivery[{{ val.code }}]" >
{% for k, v in delivery.retailcrm %} {% for k, v in delivery.retailcrm %}
<option value="{{ v.code }}" {% if saved_settings.module_retailcrm_delivery[key] is defined and v.code == saved_settings.module_retailcrm_delivery[key] %} selected="selected" {% endif %}> <option value="{{ v.code }}" {% if saved_settings.module_retailcrm_delivery[key] is defined and v.code == saved_settings.module_retailcrm_delivery[key] %} selected="selected" {% endif %}>
{{ v.name }} {{ v.name }}
</option> </option>
{% endfor %} {% endfor %}
</select> </select>
<label for="retailcrm_pm_{{ val.code }}">{{ val.title }}</label> <label for="retailcrm_pm_{{ val.code }}">{{ val.title }}</label>
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
@ -147,7 +150,33 @@
<label for="retailcrm_payment_{{ key }}">{{ value }}</label> <label for="retailcrm_payment_{{ key }}">{{ value }}</label>
</div> </div>
{% endfor %} {% endfor %}
<h4>{{ retailcrm_dict_default }}</h4>
<div class="retailcrm_unit">
<select id="retailcrm_default_payment" name="retailcrm_default_payment" >
{% for k, v in payments.opencart %}
<option value="{{ k }}" {% if saved_settings.retailcrm_default_payment is defined and k == saved_settings.retailcrm_default_payment %} selected="selected" {% endif %}>
{{ v }}
</option>
{% endfor %}
</select>
<label for="retailcrm_default_payment">{{ text_payment }}</label>
</div>
<div class="retailcrm_unit">
<select id="retailcrm_default_shipping" name="retailcrm_default_shipping" >
{% for key, value in delivery.opencart %}
<optgroup label="{{ value.title }}">
{% for k, v in value %}
{% if k != 'title' %}
<option value="{{ v.code }}" {% if saved_settings.retailcrm_default_shipping is defined and v.code == saved_settings.retailcrm_default_shipping %} selected="selected" {% endif %}>
{{ v.title }}
</option>
{% endif %}
{% endfor %}
</optgroup>
{% endfor %}
</select>
<label for="retailcrm_default_payment">{{ text_shipping }}</label>
</div>
{% endif %} {% endif %}
{% endif %} {% endif %}
@ -174,8 +203,6 @@
<label for="retailcrm_collector" class="col-md-4">{{ collector_site_key }}</label> <label for="retailcrm_collector" class="col-md-4">{{ collector_site_key }}</label>
<input id="retailcrm_collector_site_key" type="text" name="module_retailcrm_collector[site_key]" value="{% if saved_settings.module_retailcrm_collector.site_key is defined %}{{ saved_settings.module_retailcrm_collector.site_key }}{% endif %}"> <input id="retailcrm_collector_site_key" type="text" name="module_retailcrm_collector[site_key]" value="{% if saved_settings.module_retailcrm_collector.site_key is defined %}{{ saved_settings.module_retailcrm_collector.site_key }}{% endif %}">
</div> </div>
{% if saved_settings.module_retailcrm_collector.site_key is not empty and
saved_settings.module_retailcrm_collector_active == 1 %}
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4">{{ text_collector_form_capture }}</label> <label for="retailcrm_collector" class="col-md-4">{{ text_collector_form_capture }}</label>
<label class="radio-inline"> <label class="radio-inline">
@ -191,22 +218,20 @@
{{ text_no }} {{ text_no }}
</label> </label>
</div> </div>
{% if saved_settings.module_retailcrm_collector.form_capture is defined and
saved_settings.module_retailcrm_collector.form_capture == 1 %}
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4">{{ text_collector_period }}</label> <label for="module_retailcrm_collector" class="col-md-4">{{ text_collector_period }}</label>
<input id="retailcrm_collector_period" type="text" name="module_retailcrm_collector[period]" value="{% if saved_settings.module_retailcrm_collector.period is defined %}{{ saved_settings.module_retailcrm_collector.period }}{% endif %}"> <input id="module_retailcrm_collector_period" type="text" name="module_retailcrm_collector[period]" value="{% if saved_settings.module_retailcrm_collector.period is defined %}{{ saved_settings.module_retailcrm_collector.period }}{% endif %}">
</div> </div>
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4">{{ text_label_promo }}</label> <label for="module_retailcrm_collector" class="col-md-4">{{ text_label_promo }}</label>
<input id="retailcrm_collector[]" type="text" name="module_retailcrm_collector[label_promo]" value="{% if saved_settings.module_retailcrm_collector.label_promo is defined %}{{ saved_settings.module_retailcrm_collector.label_promo }}{% endif %}"> <input id="module_retailcrm_collector[]" type="text" name="module_retailcrm_collector[label_promo]" value="{% if saved_settings.module_retailcrm_collector.label_promo is defined %}{{ saved_settings.module_retailcrm_collector.label_promo }}{% endif %}">
</div> </div>
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4">{{ text_label_send }}</label> <label for="module_retailcrm_collector" class="col-md-4">{{ text_label_send }}</label>
<input id="retailcrm_collector_label_send" type="text" name="module_retailcrm_collector[label_send]" value="{% if saved_settings.module_retailcrm_collector.label_send is defined %} {{ saved_settings.module_retailcrm_collector.label_send }} {% endif %}"> <input id="module_retailcrm_collector_label_send" type="text" name="module_retailcrm_collector[label_send]" value="{% if saved_settings.module_retailcrm_collector.label_send is defined %}{{ saved_settings.module_retailcrm_collector.label_send }}{% endif %}">
</div> </div>
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4">{{ collector_custom_text }}</label> <label for="module_retailcrm_collector" class="col-md-4">{{ collector_custom_text }}</label>
<label class="radio-inline"> <label class="radio-inline">
<input type="radio" name="module_retailcrm_collector[custom_form]" value="1" {% if saved_settings.module_retailcrm_collector.custom_form is defined and <input type="radio" name="module_retailcrm_collector[custom_form]" value="1" {% if saved_settings.module_retailcrm_collector.custom_form is defined and
saved_settings.module_retailcrm_collector.custom_form == 1 %} {{ 'checked' }} saved_settings.module_retailcrm_collector.custom_form == 1 %} {{ 'checked' }}
@ -214,43 +239,68 @@
{{ text_yes }} {{ text_yes }}
</label> </label>
<label class="radio-inline"> <label class="radio-inline">
<input type="radio" name="module_retailcrm_collector[custom_form]" value="0" {% if saved_settings.module_retailcrm_collector.custom_form is defined or <input type="radio" name="module_retailcrm_collector[custom_form]" value="0" {% if saved_settings.module_retailcrm_collector.custom_form is not defined or
saved_settings.module_retailcrm_collector.custom_form == 0 %} {{ 'checked' }} saved_settings.module_retailcrm_collector.custom_form == 0 %} {{ 'checked' }}
{% endif %}> {% endif %}>
{{ text_no }} {{ text_no }}
</label> </label>
</div> </div>
{% if saved_settings.module_retailcrm_collector.custom_form is defined and
saved_settings.module_retailcrm_collector.custom_form == 1 %}
{% for field, label in collectorFields %} {% for field, label in collectorFields %}
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4">{{ label }}</label> <label for="retailcrm_collector" class="col-md-4">{{ label }}</label>
<div class="col-md-8"> <div class="col-md-8">
{# <input id="retailcrm_collector" type="text" name="module_retailcrm_collector[custom][{{ field }}]" value="{% if saved_settings.module_retailcrm_collector.custom.{{ field }} is defined %} {{ saved_settings.module_retailcrm_collector.custom.{{ field }} {% endif %}"> #} <input id="module_retailcrm_collector" type="text" name="module_retailcrm_collector[custom][{{ field }}]" value="{% if saved_settings.module_retailcrm_collector.custom[field] is defined %} {{ saved_settings.module_retailcrm_collector.custom[field] }} {% endif %}">
<input type="checkbox" name="module_retailcrm_collector[require][{{ field }}_require]" value="1" {% if saved_settings.module_retailcrm_collector.require.field ~'_require' %} {{ 'checked' }} {% endif %}> <input type="checkbox" name="module_retailcrm_collector[require][{{ field }}_require]" value="1" {% if saved_settings.module_retailcrm_collector.require[field ~'_require'] %} checked {% endif %}>
<label for="retailcrm_collector">{{ text_require }}</label> <label for="retailcrm_collector">{{ text_require }}</label>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
{% endif %}
{% endif %}
{% endif %}
</div> </div>
{% 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 %}
<div class="tab-pane" id="tab-custom_fields"> <div class="tab-pane" id="tab-custom_fields">
<h4>{{ retailcrm_dict_custom_fields }}</h4> <h4>{{ retailcrm_dict_custom_fields }}</h4>
{% if customFields.retailcrm is not empty and customFields.opencart is not empty %} {% if customFields.retailcrm is not empty and customFields.opencart is not empty %}
<div class="retailcrm_unit">
<label for="retailcrm_custom_field_active">{{ text_custom_field_activity }}</label>
<label class="radio-inline">
<input type="radio" name="module_retailcrm_custom_field_active" value="1" {% if saved_settings.module_retailcrm_custom_field_active is defined and
saved_settings.module_retailcrm_custom_field_active == 1 %}
checked {% endif %} >
{{ text_yes }}
</label>
<label class="radio-inline">
<input type="radio" name="module_retailcrm_custom_field_active" value="0" {% if saved_settings.module_retailcrm_custom_field_active is not defined or
saved_settings.module_retailcrm_custom_field_active == 0 %}
checked {% endif %} >
{{ text_no }}
</label>
</div>
<h4>{{ text_customers_custom_fields }}</h4>
{% for customField in customFields.opencart %} {% for customField in customFields.opencart %}
{% set fid = customField.custom_field_id %} {% set fid = 'c_' ~ customField.custom_field_id %}
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<select id="retailcrm_custom_field_{{ fid }}" name="retailcrm_custom_field[{{ fid }}]" > <select id="module_retailcrm_custom_field_{{ fid }}" name="module_retailcrm_custom_field[{{ fid }}]" >
{% for v in customFields.retailcrm %} {% for v in customFields.retailcrm.customers %}
<option value="{{ v.code }}" {% if saved_settings.retailcrm_custom_field.fid is defined and v.code == saved_settings.retailcrm_custom_field.fid %} selected="selected" {% endif %}> <option value="{{ v.code }}" {% if saved_settings.module_retailcrm_custom_field[fid] is defined and v.code == saved_settings.module_retailcrm_custom_field[fid] %} selected="selected" {% endif %}>
{{ v.name }} {{ v.name }}
</option> </option>
{% endfor %} {% endfor %}
</select> </select>
<label for="retailcrm_custom_field_{{ fid }}">{{ customField.name }}</label> <label for="module_retailcrm_custom_field_{{ fid }}">{{ customField.name }}</label>
</div>
{% endfor %}
<h4>{{ text_orders_custom_fields }}</h4>
{% for customField in customFields.opencart %}
{% set fid = 'o_' ~ customField.custom_field_id %}
<div class="retailcrm_unit">
<select id="module_retailcrm_custom_field_{{ fid }}" name="module_retailcrm_custom_field[{{ fid }}]" >
{% for v in customFields.retailcrm.orders %}
<option value="{{ v.code }}" {% if saved_settings.module_retailcrm_custom_field[fid] is defined and v.code == saved_settings.module_retailcrm_custom_field[fid] %} selected="selected" {% endif %}>
{{ v.name }}
</option>
{% endfor %}
</select>
<label for="module_retailcrm_custom_field_{{ fid }}">{{ customField.name }}</label>
</div> </div>
{% endfor %} {% endfor %}
{% elseif customFields.retailcrm is empty and customFields.opencart is empty %} {% elseif customFields.retailcrm is empty and customFields.opencart is empty %}

View File

@ -20,7 +20,11 @@ class ControllerExtensionAnalyticsDaemonCollector extends Controller {
$cntEmpty = 0; $cntEmpty = 0;
foreach ($setting['custom'] as $field => $label) { foreach ($setting['custom'] as $field => $label) {
if (empty($label)) { $cntEmpty += 1; continue; } if (empty($label)) {
$cntEmpty += 1;
continue;
}
if (isset($setting['require'][$field . '_require'])) { if (isset($setting['require'][$field . '_require'])) {
$customForm .= "\n\t'$field': { required: true, label: '$label' },"; $customForm .= "\n\t'$field': { required: true, label: '$label' },";
@ -46,7 +50,7 @@ class ControllerExtensionAnalyticsDaemonCollector extends Controller {
});"; });";
} else { } else {
$captureForm = "_rc('require', 'capture-form', { $captureForm = "_rc('require', 'capture-form', {
'period': " . $settings['retailcrm_collector']['period'] . ", 'period': " . $settings[$moduleTitle . '_collector']['period'] . ",
" . $customForm . " " . $customForm . "
});"; });";
} }
@ -67,14 +71,18 @@ class ControllerExtensionAnalyticsDaemonCollector extends Controller {
$captureForm = ""; $captureForm = "";
} }
$js = "<script type=\"text/javascript\"> if (!$customer) {
(function(_,r,e,t,a,i,l){_['retailCRMObject']=a;_[a]=_[a]||function(){(_[a].q=_[a].q||[]).push(arguments)};_[a].l=1*new Date();l=r.getElementsByTagName(e)[0];i=r.createElement(e);i.async=!0;i.src=t;l.parentNode.insertBefore(i,l)})(window,document,'script','https://collector.retailcrm.pro/w.js','_rc'); $initClient = "_rc('create', '" . $siteCode . "');";
} else {
_rc('create', '" . $siteCode . "', { $initClient = "_rc('create', '" . $siteCode . "', {
" . $customer . " " . $customer . "
}); });";
" . $captureForm . " }
_rc('send', 'pageView');
$js = "<script type=\"text/javascript\">
(function(_,r,e,t,a,i,l){_['retailCRMObject']=a;_[a]=_[a]||function(){(_[a].q=_[a].q||[]).push(arguments)};_[a].l=1*new Date();l=r.getElementsByTagName(e)[0];i=r.createElement(e);i.async=!0;i.src=t;l.parentNode.insertBefore(i,l)})(window,document,'script','https://collector.retailcrm.pro/w.js','_rc');"
. $initClient . $captureForm .
"_rc('send', 'pageView');
</script>"; </script>";
return html_entity_decode($js, ENT_QUOTES, 'UTF-8'); return html_entity_decode($js, ENT_QUOTES, 'UTF-8');

View File

@ -55,12 +55,14 @@ class ModelExtensionRetailcrmCustomer extends Model {
$customFields = json_decode($customer['custom_field']); $customFields = json_decode($customer['custom_field']);
foreach ($customFields as $key => $value) { foreach ($customFields as $key => $value) {
if (isset($this->settings[$moduleTitle . '_custom_field'][$key])) { if (isset($this->settings[$moduleTitle . '_custom_field']['c_' . $key])) {
$customFieldsToCrm[$this->settings[$moduleTitle . '_custom_field'][$key]] = $value; $customFieldsToCrm[$this->settings[$moduleTitle . '_custom_field']['c_' . $key]] = $value;
} }
} }
$customerToCrm['customFields'] = $customFieldsToCrm; if (isset($customFieldsToCrm)) {
$customerToCrm['customFields'] = $customFieldsToCrm;
}
} }
return $customerToCrm; return $customerToCrm;

View File

@ -63,10 +63,12 @@ class ModelExtensionRetailcrmOrder extends Model {
if ($this->settings[$this->moduleTitle . '_apiversion'] == 'v5' && $response->isSuccessful()) { if ($this->settings[$this->moduleTitle . '_apiversion'] == 'v5' && $response->isSuccessful()) {
$response_order = $this->retailcrm->ordersGet($order_id); $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) { 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; $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; return $order;

View File

@ -138,8 +138,13 @@ class OpencartApiClient {
'lastname' => $data['lastname'], 'lastname' => $data['lastname'],
'email' => $data['email'], 'email' => $data['email'],
'telephone' => !empty($data['telephone']) ? $data['telephone'] : '0000', '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); $this->request('customer', array(), $customer);
$products = array(); $products = array();

View File

@ -63,7 +63,7 @@
<field id="shipment_date" group="order">shipmentDate</field> <field id="shipment_date" group="order">shipmentDate</field>
<field id="shipped" group="order">shipped</field> <field id="shipped" group="order">shipped</field>
<!--<field id="order_product" group="order">item</field>--> <!--<field id="order_product" group="order">item</field>-->
<field id="payment" group="order">payments</field> <field id="payment" group="order">payment</field>
<field id="payments.amount" group="order">amount</field> <field id="payments.amount" group="order">amount</field>
<field id="payments.paid_at" group="order">paidAt</field> <field id="payments.paid_at" group="order">paidAt</field>
<field id="payments.comment" group="order">comment</field> <field id="payments.comment" group="order">comment</field>