+ * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
+ * @version Release: 1.0.0
+ * @link https://github.com/dmamontov/restnormalizer/
+ * @since Class available since Release 1.0.0
+ */
+
+class RestNormalizer
+{
+ /**
+ * Cleanup of null values
+ * @var boolean
+ * @access public
+ */
+ public $clear = true;
+
+ /**
+ * Sorted file validation
+ * @var array
+ * @access private
+ */
+ private $validation = array();
+
+ /**
+ * File validation
+ * @var array
+ * @access private
+ */
+ private $originalValidation = array();
+
+ /**
+ * Class constructor
+ * @return void
+ * @access public
+ * @final
+ */
+ final public function __construct()
+ {
+ if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
+ date_default_timezone_set(@date_default_timezone_get());
+ }
+ }
+
+ /**
+ * Installation file validation
+ * @param string $file The path to the file validation
+ * @return void
+ * @access public
+ * @final
+ */
+ final public function setValidation($file)
+ {
+ if (is_null($file) || is_file($file) === false
+ || json_decode(file_get_contents($file)) === null
+ || $this->parseConfig($file) === false) {
+ ICrmOrderActions::eventLog('RestNormalizer', 'intaro.intarocrm', 'Incorrect file normalize.');
+ return false;
+ }
+ }
+
+ /**
+ * Parsing the file validation
+ * @param string $file The path to the file validation
+ * @return boolean
+ * @access private
+ * @final
+ */
+ final private function parseConfig($file)
+ {
+ if (json_decode(file_get_contents($file)) !== null) {
+ $this->originalValidation = json_decode(file_get_contents($file), true);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Starting the process of normalization of the data
+ * @param array $data The key is to sort the data validation
+ * @param string $key Data normalization
+ * @return array
+ * @access public
+ * @final
+ */
+ final public function normalize($data, $key = false)
+ {
+ if (is_string($data)) {
+ $data = json_decode($data, true);
+ }
+
+ if (is_string($key) && isset($this->originalValidation[ $key ])) {
+ $this->validation = $this->originalValidation[ $key ];
+ } else {
+ $this->validation = $this->originalValidation;
+ }
+
+ if (!is_array($data) || count($data) < 1) {
+ ICrmOrderActions::eventLog('RestNormalizer', 'intaro.intarocrm', 'Incorrect data array.');
+ return false;
+ }
+
+ return $this->formatting($data);
+ }
+
+ /**
+ * Data formatting
+ * @param array $data The key is to sort the data validation
+ * @param boolean $skip Skip perform methods intended for the first run
+ * @return array
+ * @access private
+ * @final
+ */
+ final private function formatting($data, $skip = false)
+ {
+ $formatted = array();
+
+ foreach ($data as $code => $value) {
+
+ if (isset($this->validation[ $code ]) && $this->validation[ $code ]['type'] == 'skip') {
+ $formatted[ $code ] = $value;
+ }elseif (isset($this->validation[ $code ]) && is_array($value) === false) {
+ $formatted[ $code ] = $this->setFormat($value, $this->validation[ $code ]);
+ } elseif (is_array($value)) {
+ $formatted[ $code ] = $this->formatting($value, true);
+ }
+
+ if ($formatted[ $code ] === null || $formatted[ $code ] == '' || count($formatted[ $code ]) < 1) {
+ if ($this->clear === true) {
+ unset($formatted[ $code ]);
+ }
+
+ if (isset($this->validation[ $code ]['required']) && $this->validation[ $code ]['required'] === true) {
+ $formatted = array();
+ break;
+ }
+ }
+
+ }
+
+ if ($skip === false) {
+ foreach ($this->validation as $code => $valid) {
+ if (isset($valid['required']) && $valid['required'] === true && isset($formatted[ $code ]) === false) {
+ ICrmOrderActions::eventLog('RestNormalizer', 'intaro.intarocrm', "NOT VALID: $code");
+ }
+ }
+
+ $formatted = $this->multiConvert($formatted);
+ }
+
+ return count($formatted) < 1 ? false : $formatted;
+ }
+
+ /**
+ * Formatting data depending on the type
+ * @param mixed $data The value to be formatted
+ * @param array $validation The data for the current data type validation
+ * @return mixed
+ * @access private
+ * @final
+ */
+ final private function setFormat($data, $validation)
+ {
+ $format = null;
+
+ switch ($validation['type']) {
+ case 'string':
+ $format = $this->setString($data, $validation);
+ break;
+ case 'int':
+ $format = $this->setInt($data, $validation);
+ break;
+ case 'double':
+ $format = $this->setDouble($data, $validation);
+ break;
+ case 'bool':
+ $format = $this->setBool($data, $validation);
+ break;
+ case 'datetime':
+ $format = $this->setDateTime($data, $validation);
+ break;
+ case 'enum':
+ $format = $this->setEnum($data, $validation);
+ break;
+ }
+
+ return $format;
+ }
+
+ /**
+ * Formatting data for strings
+ * @param string $data String to formatting
+ * @param array $validation The data for the current data type validation
+ * @return string
+ * @access private
+ * @final
+ */
+ final private function setString($data, $validation)
+ {
+ $data = trim((string) $data);
+
+ if (isset($validation['default']) && is_string($validation['default']) && trim($validation['default']) != ''
+ && ($data == '' || is_string($data) === false)) {
+ $data = trim($validation['default']);
+ } elseif ($data == '' || is_string($data) === false) {
+ return null;
+ } elseif (isset($validation['min']) && mb_strlen($data) < $validation['min']) {
+ $pad = isset($validation['pad']) && mb_strlen($validation['pad']) == 1 ? $validation['pad'] : ' ';
+ $data .= str_repeat($pad, $validation['min'] - mb_strlen($data));
+ }elseif (isset($validation['max']) && mb_strlen($data) > $validation['max']) {
+ $data = mb_substr($data, 0, $validation['max']);
+ }
+
+ return (string) $data;
+ }
+
+ /**
+ * Formatting data for integers
+ * @param integer $data Integer to formatting
+ * @param array $validation The data for the current data type validation
+ * @return integer
+ * @access private
+ * @final
+ */
+ final private function setInt($data, $validation)
+ {
+ if (isset($validation['default']) && is_numeric($validation['default']) && is_numeric($data) === false) {
+ $data = $validation['default'];
+ } elseif (is_numeric($data) === false) {
+ return null;
+ } elseif (isset($validation['min']) && $data < $validation['min']) {
+ $data += $validation['min'] - $data;
+ } elseif (isset($validation['max']) && $data > $validation['max']) {
+ $data -= $data - $validation['max'];
+ }
+
+ return (int) $data;
+ }
+
+ /**
+ * Formatting data for floating-point numbers
+ * @param float $data Floating-point number to formatting
+ * @param array $validation The data for the current data type validation
+ * @return float
+ * @access private
+ * @final
+ */
+ final private function setDouble($data, $validation)
+ {
+ if (isset($validation['default']) && is_numeric($validation['default']) && is_numeric($data) === false) {
+ $data = $validation['default'];
+ } elseif (is_numeric($data) === false) {
+ return null;
+ } elseif (isset($validation['min']) && $data < $validation['min']) {
+ $data += $validation['min'] - $data;
+ } elseif (isset($validation['max']) && $data > $validation['max']) {
+ $data -= $data - $validation['max'];
+ }
+
+ if (isset($validation['decimals'])) {
+ $data = number_format($data, $validation['decimals'], '.', '');
+ }
+
+ return (double) $data;
+ }
+
+ /**
+ * Formatting data for logical values
+ * @param boolean $data Boolean value to formatting
+ * @param array $validation The data for the current data type validation
+ * @return boolean
+ * @access private
+ * @final
+ */
+ final private function setBool($data, $validation)
+ {
+ if (isset($validation['default']) && is_bool($validation['default']) && is_bool($data) === false) {
+ $data = $validation['default'];
+ } elseif (is_bool($data) === false) {
+ return null;
+ }
+
+ return (bool) $data;
+ }
+
+ /**
+ * Formatting data for date and time
+ * @param mixed $data Date and time of to formatting
+ * @param array $validation The data for the current data type validation
+ * @param boolean $skip Skip perform methods intended for the first run
+ * @return mixed
+ * @access private
+ * @final
+ */
+ final private function setDateTime($data, $validation, $skip = false)
+ {
+ if (is_a($data, 'DateTime') && isset($validation['format'])) {
+ $data = (string) $data->format($validation['format']);
+ } elseif (is_string($data) && isset($validation['format']) && strtotime($data) !== false) {
+ $data = (string) date($validation['format'], strtotime($data));
+ } elseif (is_numeric($data) && isset($validation['format'])) {
+ $data = (string) date($validation['format'], (int) $data);
+ } elseif (is_numeric($data)) {
+ $data = (int) $data;
+ } elseif (isset($validation['format'])) {
+ $data = (string) date($validation['format']);
+ } elseif (isset($validation['default']) && $skip === false) {
+ $data = $this->setDateTime(time(), $validation, true);
+ } else {
+ return null;
+ }
+
+ return $data;
+ }
+
+ /**
+ * Formatting data for enum
+ * @param string $data Enum to formatting
+ * @param array $validation The data for the current data type validation
+ * @return string
+ * @access private
+ * @final
+ */
+ final private function setEnum($data, $validation)
+ {
+ if (isset($validation['values']) === false || count($validation['values']) < 1) {
+ return null;
+ } elseif (isset($validation['default']) && in_array($validation['default'], $validation['values']) === false) {
+ return null;
+ } elseif (in_array($data, $validation['values']) === false
+ && isset($validation['default']) && in_array($validation['default'], $validation['values'])) {
+ $data = $validation['default'];
+ } elseif (in_array($data, $validation['values']) === false) {
+ return null;
+ }
+
+ return $data;
+ }
+
+ /**
+ * Installing the specified encoding
+ * @param array $data The original dataset
+ * @return array
+ * @access private
+ * @final
+ */
+ final private function multiConvert($data)
+ {
+ global $APPLICATION;
+
+ if (is_array($data)) {
+ foreach ($data as $code => $value) {
+ $data[$APPLICATION->ConvertCharset($code, SITE_CHARSET, 'utf-8')] = is_array($value)
+ ? $this->multiConvert($value)
+ : $APPLICATION->ConvertCharset($value, SITE_CHARSET, 'utf-8');
+ }
+ return $data;
+ } else {
+ return $APPLICATION->ConvertCharset($data, SITE_CHARSET, 'utf-8');
+ }
+
+ return $data;
+ }
+}
+?>
\ No newline at end of file
diff --git a/intaro.intarocrm/classes/general/config/options.xml b/intaro.intarocrm/classes/general/config/options.xml
new file mode 100644
index 00000000..95c4ce1f
--- /dev/null
+++ b/intaro.intarocrm/classes/general/config/options.xml
@@ -0,0 +1,41 @@
+
+
+
+ Физ. лицо
+ Юр. лицо
+ ИП
+
+
+ Ф.И.О.
+ Телефон
+ E-mail
+ Адрес (строкой)
+ Город
+ Индекс
+ Улица
+ Строение
+ Квартира
+ Домофон
+ Этаж
+ Подъезд
+ Строение / корпус
+
+ Полное наименование
+ Адрес регистрации (Юридический адрес)
+ ИНН
+ ОКПО
+ БИК
+ Банк
+ Адрес банка
+ Корреспондентский счет
+ Расчетный счет
+
+ КПП
+ ОГРН
+
+ ОГРНИП
+ Номер свидетельства
+ Дата свидетельства
+
+
+
\ No newline at end of file
diff --git a/intaro.intarocrm/classes/general/config/retailcrm.json b/intaro.intarocrm/classes/general/config/retailcrm.json
new file mode 100644
index 00000000..43155083
--- /dev/null
+++ b/intaro.intarocrm/classes/general/config/retailcrm.json
@@ -0,0 +1,379 @@
+{
+ "customers": {
+ "externalId": {
+ "type": "string",
+ "required": true
+ },
+ "firstName": {
+ "type": "string"
+ },
+ "lastName": {
+ "type": "string"
+ },
+ "patronymic": {
+ "type": "string"
+ },
+ "email": {
+ "type": "string"
+ },
+ "number": {
+ "type": "string"
+ },
+ "site": {
+ "type": "string"
+ },
+ "index": {
+ "type": "string"
+ },
+ "country": {
+ "type": "string"
+ },
+ "region": {
+ "type": "string"
+ },
+ "city": {
+ "type": "string"
+ },
+ "street": {
+ "type": "string"
+ },
+ "building": {
+ "type": "string"
+ },
+ "flat": {
+ "type": "string"
+ },
+ "intercomCode": {
+ "type": "string"
+ },
+ "floor": {
+ "type": "int"
+ },
+ "block": {
+ "type": "int"
+ },
+ "house": {
+ "type": "string"
+ },
+ "metro": {
+ "type": "string"
+ },
+ "notes": {
+ "type": "string"
+ },
+ "text": {
+ "type": "string"
+ },
+ "createdAt": {
+ "type": "datetime",
+ "format": "Y-m-d H:i:s"
+ },
+ "vip": {
+ "type": "bool",
+ "default": false
+ },
+ "bad": {
+ "type": "bool",
+ "default": false
+ },
+ "commentary": {
+ "type": "string"
+ },
+ "customFields": {
+ "type": "skip"
+ },
+ "contragentType": {
+ "type": "enum",
+ "default": "individual",
+ "values": ["individual", "legal-entity", "enterpreneur"]
+ },
+ "legalName": {
+ "type": "string"
+ },
+ "legalAddress": {
+ "type": "string"
+ },
+ "INN": {
+ "type": "string"
+ },
+ "OKPO": {
+ "type": "string"
+ },
+ "KPP": {
+ "type": "string"
+ },
+ "OGRN": {
+ "type": "string"
+ },
+ "OGRNIP": {
+ "type": "string"
+ },
+ "certificateNumber": {
+ "type": "string"
+ },
+ "certificateDate": {
+ "type": "datetime",
+ "format": "Y-m-d"
+ },
+ "BIK": {
+ "type": "string"
+ },
+ "bank": {
+ "type": "string"
+ },
+ "bankAddress": {
+ "type": "string"
+ },
+ "corrAccount": {
+ "type": "string"
+ },
+ "bankAccount": {
+ "type": "string"
+ },
+ "managerId": {
+ "type": "int"
+ }
+ },
+ "orders": {
+ "number": {
+ "type": "string"
+ },
+ "externalId": {
+ "type": "string",
+ "required": true
+ },
+ "createdAt": {
+ "type": "datetime",
+ "format": "Y-m-d H:i:s"
+ },
+ "discount": {
+ "type": "double",
+ "default": 0,
+ "min": 0,
+ "decimals": 2
+ },
+ "discountPercent": {
+ "type": "double",
+ "default": 0,
+ "max": 100,
+ "min": 0,
+ "decimals": 2
+ },
+ "mark": {
+ "type": "int",
+ "max": 10,
+ "min": 0
+ },
+ "markDatetime": {
+ "type": "datetime",
+ "format": "Y-m-d H:i:s"
+ },
+ "firstName": {
+ "type": "string"
+ },
+ "lastName": {
+ "type": "string"
+ },
+ "patronymic": {
+ "type": "string"
+ },
+ "phone": {
+ "type": "string"
+ },
+ "additionalPhone": {
+ "type": "string"
+ },
+ "email": {
+ "type": "string"
+ },
+ "site": {
+ "type": "string"
+ },
+ "call": {
+ "type": "bool",
+ "default": false
+ },
+ "expired": {
+ "type": "bool",
+ "default": false
+ },
+ "customerComment": {
+ "type": "string"
+ },
+ "managerComment": {
+ "type": "string"
+ },
+ "paymentDetail": {
+ "type": "string"
+ },
+ "statusComment": {
+ "type": "string"
+ },
+ "customFields": {
+ "type": "skip"
+ },
+ "contragentType": {
+ "type": "enum",
+ "default": "individual",
+ "values": ["individual", "legal-entity", "enterpreneur"]
+ },
+ "legalName": {
+ "type": "string"
+ },
+ "legalAddress": {
+ "type": "string"
+ },
+ "INN": {
+ "type": "string"
+ },
+ "OKPO": {
+ "type": "string"
+ },
+ "KPP": {
+ "type": "string"
+ },
+ "OGRN": {
+ "type": "string"
+ },
+ "OGRNIP": {
+ "type": "string"
+ },
+ "certificateNumber": {
+ "type": "string"
+ },
+ "certificateDate": {
+ "type": "datetime",
+ "format": "Y-m-d"
+ },
+ "BIK": {
+ "type": "string"
+ },
+ "bank": {
+ "type": "string"
+ },
+ "bankAddress": {
+ "type": "string"
+ },
+ "corrAccount": {
+ "type": "string"
+ },
+ "bankAccount": {
+ "type": "string"
+ },
+ "orderType": {
+ "type": "string"
+ },
+ "orderMethod": {
+ "type": "string"
+ },
+ "customerId": {
+ "type": "string"
+ },
+ "managerId": {
+ "type": "int"
+ },
+ "paymentType": {
+ "type": "string"
+ },
+ "paymentStatus": {
+ "type": "string"
+ },
+ "status": {
+ "type": "string"
+ },
+ "sourceId": {
+ "type": "string"
+ },
+ "initialPrice": {
+ "type": "double",
+ "default": 0,
+ "min": 0,
+ "decimals": 2
+ },
+ "quantity": {
+ "type": "double",
+ "default": 1,
+ "min": 1,
+ "decimals": 1
+ },
+ "properties": {
+ "type": "skip"
+ },
+ "productId": {
+ "type": "string"
+ },
+ "productName": {
+ "type": "string"
+ },
+ "comment": {
+ "type": "string"
+ },
+ "purchasePrice": {
+ "type": "double",
+ "default": 0,
+ "min": 0,
+ "decimals": 1
+ },
+ "code": {
+ "type": "string"
+ },
+ "integrationCode": {
+ "type": "string"
+ },
+ "data": {
+ "type": "skip"
+ },
+ "service": {
+ "type": "skip"
+ },
+ "cost": {
+ "type": "string"
+ },
+ "date": {
+ "type": "datetime",
+ "format": "Y-m-d"
+ },
+ "index": {
+ "type": "string"
+ },
+ "country": {
+ "type": "string"
+ },
+ "region": {
+ "type": "string"
+ },
+ "city": {
+ "type": "string"
+ },
+ "street": {
+ "type": "string"
+ },
+ "building": {
+ "type": "string"
+ },
+ "flat": {
+ "type": "string"
+ },
+ "intercomCode": {
+ "type": "string"
+ },
+ "floor": {
+ "type": "int"
+ },
+ "block": {
+ "type": "int"
+ },
+ "house": {
+ "type": "string"
+ },
+ "metro": {
+ "type": "string"
+ },
+ "notes": {
+ "type": "string"
+ },
+ "text": {
+ "type": "string"
+ }
+ }
+}
\ No newline at end of file
diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php
index 0bc1adbf..3fc2b04f 100644
--- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php
+++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php
@@ -14,7 +14,11 @@ class ICrmOrderEvent {
protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
protected static $CRM_ORDER_LAST_ID = 'order_last_id';
protected static $CRM_ORDER_PROPS = 'order_props';
+ protected static $CRM_LEGAL_DETAILS = 'legal_details';
+ protected static $CRM_CUSTOM_FIELDS = 'custom_fields';
+ protected static $CRM_CONTRAGENT_TYPE = 'contragent_type';
protected static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
+ protected static $CRM_SITES_LIST = 'sites_list';
/**
* onBeforeOrderAdd
@@ -54,13 +58,12 @@ class ICrmOrderEvent {
* @param mixed $arFields - Order arFields
*/
function onUpdateOrder($ID, $arFields) {
-
if(isset($GLOBALS['INTARO_CRM_ORDER_ADD']) && $GLOBALS['INTARO_CRM_ORDER_ADD'])
return;
if(isset($GLOBALS['INTARO_CRM_ORDER_RESERVE']) && $GLOBALS['INTARO_CRM_ORDER_RESERVE'])
return;
-
+
if(isset($GLOBALS['INTARO_CRM_FROM_HISTORY']) && $GLOBALS['INTARO_CRM_FROM_HISTORY'])
return;
@@ -125,8 +128,7 @@ class ICrmOrderEvent {
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'catalog', 'module not found');
return true;
}
-
- $GLOBALS['INTARO_CRM_ORDER_ADD'] = false;
+
$GLOBALS['INTARO_CRM_FROM_HISTORY'] = false;
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
@@ -138,21 +140,29 @@ class ICrmOrderEvent {
$optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0));
$optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses
$optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0));
+ $optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
$optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0));
+ $optionsLegalDetails = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_LEGAL_DETAILS, 0));
+ $optionsContragentType = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CONTRAGENT_TYPE, 0));
+ $optionsCustomFields = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CUSTOM_FIELDS, 0));
- $api = new IntaroCrm\RestApi($api_host, $api_key);
+ $api = new RetailCrm\RestApi($api_host, $api_key);
$arParams = ICrmOrderActions::clearArr(array(
- 'optionsOrderTypes' => $optionsOrderTypes,
- 'optionsDelivTypes' => $optionsDelivTypes,
- 'optionsPayTypes' => $optionsPayTypes,
- 'optionsPayStatuses' => $optionsPayStatuses,
- 'optionsPayment' => $optionsPayment,
- 'optionsOrderProps' => $optionsOrderProps
+ 'optionsOrderTypes' => $optionsOrderTypes,
+ 'optionsDelivTypes' => $optionsDelivTypes,
+ 'optionsPayTypes' => $optionsPayTypes,
+ 'optionsPayStatuses' => $optionsPayStatuses,
+ 'optionsPayment' => $optionsPayment,
+ 'optionsOrderProps' => $optionsOrderProps,
+ 'optionsLegalDetails' => $optionsLegalDetails,
+ 'optionsContragentType' => $optionsContragentType,
+ 'optionsSitesList' => $optionsSitesList,
+ 'optionsCustomFields' => $optionsCustomFields
));
-
+
$arOrder = CSaleOrder::GetById($ID);
-
+
if (is_array($arFields) && !empty($arFields)) {
$arFieldsNew = array(
@@ -168,9 +178,13 @@ class ICrmOrderEvent {
$arFieldsNew = array_merge($arFieldsNew, $arFields);
$arOrder = $arFieldsNew;
}
-
- $result = ICrmOrderActions::orderCreate($arOrder, $api, $arParams, true);
-
+ if(count($optionsSitesList)>1){
+ $result = ICrmOrderActions::orderCreate($arOrder, $api, $arParams, true, $optionsSitesList[$arOrder['LID']]);
+ }
+ else{
+ $result = ICrmOrderActions::orderCreate($arOrder, $api, $arParams, true);
+ }
+
if(!$result) {
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'ICrmOrderActions::orderCreate', 'error during creating order');
return false;
@@ -217,7 +231,7 @@ class ICrmOrderEvent {
//saved cat params
$optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses
- $api = new IntaroCrm\RestApi($api_host, $api_key);
+ $api = new RetailCrm\RestApi($api_host, $api_key);
$order = array();
@@ -239,14 +253,9 @@ class ICrmOrderEvent {
try {
$api->orderEdit($order);
- } catch (\IntaroCrm\Exception\ApiException $e) {
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
- 'ICrmOrderEvent::onSaleCancelOrder', 'IntaroCrm\RestApi::orderEdit',
- $e->getCode() . ': ' . $e->getMessage()
- );
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'ICrmOrderEvent::onSaleCancelOrder', 'IntaroCrm\RestApi::orderEdit::CurlException',
+ 'ICrmOrderEvent::onSaleCancelOrder', 'RetailCrm\RestApi::orderEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
}
@@ -291,7 +300,7 @@ class ICrmOrderEvent {
//saved cat params
$optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0));
- $api = new IntaroCrm\RestApi($api_host, $api_key);
+ $api = new RetailCrm\RestApi($api_host, $api_key);
$order = array(
'externalId' => (int) $ID,
@@ -302,14 +311,9 @@ class ICrmOrderEvent {
try {
$api->orderEdit($order);
- } catch (\IntaroCrm\Exception\ApiException $e) {
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
- 'ICrmOrderEvent::onSalePayOrder', 'IntaroCrm\RestApi::orderEdit',
- $e->getCode() . ': ' . $e->getMessage()
- );
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'ICrmOrderEvent::onSalePayOrder', 'IntaroCrm\RestApi::orderEdit::CurlException',
+ 'ICrmOrderEvent::onSalePayOrder', 'RetailCrm\RestApi::orderEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
}
diff --git a/intaro.intarocrm/description.ru b/intaro.intarocrm/description.ru
new file mode 100644
index 00000000..52611166
--- /dev/null
+++ b/intaro.intarocrm/description.ru
@@ -0,0 +1,13 @@
+- API
+- .
+-
+-
+-
+-
+- id
+- $_SERVER['SERVER_NAME']
+-
+-
+-
+-
+-
\ No newline at end of file
diff --git a/intaro.intarocrm/export/export_run.php b/intaro.intarocrm/export/export_run.php
index 160ea9db..983905a2 100644
--- a/intaro.intarocrm/export/export_run.php
+++ b/intaro.intarocrm/export/export_run.php
@@ -10,6 +10,13 @@ if (!CModule::IncludeModule("catalog"))
if (!CModule::IncludeModule("intaro.intarocrm"))
return;
+$rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
+while ($ar = $rsSites->Fetch()){
+ if($ar['DEF'] == 'Y'){
+ $SERVER_NAME = $ar['SERVER_NAME'];//разделить потом с учетом многосайтовости
+ }
+}
+
$iblockProperties = Array(
"article" => "article",
"manufacturer" => "manufacturer",
@@ -69,6 +76,7 @@ $loader->propertiesUnitSKU = $IBLOCK_PROPERTY_UNIT_SKU;
$loader->propertiesProduct = $IBLOCK_PROPERTY_PRODUCT;
$loader->propertiesUnitProduct = $IBLOCK_PROPERTY_UNIT_PRODUCT;
$loader->filename = $SETUP_FILE_NAME;
+$loader->serverName = $SERVER_NAME;
$loader->application = $APPLICATION;
$loader->loadPurchasePrice = $LOAD_PURCHASE_PRICE == 'Y';
$loader->Load();
\ No newline at end of file
diff --git a/intaro.intarocrm/include.php b/intaro.intarocrm/include.php
old mode 100755
new mode 100644
index d836cd19..8d2ce2c0
--- a/intaro.intarocrm/include.php
+++ b/intaro.intarocrm/include.php
@@ -2,11 +2,13 @@
CModule::AddAutoloadClasses(
'intaro.intarocrm', // module name
array (
- 'IntaroCrm\RestApi' => 'classes/general/RestApi.php',
- 'ICrmOrderActions' => 'classes/general/ICrmOrderActions.php',
- 'ICMLLoader' => 'classes/general/ICMLLoader.php',
- 'ICrmOrderEvent' => 'classes/general/events/ICrmOrderEvent.php',
- 'IntaroCrm\Exception\ApiException' => 'classes/general/Exception/ApiException.php',
- 'IntaroCrm\Exception\CurlException' => 'classes/general/Exception/CurlException.php'
+ 'RestNormalizer' => 'classes/general/RestNormalizer.php',
+ 'RetailCrm\RestApi' => 'classes/general/RestApi.php',
+ 'RetailCrm\Response\ApiResponse' => 'classes/general/Response/ApiResponse.php',
+ 'ICrmOrderActions' => 'classes/general/ICrmOrderActions.php',
+ 'ICMLLoader' => 'classes/general/ICMLLoader.php',
+ 'ICrmOrderEvent' => 'classes/general/events/ICrmOrderEvent.php',
+ 'RetailCrm\Exception\InvalidJsonException' => 'classes/general/Exception/InvalidJsonException.php',
+ 'RetailCrm\Exception\CurlException' => 'classes/general/Exception/CurlException.php',
)
);
\ No newline at end of file
diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php
old mode 100755
new mode 100644
index 653541f7..64df00a7
--- a/intaro.intarocrm/install/index.php
+++ b/intaro.intarocrm/install/index.php
@@ -24,6 +24,7 @@ class intaro_intarocrm extends CModule {
var $INTARO_CRM_EXPORT = 'intarocrm';
var $CRM_API_HOST_OPTION = 'api_host';
var $CRM_API_KEY_OPTION = 'api_key';
+ var $CRM_SITES_LIST= 'sites_list';
var $CRM_ORDER_TYPES_ARR = 'order_types_arr';
var $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
var $CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr';
@@ -31,8 +32,10 @@ class intaro_intarocrm extends CModule {
var $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
var $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
var $CRM_ORDER_LAST_ID = 'order_last_id';
- var $CRM_ORDER_SITES = 'sites_ids';
var $CRM_ORDER_PROPS = 'order_props';
+ var $CRM_LEGAL_DETAILS = 'legal_details';
+ var $CRM_CUSTOM_FIELDS = 'custom_fields';
+ var $CRM_CONTRAGENT_TYPE = 'contragent_type';
var $CRM_ORDER_DISCHARGE = 'order_discharge';
var $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
var $CRM_ORDER_HISTORY_DATE = 'order_history_date';
@@ -47,7 +50,7 @@ class intaro_intarocrm extends CModule {
include($path . "/version.php");
$this->MODULE_VERSION = $arModuleVersion["VERSION"];
$this->MODULE_VERSION_DATE = $arModuleVersion["VERSION_DATE"];
- $this->MODULE_NAME = GetMessage('MODULE_NAME');
+ $this->MODULE_NAME = GetMessage('INTARO_MODULE_NAME');
$this->MODULE_DESCRIPTION = GetMessage('MODULE_DESCRIPTION');
$this->PARTNER_NAME = GetMessage('MODULE_PARTNER_NAME');
$this->PARTNER_URI = GetMessage('MODULE_PARTNER_URI');
@@ -73,77 +76,55 @@ class intaro_intarocrm extends CModule {
}
include($this->INSTALL_PATH . '/../classes/general/RestApi.php');
+ include($this->INSTALL_PATH . '/../classes/general/Response/ApiResponse.php');
include($this->INSTALL_PATH . '/../classes/general/ICrmOrderActions.php');
include($this->INSTALL_PATH . '/../classes/general/ICMLLoader.php');
- include($this->INSTALL_PATH . '/../classes/general/Exception/ApiException.php');
+ include($this->INSTALL_PATH . '/../classes/general/Exception/InvalidJsonException.php');
include($this->INSTALL_PATH . '/../classes/general/Exception/CurlException.php');
+ include($this->INSTALL_PATH . '/../classes/general/RestNormalizer.php');
$step = intval($_REQUEST['step']);
- $arResult['orderProps'] = array(
- array(
- 'NAME' => GetMessage('FIO'),
- 'ID' => 'fio'
- ),
- array(
- 'NAME' => GetMessage('PHONE'),
- 'ID' => 'phone'
- ),
- array(
- 'NAME' => GetMessage('EMAIL'),
- 'ID' => 'email'
- ),
- array(
- 'NAME' => GetMessage('ADDRESS'),
- 'ID' => 'text'
- ),
- // address
- /* array(
- 'NAME' => GetMessage('COUNTRY'),
- 'ID' => 'country'
- ),
- array(
- 'NAME' => GetMessage('REGION'),
- 'ID' => 'region'
- ),
- array(
- 'NAME' => GetMessage('CITY'),
- 'ID' => 'city'
- ), */
- array(
- 'NAME' => GetMessage('ZIP'),
- 'ID' => 'index'
- ),
- array(
- 'NAME' => GetMessage('STREET'),
- 'ID' => 'street'
- ),
- array(
- 'NAME' => GetMessage('BUILDING'),
- 'ID' => 'building'
- ),
- array(
- 'NAME' => GetMessage('FLAT'),
- 'ID' => 'flat'
- ),
- array(
- 'NAME' => GetMessage('INTERCOMCODE'),
- 'ID' => 'intercomcode'
- ),
- array(
- 'NAME' => GetMessage('FLOOR'),
- 'ID' => 'floor'
- ),
- array(
- 'NAME' => GetMessage('BLOCK'),
- 'ID' => 'block'
- ),
- array(
- 'NAME' => GetMessage('HOUSE'),
- 'ID' => 'house'
- )
- );
+ if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.intarocrm/classes/general/config/options.xml')) {
+ $options = simplexml_load_file($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.intarocrm/classes/general/config/options.xml');
+ foreach($options->contragents->contragent as $contragent)
+ {
+ $type["NAME"] = $APPLICATION->ConvertCharset((string)$contragent, 'utf-8', SITE_CHARSET);
+ $type["ID"] = (string)$contragent["id"];
+ $arResult['contragentType'][] = $type;
+ unset ($type);
+ }
+ foreach($options->fields->field as $field)
+ {
+ $type["NAME"] = $APPLICATION->ConvertCharset((string)$field, 'utf-8', SITE_CHARSET);
+ $type["ID"] = (string)$field["id"];
+
+ if ($field["group"] == 'custom') {
+ $arResult['customFields'][] = $type;
+ } elseif(!$field["group"]){
+ $arResult['orderProps'][] = $type;
+ } else{
+ $groups = explode(",", (string)$field["group"]);
+ foreach($groups as $group){
+ $type["GROUP"][] = trim($group);
+ }
+ $arResult['legalDetails'][] = $type;
+ }
+ unset($type);
+ }
+ }
+
+ if($step == 11){
+ $arResult['arSites'] = array();
+ $rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
+ while ($ar = $rsSites->Fetch()){
+ $arResult['arSites'][] = $ar;
+ }
+ if(count($arResult['arSites'])<2){
+ $step = 2;
+ }
+ }
if ($step <= 1) {
if (!CModule::IncludeModule("sale")) {
$arResult['errCode'] = 'ERR_SALE';
@@ -158,14 +139,80 @@ class intaro_intarocrm extends CModule {
}
$arResult['arSites'] = array();
- $rsSites = CSite::GetList($by, $sort, array());
+ $rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
while ($ar = $rsSites->Fetch())
$arResult['arSites'][] = $ar;
$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
);
- } else if ($step == 2) {
+ } else if ($step == 11) {
+ //new page
+ if (!CModule::IncludeModule("sale")) {
+ $arResult['errCode'] = 'ERR_SALE';
+ }
+
+ if (!CModule::IncludeModule("iblock")) {
+ $arResult['errCode'] = 'ERR_IBLOCK';
+ }
+
+ if (!CModule::IncludeModule("catalog")) {
+ $arResult['errCode'] = 'ERR_CATALOG';
+ }
+
+ if (isset($arResult['errCode']) && $arResult['errCode']) {
+ $APPLICATION->IncludeAdminFile(
+ GetMessage('MODULE_INSTALL_TITLE'),
+ $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
+ );
+ return;
+ }
+
+ $api_host = htmlspecialchars(trim($_POST[$this->CRM_API_HOST_OPTION]));
+ $api_key = htmlspecialchars(trim($_POST[$this->CRM_API_KEY_OPTION]));
+
+ // form correct url
+ $api_host = parse_url($api_host);
+ if($api_host['scheme'] != 'https') $api_host['scheme'] = 'https';
+ $api_host = $api_host['scheme'] . '://' . $api_host['host'];
+
+ if (!$api_host || !$api_key) {
+ $arResult['errCode'] = 'ERR_FIELDS_API_HOST';
+ $APPLICATION->IncludeAdminFile(
+ GetMessage('MODULE_INSTALL_TITLE'),
+ $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
+ );
+ return;
+ }
+
+ $this->INTARO_CRM_API = new RetailCrm\RestApi($api_host, $api_key);
+ //api key ok and sites list
+ try {
+ $arResult['sitesList'] = $this->INTARO_CRM_API->sitesList()->sites;
+ } catch (\RetailCrm\Exception\CurlException $e) {
+ ICrmOrderActions::eventLog(
+ 'intaro.crm/install/index.php', 'RetailCrm\RestApi::sitesList',
+ $e->getCode() . ': ' . $e->getMessage()
+ );
+
+ $arResult['errCode'] = 'ERR_' . $e->getCode();
+
+ $APPLICATION->IncludeAdminFile(
+ GetMessage('MODULE_INSTALL_TITLE'),
+ $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
+ );
+
+ return;
+ }
+
+ COption::SetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, $api_host);
+ COption::SetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, $api_key);
+
+ $APPLICATION->IncludeAdminFile(
+ GetMessage('MODULE_INSTALL_TITLE'),
+ $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step11.php'
+ );
+ } else if ($step == 2) {//доставки, оплаты, типы заказов
if (!CModule::IncludeModule("sale")) {
$arResult['errCode'] = 'ERR_SALE';
@@ -179,11 +226,6 @@ class intaro_intarocrm extends CModule {
$arResult['errCode'] = 'ERR_CATALOG';
}
- $arResult['arSites'] = array();
- $rsSites = CSite::GetList($by, $sort, array());
- while ($ar = $rsSites->Fetch())
- $arResult['arSites'][] = $ar;
-
if (isset($arResult['errCode']) && $arResult['errCode']) {
$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'),
@@ -191,29 +233,35 @@ class intaro_intarocrm extends CModule {
);
return;
}
-
+
+ $arResult['arSites'] = array();
+ $rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
+ while ($ar = $rsSites->Fetch()){
+ if(!$ar["SERVER_NAME"]){
+ $arResult['errCode'] = 'URL_NOT_FOUND';
+ $APPLICATION->IncludeAdminFile(
+ GetMessage('MODULE_INSTALL_TITLE'),
+ $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
+ );
+ return;
+ }
+ else{
+ $arResult['arSites'][] = $ar;
+ }
+ }
+
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) {
$api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0);
- $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
+ $this->INTARO_CRM_API = new \RetailCrm\RestApi($api_host, $api_key);
//prepare crm lists
try {
- $arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList();
- } catch (\IntaroCrm\Exception\ApiException $e) {
+ $arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList()->orderTypes;
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::orderTypesList',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- $APPLICATION->RestartBuffer();
- header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
- die(json_encode(array("success" => false)));
-
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::orderTypesList::CurlException',
+ 'intaro.crm/install/index.php', 'RetailCrm\RestApi::orderTypesList::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
@@ -223,21 +271,15 @@ class intaro_intarocrm extends CModule {
}
try {
- $arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList();
- $arResult['deliveryServicesList'] = $this->INTARO_CRM_API->deliveryServicesList();
- $arResult['paymentTypesList'] = $this->INTARO_CRM_API->paymentTypesList();
- $arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); // --statuses
- $arResult['paymentList'] = $this->INTARO_CRM_API->orderStatusesList();
- $arResult['paymentGroupList'] = $this->INTARO_CRM_API->orderStatusGroupsList(); // -- statuses groups
- } catch (\IntaroCrm\Exception\ApiException $e) {
+ $arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList()->deliveryTypes;
+ $arResult['deliveryServicesList'] = $this->INTARO_CRM_API->deliveryServicesList()->deliveryServices;
+ $arResult['paymentTypesList'] = $this->INTARO_CRM_API->paymentTypesList()->paymentTypes;
+ $arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList()->paymentStatuses; // --statuses
+ $arResult['paymentList'] = $this->INTARO_CRM_API->orderStatusesList()->statuses;
+ $arResult['paymentGroupList'] = $this->INTARO_CRM_API->orderStatusGroupsList()->statusGroups; // -- statuses groups
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::*List',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::*List::CurlException',
+ 'intaro.crm/install/index.php', 'RetailCrm\RestApi::*List::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
}
@@ -287,7 +329,8 @@ class intaro_intarocrm extends CModule {
'NAME' => 'ASC'
),
array(
- 'ACTIVE' => 'Y'
+ 'ACTIVE' => 'Y',
+ 'SITE_ID' => $arResult['arSites'][0]['LID']
)
);
@@ -485,86 +528,82 @@ class intaro_intarocrm extends CModule {
header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
die(json_encode(array("success" => true, "result" => $input)));
}
+
+ if(count($arResult['arSites'])>1){
+ // api load
+ $api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0);
+ $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0);
- $api_host = htmlspecialchars(trim($_POST[$this->CRM_API_HOST_OPTION]));
- $api_key = htmlspecialchars(trim($_POST[$this->CRM_API_KEY_OPTION]));
+ foreach($arResult['arSites'] as $site){
+ if($_POST['sites-id-'.$site['LID']] && !empty($_POST['sites-id-'.$site['LID']])){
+ $siteCode[$site['LID']] = htmlspecialchars(trim($_POST['sites-id-'.$site['LID']]));
+ }
+ }
+ if (count($arResult['arSites'])!=count($siteCode)) {
+ $arResult['errCode'] = 'ERR_FIELDS_API_HOST';
+ $APPLICATION->IncludeAdminFile(
+ GetMessage('MODULE_INSTALL_TITLE'),
+ $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step11.php'
+ );
+ return;
+ }
- // empty == select all
- $orderSites = array();
- /* foreach ($_POST[$this->CRM_ORDER_SITES] as $site) {
- $orderSites[] = htmlspecialchars(trim($site));
- } */
+ $this->INTARO_CRM_API = new \RetailCrm\RestApi($api_host, $api_key);
+ COption::SetOptionString($this->MODULE_ID, $this->CRM_SITES_LIST, serialize($siteCode));
+ }
+ else{//если 1 сайт
+ $api_host = htmlspecialchars(trim($_POST[$this->CRM_API_HOST_OPTION]));
+ $api_key = htmlspecialchars(trim($_POST[$this->CRM_API_KEY_OPTION]));
- // form correct url
- $api_host = parse_url($api_host);
- if($api_host['scheme'] != 'https') $api_host['scheme'] = 'https';
- $api_host = $api_host['scheme'] . '://' . $api_host['host'];
+ // form correct url
+ $api_host = parse_url($api_host);
+ if($api_host['scheme'] != 'https') $api_host['scheme'] = 'https';
+ $api_host = $api_host['scheme'] . '://' . $api_host['host'];
- if (!$api_host || !$api_key) {
- $arResult['errCode'] = 'ERR_FIELDS_API_HOST';
- $APPLICATION->IncludeAdminFile(
- GetMessage('MODULE_INSTALL_TITLE'),
+ if (!$api_host || !$api_key) {
+ $arResult['errCode'] = 'ERR_FIELDS_API_HOST';
+ $APPLICATION->IncludeAdminFile(
+ GetMessage('MODULE_INSTALL_TITLE'),
+ $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
+ );
+ return;
+ }
+
+ $this->INTARO_CRM_API = new \RetailCrm\RestApi($api_host, $api_key);
+
+ try {
+ $this->INTARO_CRM_API->paymentStatusesList()->paymentStatuses;
+ } catch (\RetailCrm\Exception\CurlException $e) {
+ ICrmOrderActions::eventLog(
+ 'intaro.crm/install/index.php', 'RetailCrm\RestApi::paymentStatusesList::CurlException',
+ $e->getCode() . ': ' . $e->getMessage()
+ );
+
+ $arResult['errCode'] = 'ERR_' . $e->getCode();
+
+ $APPLICATION->IncludeAdminFile(
+ GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
- );
- return;
+ );
+
+ return;
+ }
+ COption::SetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, $api_host);
+ COption::SetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, $api_key);
}
-
- $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
-
- try {
- $this->INTARO_CRM_API->paymentStatusesList();
- } catch (\IntaroCrm\Exception\ApiException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::paymentStatusesList',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- $arResult['errCode'] = 'ERR_' . $e->getCode();
-
- $APPLICATION->IncludeAdminFile(
- GetMessage('MODULE_INSTALL_TITLE'),
- $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
- );
-
- return;
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::paymentStatusesList::CurlException',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- $arResult['errCode'] = 'ERR_' . $e->getCode();
-
- $APPLICATION->IncludeAdminFile(
- GetMessage('MODULE_INSTALL_TITLE'),
- $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
- );
-
- return;
- }
-
- COption::SetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, $api_host);
- COption::SetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, $api_key);
- COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_SITES, serialize($orderSites));
-
+
//prepare crm lists
- try {
- $arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList();
- $arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList();
- $arResult['deliveryServicesList'] = $this->INTARO_CRM_API->deliveryServicesList();
- $arResult['paymentTypesList'] = $this->INTARO_CRM_API->paymentTypesList();
- $arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); // --statuses
- $arResult['paymentList'] = $this->INTARO_CRM_API->orderStatusesList();
- $arResult['paymentGroupList'] = $this->INTARO_CRM_API->orderStatusGroupsList(); // -- statuses groups
- } catch (\IntaroCrm\Exception\ApiException $e) {
+ try {
+ $arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList()->orderTypes;
+ $arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList()->deliveryTypes;
+ $arResult['deliveryServicesList'] = $this->INTARO_CRM_API->deliveryServicesList()->deliveryServices;
+ $arResult['paymentTypesList'] = $this->INTARO_CRM_API->paymentTypesList()->paymentTypes;
+ $arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList()->paymentStatuses; // --statuses
+ $arResult['paymentList'] = $this->INTARO_CRM_API->orderStatusesList()->statuses;
+ $arResult['paymentGroupList'] = $this->INTARO_CRM_API->orderStatusGroupsList()->statusGroups; // -- statuses groups
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::*List',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::*List::CurlException',
+ 'intaro.crm/install/index.php', 'RetailCrm\RestApi::*List::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
}
@@ -607,7 +646,8 @@ class intaro_intarocrm extends CModule {
'NAME' => 'ASC'
),
array(
- 'ACTIVE' => 'Y'
+ 'ACTIVE' => 'Y',
+ 'SITE_ID' => $arResult['arSites'][0]['LID']
)
);
@@ -659,7 +699,7 @@ class intaro_intarocrm extends CModule {
GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step2.php'
);
- } else if ($step == 3) {
+ } else if ($step == 3) {//сопостовление свойств заказа
if (!CModule::IncludeModule("sale")) {
//handler
}
@@ -674,7 +714,7 @@ class intaro_intarocrm extends CModule {
// api load
$api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0);
- $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
+ $this->INTARO_CRM_API = new \RetailCrm\RestApi($api_host, $api_key);
//bitrix orderTypesList -- personTypes
$dbOrderTypesList = CSalePersonType::GetList(
@@ -705,15 +745,20 @@ class intaro_intarocrm extends CModule {
"ACTIVE" => "Y",
), false, false, array()
);
-
+
//bitrix deliveryServicesList
+ $rsSites = CSite::GetList($by, $sort, array());
+ while ($ar = $rsSites->Fetch()){
+ $arResult['arSites'][] = $ar;
+ }
$dbDeliveryServicesList = CSaleDeliveryHandler::GetList(
array(
'SORT' => 'ASC',
'NAME' => 'ASC'
),
array(
- 'ACTIVE' => 'Y'
+ 'ACTIVE' => 'Y',
+ 'SITE_ID' => $arResult['arSites'][0]['LID']
)
);
@@ -760,15 +805,9 @@ class intaro_intarocrm extends CModule {
'description' => ICrmOrderActions::toJSON($arDeliveryTypesList['DESCRIPTION']),
'paymentTypes' => ''
)));
- } catch (\IntaroCrm\Exception\ApiException $e) {
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::deliveryTypeEdit',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::deliveryTypeEdit::CurlException',
+ 'intaro.crm/install/index.php', 'RetailCrm\RestApi::deliveryTypeEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
}
@@ -790,21 +829,14 @@ class intaro_intarocrm extends CModule {
'description' => ICrmOrderActions::toJSON($arDeliveryTypesList['DESCRIPTION']),
'paymentTypes' => ''
)));
- } catch (\IntaroCrm\Exception\ApiException $e) {
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::deliveryTypeEdit',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::deliveryTypeEdit::CurlException',
+ 'intaro.crm/install/index.php', 'RetailCrm\RestApi::deliveryTypeEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
}
foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) {
-
// send to crm
try {
$this->INTARO_CRM_API->deliveryServiceEdit(ICrmOrderActions::clearArr(array(
@@ -812,13 +844,7 @@ class intaro_intarocrm extends CModule {
'name' => ICrmOrderActions::toJSON($profile['TITLE']),
'deliveryType' => $arDeliveryServicesList['SID']
)));
- } catch (\IntaroCrm\Exception\ApiException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::deliveryServiceEdit',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- } catch (\IntaroCrm\Exception\CurlException $e) {
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::deliveryServiceEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
@@ -892,7 +918,7 @@ class intaro_intarocrm extends CModule {
GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step3.php'
);
- } else if ($step == 4) {
+ } else if ($step == 4) {//выгрузка старых заказов
if (!CModule::IncludeModule("sale")) {
//handler
}
@@ -904,8 +930,7 @@ class intaro_intarocrm extends CModule {
);
}
- if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
- && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) {
+ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) {
ICrmOrderActions::uploadOrders(); // each 50
$lastUpOrderId = COption::GetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0);
@@ -966,14 +991,43 @@ class intaro_intarocrm extends CModule {
$orderPropsArr[$orderType['ID']] = $_orderPropsArr;
}
+ //legal details props
+ $legalDetailsArr = array();
+ foreach ($orderTypesList as $orderType) {
+ $_legalDetailsArr = array();
+ foreach ($arResult['legalDetails'] as $legalDetails) {
+
+ $_legalDetailsArr[$legalDetails['ID']] = htmlspecialchars(trim($_POST['legal-detail-' . $legalDetails['ID'] . '-' . $orderType['ID']]));
+ }
+ $legalDetailsArr[$orderType['ID']] = $_legalDetailsArr;
+ }
+
+ $customFieldsArr = array();
+ foreach ($orderTypesList as $orderType) {
+ $_customFieldsArr = array();
+ foreach ($arResult['customFields'] as $custom) {
+ $_customFieldsArr[$custom['ID']] = htmlspecialchars(trim($_POST['custom-fields-' . $custom['ID'] . '-' . $orderType['ID']]));
+ }
+ $customFieldsArr[$orderType['ID']] = $_customFieldsArr;
+ }
+
+ //contragents type list
+ $contragentTypeArr = array();//сделать проверки
+ foreach ($orderTypesList as $orderType) {
+ $contragentTypeArr[$orderType['ID']] = htmlspecialchars(trim($_POST['contragent-type-' . $orderType['ID']]));
+ }
+
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_PROPS, serialize(ICrmOrderActions::clearArr($orderPropsArr)));
-
+ COption::SetOptionString($this->MODULE_ID, $this->CRM_CUSTOM_FIELDS, serialize(ICrmOrderActions::clearArr($customFieldsArr)));
+ COption::SetOptionString($this->MODULE_ID, $this->CRM_LEGAL_DETAILS, serialize(ICrmOrderActions::clearArr($legalDetailsArr)));
+ COption::SetOptionString($this->MODULE_ID, $this->CRM_CONTRAGENT_TYPE, serialize(ICrmOrderActions::clearArr($contragentTypeArr)));
+
$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step4.php'
);
- } else if ($step == 5) {
+ } else if ($step == 5) {//экспорт каталога
if (!CModule::IncludeModule("iblock")) {
$arResult['errCode'] = 'ERR_IBLOCK';
}
@@ -996,7 +1050,7 @@ class intaro_intarocrm extends CModule {
GetMessage('MODULE_INSTALL_TITLE'),
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step5.php'
);
- } else if ($step == 6) {
+ } else if ($step == 6) {//регистрация модуля
if (!CModule::IncludeModule("iblock")) {
$arResult['errCode'] = 'ERR_IBLOCK';
@@ -1114,7 +1168,13 @@ class intaro_intarocrm extends CModule {
$this->CopyFiles();
if (isset($_POST['LOAD_NOW'])) {
-
+ $rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
+ while ($ar = $rsSites->Fetch()){
+ if($ar['DEF'] == 'Y'){
+ $SERVER_NAME = $ar['SERVER_NAME'];//разделить потом с учетом многосайтовости
+ }
+ }
+
$loader = new ICMLLoader();
$loader->iblocks = $iblocks;
$loader->propertiesUnitProduct = $propertiesUnitProduct;
@@ -1122,6 +1182,7 @@ class intaro_intarocrm extends CModule {
$loader->propertiesUnitSKU = $propertiesUnitSKU;
$loader->propertiesSKU = $propertiesSKU;
$loader->filename = $filename;
+ $loader->serverName = $SERVER_NAME;
$loader->application = $APPLICATION;
$loader->Load();
@@ -1239,18 +1300,12 @@ class intaro_intarocrm extends CModule {
$api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0);
- $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
+ $this->INTARO_CRM_API = new \RetailCrm\RestApi($api_host, $api_key);
try {
$this->INTARO_CRM_API->statisticUpdate();
- } catch (\IntaroCrm\Exception\ApiException $e) {
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::statisticUpdate',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/install/index.php', 'IntaroCrm\RestApi::statisticUpdate::CurlException',
+ 'intaro.crm/install/index.php', 'RetailCrm\RestApi::statisticUpdate::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
}
@@ -1280,6 +1335,10 @@ class intaro_intarocrm extends CModule {
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_LAST_ID);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_SITES);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_PROPS);
+ COption::RemoveOption($this->MODULE_ID, $this->CRM_LEGAL_DETAILS);
+ COption::RemoveOption($this->MODULE_ID, $this->CRM_CONTRAGENT_TYPE);
+ COption::RemoveOption($this->MODULE_ID, $this->CRM_CUSTOM_FIELDS);
+ COption::RemoveOption($this->MODULE_ID, $this->CRM_SITES_LIST);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_DISCHARGE);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_HISTORY_DATE);
diff --git a/intaro.intarocrm/install/retailcrm/agent.php b/intaro.intarocrm/install/retailcrm/agent.php
deleted file mode 100644
index d24b259a..00000000
--- a/intaro.intarocrm/install/retailcrm/agent.php
+++ /dev/null
@@ -1,2 +0,0 @@
-">
-
+
diff --git a/intaro.intarocrm/install/step11.php b/intaro.intarocrm/install/step11.php
new file mode 100644
index 00000000..af6bfb5e
--- /dev/null
+++ b/intaro.intarocrm/install/step11.php
@@ -0,0 +1,53 @@
+
+
+
\ No newline at end of file
diff --git a/intaro.intarocrm/install/step2.php b/intaro.intarocrm/install/step2.php
old mode 100755
new mode 100644
diff --git a/intaro.intarocrm/install/step3.php b/intaro.intarocrm/install/step3.php
old mode 100755
new mode 100644
index 46bc838c..6a94c8fa
--- a/intaro.intarocrm/install/step3.php
+++ b/intaro.intarocrm/install/step3.php
@@ -19,7 +19,6 @@ $defaultOrderProps = array(
'email' => 'EMAIL'
)
);
-
?>
@@ -60,6 +75,21 @@ $defaultOrderProps = array(
|
+
+
+
+ |
+
+
+ |
+
+
@@ -71,23 +101,78 @@ $defaultOrderProps = array(
+
3) echo 'class="address-detail-' . $bitrixOrderType['ID'] . '"'; if(($countProps > 3) && (count($defaultOrderProps[$bitrixOrderType['ID']]) < 6)) echo 'style="display:none;"';?>>
|
-
-
- |
-
-
-
+
+
+ |
+
+
+
+ 0):?>
+
+
+
+ =GetMessage("ORDER_CUSTOM"); ?>
+
+ |
+
+
+
+
+ =$customFields['NAME']; ?>
+ |
+
+
+ |
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+ |
+
+
+ |
+
+
+
+
diff --git a/intaro.intarocrm/install/unstep1.php b/intaro.intarocrm/install/unstep1.php
old mode 100755
new mode 100644
diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php
index 8237d382..84c7a46f 100644
--- a/intaro.intarocrm/install/version.php
+++ b/intaro.intarocrm/install/version.php
@@ -1,5 +1,6 @@
$arModuleVersion = array(
- "VERSION" => "1.0.15",
- "VERSION_DATE" => "2014-11-27 16:00:00"
+ "VERSION" => "1.1.0",
+ "VERSION_DATE" => "2015-03-03 16:21:38"
);
+
diff --git a/intaro.intarocrm/lang/ru/install/index.php b/intaro.intarocrm/lang/ru/install/index.php
old mode 100755
new mode 100644
index bc394e36..29de5b63
--- a/intaro.intarocrm/lang/ru/install/index.php
+++ b/intaro.intarocrm/lang/ru/install/index.php
@@ -1,15 +1,14 @@
Интеграция).';
$MESS ['INFO_3'] = 'Код сайта в 1С-Битрикс должен совпадать с кодом сайта в retailCRM (Администрирование > Магазины).';
\ No newline at end of file
diff --git a/intaro.intarocrm/lang/ru/install/step11.php b/intaro.intarocrm/lang/ru/install/step11.php
new file mode 100644
index 00000000..64b4072e
--- /dev/null
+++ b/intaro.intarocrm/lang/ru/install/step11.php
@@ -0,0 +1,11 @@
+ GetMessage('FIO'),
- 'ID' => 'fio'
- ),
- array(
- 'NAME' => GetMessage('PHONE'),
- 'ID' => 'phone'
- ),
- array(
- 'NAME' => GetMessage('EMAIL'),
- 'ID' => 'email'
- ),
- array(
- 'NAME' => GetMessage('ADDRESS'),
- 'ID' => 'text'
- ),
- // address
- /* array(
- 'NAME' => GetMessage('COUNTRY'),
- 'ID' => 'country'
- ),
- array(
- 'NAME' => GetMessage('REGION'),
- 'ID' => 'region'
- ),
- array(
- 'NAME' => GetMessage('CITY'),
- 'ID' => 'city'
- ),*/
- array(
- 'NAME' => GetMessage('ZIP'),
- 'ID' => 'index'
- ),
- array(
- 'NAME' => GetMessage('STREET'),
- 'ID' => 'street'
- ),
- array(
- 'NAME' => GetMessage('BUILDING'),
- 'ID' => 'building'
- ),
- array(
- 'NAME' => GetMessage('FLAT'),
- 'ID' => 'flat'
- ),
- array(
- 'NAME' => GetMessage('INTERCOMCODE'),
- 'ID' => 'intercomcode'
- ),
- array(
- 'NAME' => GetMessage('FLOOR'),
- 'ID' => 'floor'
- ),
- array(
- 'NAME' => GetMessage('BLOCK'),
- 'ID' => 'block'
- ),
- array(
- 'NAME' => GetMessage('HOUSE'),
- 'ID' => 'house'
- )
-);
+if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.intarocrm/classes/general/config/options.xml')) {
+ $options = simplexml_load_file($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.intarocrm/classes/general/config/options.xml');
+
+ foreach($options->contragents->contragent as $contragent)
+ {
+ $type["NAME"] = $APPLICATION->ConvertCharset((string)$contragent, 'utf-8', SITE_CHARSET);
+ $type["ID"] = (string)$contragent["id"];
+ $arResult['contragentType'][] = $type;
+ unset ($type);
+ }
+ foreach($options->fields->field as $field)
+ {
+ $type["NAME"] = $APPLICATION->ConvertCharset((string)$field, 'utf-8', SITE_CHARSET);
+ $type["ID"] = (string)$field["id"];
+
+ if ($field["group"] == 'custom') {
+ $arResult['customFields'][] = $type;
+ } elseif(!$field["group"]){
+ $arResult['orderProps'][] = $type;
+ } else{
+ $groups = explode(",", (string)$field["group"]);
+ foreach ($groups as $group) {
+ $type["GROUP"][] = trim($group);
+ }
+ $arResult['legalDetails'][] = $type;
+ }
+ unset($type);
+ }
+}
+//else error
+
+$arResult['arSites'] = array();
+
+$rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
+while ($ar = $rsSites->Fetch()){
+ $arResult['arSites'][] = $ar;
+}
//ajax update deliveryServices
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) {
@@ -99,23 +77,13 @@ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_RE
$api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0);
- $api = new IntaroCrm\RestApi($api_host, $api_key);
+ $api = new RetailCrm\RestApi($api_host, $api_key);
try {
$api->paymentStatusesList();
- } catch (\IntaroCrm\Exception\ApiException $e) {
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
- 'intaro.crm/options.php', 'IntaroCrm\RestApi::paymentStatusesList',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- $APPLICATION->RestartBuffer();
- header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
- die(json_encode(array('success' => false, 'errMsg' => $e->getCode())));
-
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/options.php', 'IntaroCrm\RestApi::paymentStatusesList::CurlException',
+ 'intaro.crm/options.php', 'RetailCrm\RestApi::paymentStatusesList::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
@@ -133,7 +101,8 @@ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_RE
'NAME' => 'ASC'
),
array(
- 'ACTIVE' => 'Y'
+ 'ACTIVE' => 'Y',
+ 'SITE_ID' => $arResult['arSites'][0]['LID']
)
);
@@ -154,15 +123,9 @@ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_RE
'name' => ICrmOrderActions::toJSON($profile['TITLE']),
'deliveryType' => $arDeliveryServicesList['SID']
)));
- } catch (\IntaroCrm\Exception\ApiException $e) {
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
- 'intaro.crm/options.php', 'IntaroCrm\RestApi::deliveryServiceEdit',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/options.php', 'IntaroCrm\RestApi::deliveryServiceEdit::CurlException',
+ 'intaro.crm/options.php', 'RetailCrm\RestApi::deliveryServiceEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
}
@@ -176,33 +139,83 @@ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_RE
die(json_encode(array('success' => true)));
}
+//upload orders after install module
+if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && $_POST['ajax'] == 2){
+ $step = $_POST['step'];
+ $orders = $_POST['orders'];
+ $countStep = 50; // 50 orders on step
+
+ if($orders){
+ $ordersArr = explode(',', $orders);
+ $orders = array();
+ foreach($ordersArr as $_ordersArr){
+ $ordersList = explode('-', trim($_ordersArr));
+ if(count($ordersList) > 1){
+ for($i = (int)trim($ordersList[0]); $i <= (int)trim($ordersList[count($ordersList) - 1]); $i++){
+ $orders[] = $i;
+ }
+ } else{
+ $orders[] = (int)$ordersList[0];
+ }
+ }
+
+ $splitedOrders = array_chunk($orders, $countStep);
+ $stepOrders = $splitedOrders[$step];
+
+ ICrmOrderActions::uploadOrders($countStep, false, $stepOrders);
+
+ $percent = round((($step * $countStep + count($stepOrders)) * 100 / count($orders)), 1);
+ $step++;
+
+ if(!$splitedOrders[$step]){
+ $step='end';
+ }
+
+ $res = array("step" => $step, "percent" => $percent, 'stepOrders' => $stepOrders);
+ } else{
+ $orders = array();
+
+ for($i = 1; $i <= $countStep; $i++){
+ $orders[] = $i + $step * $countStep;
+ }
+
+ ICrmOrderActions::uploadOrders($countStep, false, $orders);
+
+ $step++;
+ $countLeft = (int) CSaleOrder::GetList(array("ID" => "ASC"), array('>ID' => $step * $countStep), array());
+ $countAll = (int) CSaleOrder::GetList(array("ID" => "ASC"), array(), array());
+ $percent = round(100 - ($countLeft * 100 / $countAll), 1);
+
+ if($countLeft == 0){
+ $step = 'end';
+ }
+
+ $res = array("step" => $step, "percent" => $percent, 'stepOrders' => $orders);
+ }
+
+ $APPLICATION->RestartBuffer();
+ header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
+ die(json_encode($res));
+}
+
//update connection settings
if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$api_host = htmlspecialchars(trim($_POST['api_host']));
$api_key = htmlspecialchars(trim($_POST['api_key']));
-
- // if empty so select all? or exception --not obligatory
- $orderSites = array();
- /*foreach ($_POST[$CRM_ORDER_SITES] as $site) {
- $orderSites[] = htmlspecialchars(trim($site));
- }*/
+
+ //bitrix site list
+ $siteListArr = array();
+ foreach ($arResult['arSites'] as $arSites) {
+ $siteListArr[$arSites['LID']] = htmlspecialchars(trim($_POST['sites-id-' . $arSites['LID']]));
+ }
if($api_host && $api_key) {
- $api = new IntaroCrm\RestApi($api_host, $api_key);
+ $api = new RetailCrm\RestApi($api_host, $api_key);
try {
$api->paymentStatusesList();
- } catch (\IntaroCrm\Exception\ApiException $e) {
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
- 'intaro.crm/options.php', 'IntaroCrm\RestApi::paymentStatusesList',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- $uri .= '&errc=ERR_' . $e->getCode();
- LocalRedirect($uri);
-
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/options.php', 'IntaroCrm\RestApi::paymentStatusesList::CurlException',
+ 'intaro.crm/options.php', 'RetailCrm\RestApi::paymentStatusesList::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
@@ -267,7 +280,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
'NAME' => 'ASC'
),
array(
- 'ACTIVE' => 'Y'
+ 'ACTIVE' => 'Y',
+ 'SITE_ID' => $arResult['arSites'][0]['LID']
)
);
@@ -349,22 +363,51 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$propsCount = 0;
$_orderPropsArr = array();
foreach ($arResult['orderProps'] as $orderProp) {
- if ((!(int) htmlspecialchars(trim($_POST['address-detail-' . $orderType['ID']]))) && $propsCount > 4)
+ if ((!(int) htmlspecialchars(trim($_POST['address-detail-' . $orderType['ID']]))) && $propsCount > 4){
break;
+ }
$_orderPropsArr[$orderProp['ID']] = htmlspecialchars(trim($_POST['order-prop-' . $orderProp['ID'] . '-' . $orderType['ID']]));
$propsCount++;
}
$orderPropsArr[$orderType['ID']] = $_orderPropsArr;
}
+ //legal details props
+ $legalDetailsArr = array();
+ foreach ($orderTypesList as $orderType) {
+ $_legalDetailsArr = array();
+ foreach ($arResult['legalDetails'] as $legalDetails) {
+ $_legalDetailsArr[$legalDetails['ID']] = htmlspecialchars(trim($_POST['legal-detail-' . $legalDetails['ID'] . '-' . $orderType['ID']]));
+ }
+ $legalDetailsArr[$orderType['ID']] = $_legalDetailsArr;
+ }
+
+ $customFieldsArr = array();
+ foreach ($orderTypesList as $orderType) {
+ $_customFieldsArr = array();
+ foreach ($arResult['customFields'] as $custom) {
+ $_customFieldsArr[$custom['ID']] = htmlspecialchars(trim($_POST['custom-fields-' . $custom['ID'] . '-' . $orderType['ID']]));
+ }
+ $customFieldsArr[$orderType['ID']] = $_customFieldsArr;
+ }
+
+ //contragents type list
+ $contragentTypeArr = array();
+ foreach ($orderTypesList as $orderType) {
+ $contragentTypeArr[$orderType['ID']] = htmlspecialchars(trim($_POST['contragent-type-' . $orderType['ID']]));
+ }
+
+ COption::SetOptionString($mid, $CRM_SITES_LIST, serialize(ICrmOrderActions::clearArr($siteListArr)));
COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize(ICrmOrderActions::clearArr($orderTypesArr)));
COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize(ICrmOrderActions::clearArr($deliveryTypesArr)));
COption::SetOptionString($mid, $CRM_PAYMENT_TYPES, serialize(ICrmOrderActions::clearArr($paymentTypesArr)));
COption::SetOptionString($mid, $CRM_PAYMENT_STATUSES, serialize(ICrmOrderActions::clearArr($paymentStatusesArr)));
COption::SetOptionString($mid, $CRM_PAYMENT, serialize(ICrmOrderActions::clearArr($paymentArr)));
- COption::SetOptionString($mid, $CRM_ORDER_SITES, serialize(ICrmOrderActions::clearArr($orderSites)));
COption::SetOptionString($mid, $CRM_ORDER_DISCHARGE, $orderDischarge);
- COption::SetOptionString($mid, $CRM_ORDER_PROPS, serialize(ICrmOrderActions::clearArr($orderPropsArr)));
+ COption::SetOptionString($mid, $CRM_ORDER_PROPS, serialize(ICrmOrderActions::clearArr($orderPropsArr)));
+ COption::SetOptionString($mid, $CRM_CONTRAGENT_TYPE, serialize(ICrmOrderActions::clearArr($contragentTypeArr)));
+ COption::SetOptionString($mid, $CRM_LEGAL_DETAILS, serialize(ICrmOrderActions::clearArr($legalDetailsArr)));
+ COption::SetOptionString($mid, $CRM_CUSTOM_FIELDS, serialize(ICrmOrderActions::clearArr($customFieldsArr)));
$uri .= '&ok=Y';
LocalRedirect($uri);
@@ -372,33 +415,21 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0);
- $api = new IntaroCrm\RestApi($api_host, $api_key);
-
- $arResult['arSites'] = array();
- $rsSites = CSite::GetList($by, $sort, array());
- while ($ar = $rsSites->Fetch())
- $arResult['arSites'][] = $ar;
+ $api = new RetailCrm\RestApi($api_host, $api_key);
//prepare crm lists
try {
- $arResult['orderTypesList'] = $api->orderTypesList();
- $arResult['deliveryTypesList'] = $api->deliveryTypesList();
- $arResult['deliveryServicesList'] = $api->deliveryServicesList();
- $arResult['paymentTypesList'] = $api->paymentTypesList();
- $arResult['paymentStatusesList'] = $api->paymentStatusesList(); // --statuses
- $arResult['paymentList'] = $api->orderStatusesList();
- $arResult['paymentGroupList'] = $api->orderStatusGroupsList(); // -- statuses groups
- } catch (\IntaroCrm\Exception\ApiException $e) {
+ $arResult['orderTypesList'] = $api->orderTypesList()->orderTypes;
+ $arResult['deliveryTypesList'] = $api->deliveryTypesList()->deliveryTypes;
+ $arResult['deliveryServicesList'] = $api->deliveryServicesList()->deliveryServices;
+ $arResult['paymentTypesList'] = $api->paymentTypesList()->paymentTypes;
+ $arResult['paymentStatusesList'] = $api->paymentStatusesList()->paymentStatuses; // --statuses
+ $arResult['paymentList'] = $api->orderStatusesList()->statuses;
+ $arResult['paymentGroupList'] = $api->orderStatusGroupsList()->statusGroups; // -- statuses groups
+ $arResult['sitesList'] = $api->sitesList()->sites;
+ } catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
- 'intaro.crm/options.php', 'IntaroCrm\RestApi::*List',
- $e->getCode() . ': ' . $e->getMessage()
- );
-
- echo CAdminMessage::ShowMessage(GetMessage('ERR_' . $e->getCode()));
-
- } catch (\IntaroCrm\Exception\CurlException $e) {
- ICrmOrderActions::eventLog(
- 'intaro.crm/options.php', 'IntaroCrm\RestApi::*List::CurlException',
+ 'intaro.crm/options.php', 'RetailCrm\RestApi::*List::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
@@ -410,16 +441,16 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
array(
"SORT" => "ASC",
"NAME" => "ASC"
- ),
+ ),
array(
"ACTIVE" => "Y",
),
false,
false,
array()
- );
+ );
- if ($arOrderTypesList = $dbOrderTypesList->Fetch()) {
+ if ($arOrderTypesList = $dbOrderTypesList->Fetch()) {
do {
$arResult['bitrixOrderTypesList'][] = $arOrderTypesList;
} while ($arOrderTypesList = $dbOrderTypesList->Fetch());
@@ -452,7 +483,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
'NAME' => 'ASC'
),
array(
- 'ACTIVE' => 'Y'
+ 'ACTIVE' => 'Y',
+ 'SITE_ID' => $arResult['arSites'][0]['LID']
)
);
@@ -511,16 +543,19 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
while ($arProp = $dbProp->GetNext()) {
$arResult['arProp'][$arProp['PERSON_TYPE_ID']][] = $arProp;
}
-
+
//saved cat params
$optionsOrderTypes = unserialize(COption::GetOptionString($mid, $CRM_ORDER_TYPES_ARR, 0));
$optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0));
$optionsPayTypes = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_TYPES, 0));
$optionsPayStatuses = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_STATUSES, 0)); // --statuses
$optionsPayment = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT, 0));
- $optionsSites = unserialize(COption::GetOptionString($mid, $CRM_ORDER_SITES, 0));
+ $optionsSitesList = unserialize(COption::GetOptionString($mid, $CRM_SITES_LIST, 0));
$optionsDischarge = COption::GetOptionString($mid, $CRM_ORDER_DISCHARGE, 0);
- $optionsOrderProps = unserialize(COption::GetOptionString($mid, $CRM_ORDER_PROPS, 0));
+ $optionsOrderProps = unserialize(COption::GetOptionString($mid, $CRM_ORDER_PROPS, 0));
+ $optionsContragentType = unserialize(COption::GetOptionString($mid, $CRM_CONTRAGENT_TYPE, 0));
+ $optionsLegalDetails = unserialize(COption::GetOptionString($mid, $CRM_LEGAL_DETAILS, 0));
+ $optionsCustomFields = unserialize(COption::GetOptionString($mid, $CRM_CUSTOM_FIELDS, 0));
$isCustomOrderType = function_exists('intarocrm_set_order_type') || function_exists('intarocrm_get_order_type');
@@ -564,8 +599,24 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$('tr.address-detail-' + orderType).show('slow');
else if(parseInt($(this).val()) === 0)
$('tr.address-detail-' + orderType).hide('slow');
+ });
+
+ $('tr.contragent-type select').change(function(){
+ splitName = $(this).attr('name').split('-');
+ contragentType = $(this).val();
+ orderType = splitName[2];
+
+ $('tr.legal-detail-' + orderType).hide();
+ $('.legal-detail-title-' + orderType).hide();
+
+ $('tr.legal-detail-' + orderType).each(function(){
+ if($(this).hasClass(contragentType)){
+ $(this).show();
+ $('.legal-detail-title-' + orderType).show();
+ }
});
- });
+ });
+ });
$('input[name="update-delivery-services"]').live('click', function() {
BX.showWait();
@@ -617,16 +668,27 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
|
|
-
+
+
+
BeginNextTab(); ?>
@@ -760,8 +822,21 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
|
-
-
+
+
+
+ |
+
+
+ |
+
+
@@ -788,7 +863,58 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
|
+ 0):?>
+
+
+
+ =GetMessage("ORDER_CUSTOM"); ?>
+
+ |
+
+
+
+
+ =$customFields['NAME']; ?>
+ |
+
+
+ |
+
+
+
+ >
+
+
+
+
+ |
+
+
+ >
+
+
+ |
+
+
+ |
+
+
+
BeginNextTab(); ?>
@@ -803,9 +929,173 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
Buttons(); ?>
-
-
+
+
End(); ?>
-
+
+
-
\ No newline at end of file
+
+
+
+
+
+
+
+
diff --git a/intaro.intarocrm/updater.php b/intaro.intarocrm/updater.php
new file mode 100644
index 00000000..b775734c
--- /dev/null
+++ b/intaro.intarocrm/updater.php
@@ -0,0 +1,87 @@
+apiUrl.'reference/sites';
+ $result = $this->curlRequest($url);
+ return $result;
+ }
+}
+$mid = 'intaro.intarocrm';
+$CRM_API_HOST_OPTION = 'api_host';
+$CRM_API_KEY_OPTION = 'api_key';
+$CRM_CONTRAGENT_TYPE = 'contragent_type';
+$CRM_SITES_LIST= 'sites_list';
+
+$api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0);
+$api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0);
+$api = new RestApiSite($api_host, $api_key);
+
+if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/intaro.intarocrm/classes/general/agent.php')) {
+ unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/intaro.intarocrm/classes/general/agent.php');
+}
+if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/intaro.intarocrm/classes/general/Exception/ApiException.php')) {
+ unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/intaro.intarocrm/classes/general/Exception/ApiException.php');
+}
+if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/retailcrm')) {
+ removeDirectory($_SERVER['DOCUMENT_ROOT'] . '/retailcrm');
+}
+
+//sites
+$rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
+while ($ar = $rsSites->Fetch()){
+ $arSites[] = $ar;
+}
+if(count($arSites)>1){
+ try {
+ $sitesList = $api->sitesList();
+ } catch (\IntaroCrm\Exception\CurlException $e) {
+ ICrmOrderActions::eventLog(
+ 'intaro.crm/updater.php', 'RetailCrm\RestApi::sitesList::CurlException',
+ $e->getCode() . ': ' . $e->getMessage()
+ );
+ return;
+ }
+ foreach ($arResult['arSites'] as $arSites) {
+ $siteListArr[$arSites['LID']] = $sitesList[0]['code'];
+ }
+ COption::SetOptionString($mid, $CRM_SITES_LIST, serialize(ICrmOrderActions::clearArr($siteListArr)));
+}
+
+//contragents type list
+$dbOrderTypesList = CSalePersonType::GetList(
+ array(
+ "SORT" => "ASC",
+ "NAME" => "ASC"
+ ),
+ array(
+ "ACTIVE" => "Y",
+ ),
+ false,
+ false,
+ array()
+);
+
+$orderTypesList = array();
+while ($arOrderTypesList = $dbOrderTypesList->Fetch()){
+ $orderTypesList[] = $arOrderTypesList;
+}
+$contragentTypeArr = array();
+foreach ($orderTypesList as $orderType) {
+ $contragentTypeArr[$orderType['ID']] = 'individual';
+}
+COption::SetOptionString($mid, $CRM_CONTRAGENT_TYPE, serialize(ICrmOrderActions::clearArr($contragentTypeArr)));
+
+function removeDirectory($dir) {
+ if ($objs = glob($dir."/*")) {
+ foreach($objs as $obj) {
+ is_dir($obj) ? removeDirectory($obj) : unlink($obj);
+ }
+ }
+ rmdir($dir);
+}