From 3f7cc6b963c7422567f14c5ae96fe7795828f2da Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 23 Jan 2014 17:50:58 +0400 Subject: [PATCH 01/10] +deliveryServices options & install; -order send --- intaro.intarocrm/classes/general/RestApi.php | 28 ++++ intaro.intarocrm/install/index.php | 166 ++++++++++++++++++- intaro.intarocrm/install/step2.php | 46 ++++- intaro.intarocrm/install/step3.php | 2 +- intaro.intarocrm/lang/ru/install/step2.php | 1 + intaro.intarocrm/lang/ru/options.php | 4 +- intaro.intarocrm/options.php | 77 ++++++++- 7 files changed, 311 insertions(+), 13 deletions(-) diff --git a/intaro.intarocrm/classes/general/RestApi.php b/intaro.intarocrm/classes/general/RestApi.php index f4207900..3050e68e 100644 --- a/intaro.intarocrm/classes/general/RestApi.php +++ b/intaro.intarocrm/classes/general/RestApi.php @@ -313,6 +313,34 @@ class RestApi return $result; } + /** + * Получение списка служб доставки + * + * @return array - массив типов доставки + */ + public function deliveryServicesList() + { + $url = $this->apiUrl.'reference/delivery-services'; + $result = $this->curlRequest($url); + return $result; + } + + /** + * Редактирование службы доставки + * + * @param array $deliveryService - информация о типе доставки + * @return array + */ + public function deliveryServiceEdit($deliveryService) + { + $dataJson = json_encode($deliveryService); + $this->parameters['deliveryService'] = $dataJson; + + $url = $this->apiUrl.'reference/delivery-services/'.$deliveryService['code'].'/edit'; + $result = $this->curlRequest($url, 'POST'); + return $result; + } + /** * Получение списка типов оплаты diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 1f1be1e0..221b13b7 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -26,6 +26,7 @@ class intaro_intarocrm extends CModule { var $CRM_API_KEY_OPTION = 'api_key'; var $CRM_ORDER_TYPES_ARR = 'order_types_arr'; var $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr'; + var $CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr'; var $CRM_PAYMENT_TYPES = 'pay_types_arr'; var $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; var $CRM_PAYMENT = 'payment_arr'; //order payment Y/N @@ -204,6 +205,7 @@ class intaro_intarocrm extends CModule { } $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(); @@ -247,6 +249,31 @@ class intaro_intarocrm extends CModule { } while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()); } + //bitrix deliveryServicesList + $dbDeliveryServicesList = CSaleDeliveryHandler::GetList( + array( + 'SORT' => 'ASC', + 'NAME' => 'ASC' + ), + array( + 'ACTIVE' => 'Y' + ) + ); + + //form delivery services ids arr + $deliveryServicesArr = array(); + if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) { + do { + //auto delivery types + $deliveryTypesArr[$arDeliveryServicesList['SID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryServicesList['SID']])); + foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) { + if(!$profile['TITLE']) continue; // services without name ? + $deliveryServicesArr[$arDeliveryServicesList['SID']][$id] = htmlspecialchars(trim($_POST['delivery-service-' . $arDeliveryServicesList['SID'] . '-' . $id])); + } + $arResult['bitrixDeliveryServicesList'][] = $arDeliveryServicesList; + } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); + } + //bitrix paymentTypesList $dbPaymentTypesList = CSalePaySystem::GetList( array( @@ -298,6 +325,7 @@ class intaro_intarocrm extends CModule { COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr)); + COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize($deliveryServicesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_TYPES, serialize($paymentTypesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT, serialize($paymentArr)); @@ -327,6 +355,43 @@ class intaro_intarocrm extends CModule { $input['delivery-type-' . $bitrixDeliveryType['ID']] .= ''; } + foreach ($arResult['bitrixDeliveryServicesList'] as $bitrixDeliveryService) { + foreach($bitrixDeliveryService['PROFILES'] as $id => $profile) { + if(!$profile['TITLE']) continue; + + $input['delivery-service-' . $bitrixDeliveryService['SID'] . '-' . $id] = + ''; + } + } + foreach ($arResult['bitrixPaymentTypesList'] as $bitrixPaymentType) { $input['payment-type-' . $bitrixPaymentType['ID']] = ' @@ -157,6 +161,34 @@ $defaultPayment = array( + + + + + $profile): if(!$profile['TITLE']) continue; ?> + + + [' . $bitrixDeliveryService['NAME'] . ']: ' . $profile['TITLE']; ?> + + + + + + + diff --git a/intaro.intarocrm/install/step3.php b/intaro.intarocrm/install/step3.php index 95416dfd..21bbd080 100755 --- a/intaro.intarocrm/install/step3.php +++ b/intaro.intarocrm/install/step3.php @@ -96,7 +96,7 @@ $defaultOrderProps = array( " class="adm-btn-save">
- " class="adm-btn-save"> + " class="adm-btn-save">
diff --git a/intaro.intarocrm/lang/ru/install/step2.php b/intaro.intarocrm/lang/ru/install/step2.php index 9a2caf28..f54c607d 100755 --- a/intaro.intarocrm/lang/ru/install/step2.php +++ b/intaro.intarocrm/lang/ru/install/step2.php @@ -3,6 +3,7 @@ $MESS ['STEP_NAME'] = 'Шаг 2'; $MESS ['MOD_NEXT_STEP'] = 'Следующий шаг'; $MESS ['MOD_PREV_STEP'] = 'Предыдущий шаг'; $MESS ['DELIVERY_TYPES_LIST'] = 'Способы доставки'; +$MESS ['DELIVERY_SERVICES_LIST'] = 'Автоматизированные службы доставок'; $MESS ['PAYMENT_TYPES_LIST'] = 'Способы оплаты'; $MESS ['PAYMENT_STATUS_LIST'] = 'Статусы'; $MESS ['ORDER_TYPES_LIST'] = 'Типы заказа'; diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 442fccdb..5b5be09f 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -52,4 +52,6 @@ $MESS ['HOUSE'] = 'Строение / корпус'; $MESS ['ADDRESS_SHORT'] = 'Краткий адрес'; $MESS ['ADDRESS_FULL'] = 'Детальный адрес'; -$MESS ['ORDER_TYPE_INFO'] = 'Тип заказа:'; \ No newline at end of file +$MESS ['ORDER_TYPE_INFO'] = 'Тип заказа:'; + +$MESS ['DELIVERY_SERVICES_LIST'] = 'Автоматизированные службы доставок'; \ No newline at end of file diff --git a/intaro.intarocrm/options.php b/intaro.intarocrm/options.php index e346f8d8..7b444d1d 100755 --- a/intaro.intarocrm/options.php +++ b/intaro.intarocrm/options.php @@ -7,6 +7,7 @@ $CRM_API_HOST_OPTION = 'api_host'; $CRM_API_KEY_OPTION = 'api_key'; $CRM_ORDER_TYPES_ARR = 'order_types_arr'; $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr'; +$CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr'; $CRM_PAYMENT_TYPES = 'pay_types_arr'; $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; $CRM_PAYMENT = 'payment_arr'; //order payment Y/N @@ -162,7 +163,32 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $deliveryTypesArr[$arDeliveryTypesList['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryTypesList['ID']])); } while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()); } - + + //bitrix deliveryServicesList + $dbDeliveryServicesList = CSaleDeliveryHandler::GetList( + array( + 'SORT' => 'ASC', + 'NAME' => 'ASC' + ), + array( + 'ACTIVE' => 'Y' + ) + ); + + //form delivery services ids arr + $deliveryServicesArr = array(); + if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) { + do { + //auto delivery types + $deliveryTypesArr[$arDeliveryServicesList['SID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryServicesList['SID']])); + foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) { + if(!$profile['TITLE']) continue; // services without name ? + $deliveryServicesArr[$arDeliveryServicesList['SID']][$id] = htmlspecialchars(trim($_POST['delivery-service-' . $arDeliveryServicesList['SID'] . '-' . $id])); + } + $arResult['bitrixDeliveryServicesList'][] = $arDeliveryServicesList; + } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); + } + //bitrix paymentTypesList $dbPaymentTypesList = CSalePaySystem::GetList( array( @@ -243,6 +269,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr)); + COption::SetOptionString($mid, $CRM_DELIVERY_SERVICES_ARR, serialize($deliveryServicesArr)); COption::SetOptionString($mid, $CRM_PAYMENT_TYPES, serialize($paymentTypesArr)); COption::SetOptionString($mid, $CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr)); COption::SetOptionString($mid, $CRM_PAYMENT, serialize($paymentArr)); @@ -266,6 +293,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { //prepare crm lists $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(); @@ -315,6 +343,24 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { } while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()); } + // bitrix deliveryServicesList + $dbDeliveryServicesList = CSaleDeliveryHandler::GetList( + array( + 'SORT' => 'ASC', + 'NAME' => 'ASC' + ), + array( + 'ACTIVE' => 'Y' + ) + ); + + if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) { + do { + $arResult['bitrixDeliveryTypesList'][] = array('ID' => $arDeliveryServicesList['SID'], 'NAME' => $arDeliveryServicesList['NAME']); + $arResult['bitrixDeliveryServicesList'][] = $arDeliveryServicesList; + } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); + } + //bitrix paymentTypesList $dbPaymentTypesList = CSalePaySystem::GetList( array( @@ -368,6 +414,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { //saved cat params $optionsOrderTypes = unserialize(COption::GetOptionString($mid, $CRM_ORDER_TYPES_ARR, 0)); $optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0)); + $optionsDelivServices = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_SERVICES_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)); @@ -471,6 +518,34 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { + + + + + $profile): if(!$profile['TITLE']) continue; ?> + + + [' . $bitrixDeliveryService['NAME'] . ']: ' . $profile['TITLE']; ?> + + + + + + + From 7fd2c09059de11f09af19d8c21a0c3af31623d9e Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Fri, 24 Jan 2014 17:57:49 +0400 Subject: [PATCH 02/10] rm option settings --- intaro.intarocrm/install/index.php | 56 ++-------------------- intaro.intarocrm/install/step2.php | 37 +------------- intaro.intarocrm/lang/ru/install/step2.php | 1 - intaro.intarocrm/lang/ru/options.php | 4 +- intaro.intarocrm/options.php | 37 -------------- 5 files changed, 6 insertions(+), 129 deletions(-) diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 221b13b7..eac1604f 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -261,16 +261,10 @@ class intaro_intarocrm extends CModule { ); //form delivery services ids arr - $deliveryServicesArr = array(); if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) { do { //auto delivery types $deliveryTypesArr[$arDeliveryServicesList['SID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryServicesList['SID']])); - foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) { - if(!$profile['TITLE']) continue; // services without name ? - $deliveryServicesArr[$arDeliveryServicesList['SID']][$id] = htmlspecialchars(trim($_POST['delivery-service-' . $arDeliveryServicesList['SID'] . '-' . $id])); - } - $arResult['bitrixDeliveryServicesList'][] = $arDeliveryServicesList; } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); } @@ -325,7 +319,6 @@ class intaro_intarocrm extends CModule { COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr)); - COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize($deliveryServicesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_TYPES, serialize($paymentTypesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT, serialize($paymentArr)); @@ -355,43 +348,6 @@ class intaro_intarocrm extends CModule { $input['delivery-type-' . $bitrixDeliveryType['ID']] .= ''; } - foreach ($arResult['bitrixDeliveryServicesList'] as $bitrixDeliveryService) { - foreach($bitrixDeliveryService['PROFILES'] as $id => $profile) { - if(!$profile['TITLE']) continue; - - $input['delivery-service-' . $bitrixDeliveryService['SID'] . '-' . $id] = - ''; - } - } - foreach ($arResult['bitrixPaymentTypesList'] as $bitrixPaymentType) { $input['payment-type-' . $bitrixPaymentType['ID']] = ''; } + + $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); die(json_encode(array("success" => true, "result" => $input))); @@ -593,7 +551,6 @@ class intaro_intarocrm extends CModule { if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) { do { $arResult['bitrixDeliveryTypesList'][] = array('ID' => $arDeliveryServicesList['SID'], 'NAME' => $arDeliveryServicesList['NAME']); - $arResult['bitrixDeliveryServicesList'][] = $arDeliveryServicesList; } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); } @@ -699,7 +656,6 @@ class intaro_intarocrm extends CModule { //form delivery types / services ids arr $deliveryTypesArr = array(); - $deliveryServicesArr = array(); if (htmlspecialchars(trim($_POST['delivery-types-export'])) == 'false') { if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) { @@ -712,11 +668,6 @@ class intaro_intarocrm extends CModule { do { //auto delivery types $deliveryTypesArr[$arDeliveryServicesList['SID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryServicesList['SID']])); - foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) { - if(!$profile['TITLE']) continue; // services without name ? - $deliveryServicesArr[$arDeliveryServicesList['SID']][$id] = htmlspecialchars(trim($_POST['delivery-service-' . $arDeliveryServicesList['SID'] . '-' . $id])); - } - $arResult['bitrixDeliveryServicesList'][] = $arDeliveryServicesList; } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); } } elseif (htmlspecialchars(trim($_POST['delivery-types-export'])) == 'true') { @@ -778,11 +729,10 @@ class intaro_intarocrm extends CModule { } foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) { - $deliveryServicesArr[$arDeliveryServicesList['SID']][$id] = $id; // send to crm $this->INTARO_CRM_API->deliveryServiceEdit(ICrmOrderActions::clearArr(array( - 'code' => $id, + 'code' => $arDeliveryServicesList['SID'] . '-' . $id, 'name' => ICrmOrderActions::toJSON($profile['TITLE']), 'deliveryType' => $arDeliveryServicesList['SID'] ))); diff --git a/intaro.intarocrm/install/step2.php b/intaro.intarocrm/install/step2.php index c8be2175..c3a83e72 100755 --- a/intaro.intarocrm/install/step2.php +++ b/intaro.intarocrm/install/step2.php @@ -94,15 +94,10 @@ $defaultPayment = array( }); $('input[name="delivery-types-export"]').click(function() { - if($(this).val() === 'true') { + if($(this).val() === 'true') $('tr.delivery-types').hide('slow'); - $('tr[name="delivery-services"]').hide('slow'); - $('tr.delivery-services').hide('slow'); - } else if($(this).val() === 'false') { + else if($(this).val() === 'false') $('tr.delivery-types').show('slow'); - $('tr[name="delivery-services"]').show('slow'); - $('tr.delivery-services').show('slow'); - } }); }); @@ -161,34 +156,6 @@ $defaultPayment = array( - - - - - $profile): if(!$profile['TITLE']) continue; ?> - - - [' . $bitrixDeliveryService['NAME'] . ']: ' . $profile['TITLE']; ?> - - - - - - - diff --git a/intaro.intarocrm/lang/ru/install/step2.php b/intaro.intarocrm/lang/ru/install/step2.php index f54c607d..9a2caf28 100755 --- a/intaro.intarocrm/lang/ru/install/step2.php +++ b/intaro.intarocrm/lang/ru/install/step2.php @@ -3,7 +3,6 @@ $MESS ['STEP_NAME'] = 'Шаг 2'; $MESS ['MOD_NEXT_STEP'] = 'Следующий шаг'; $MESS ['MOD_PREV_STEP'] = 'Предыдущий шаг'; $MESS ['DELIVERY_TYPES_LIST'] = 'Способы доставки'; -$MESS ['DELIVERY_SERVICES_LIST'] = 'Автоматизированные службы доставок'; $MESS ['PAYMENT_TYPES_LIST'] = 'Способы оплаты'; $MESS ['PAYMENT_STATUS_LIST'] = 'Статусы'; $MESS ['ORDER_TYPES_LIST'] = 'Типы заказа'; diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 5b5be09f..442fccdb 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -52,6 +52,4 @@ $MESS ['HOUSE'] = 'Строение / корпус'; $MESS ['ADDRESS_SHORT'] = 'Краткий адрес'; $MESS ['ADDRESS_FULL'] = 'Детальный адрес'; -$MESS ['ORDER_TYPE_INFO'] = 'Тип заказа:'; - -$MESS ['DELIVERY_SERVICES_LIST'] = 'Автоматизированные службы доставок'; \ No newline at end of file +$MESS ['ORDER_TYPE_INFO'] = 'Тип заказа:'; \ No newline at end of file diff --git a/intaro.intarocrm/options.php b/intaro.intarocrm/options.php index 7b444d1d..8965a4ac 100755 --- a/intaro.intarocrm/options.php +++ b/intaro.intarocrm/options.php @@ -176,16 +176,10 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { ); //form delivery services ids arr - $deliveryServicesArr = array(); if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) { do { //auto delivery types $deliveryTypesArr[$arDeliveryServicesList['SID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryServicesList['SID']])); - foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) { - if(!$profile['TITLE']) continue; // services without name ? - $deliveryServicesArr[$arDeliveryServicesList['SID']][$id] = htmlspecialchars(trim($_POST['delivery-service-' . $arDeliveryServicesList['SID'] . '-' . $id])); - } - $arResult['bitrixDeliveryServicesList'][] = $arDeliveryServicesList; } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); } @@ -269,7 +263,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr)); - COption::SetOptionString($mid, $CRM_DELIVERY_SERVICES_ARR, serialize($deliveryServicesArr)); COption::SetOptionString($mid, $CRM_PAYMENT_TYPES, serialize($paymentTypesArr)); COption::SetOptionString($mid, $CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr)); COption::SetOptionString($mid, $CRM_PAYMENT, serialize($paymentArr)); @@ -357,7 +350,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) { do { $arResult['bitrixDeliveryTypesList'][] = array('ID' => $arDeliveryServicesList['SID'], 'NAME' => $arDeliveryServicesList['NAME']); - $arResult['bitrixDeliveryServicesList'][] = $arDeliveryServicesList; } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); } @@ -414,7 +406,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { //saved cat params $optionsOrderTypes = unserialize(COption::GetOptionString($mid, $CRM_ORDER_TYPES_ARR, 0)); $optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0)); - $optionsDelivServices = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_SERVICES_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)); @@ -518,34 +509,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { - - - - - $profile): if(!$profile['TITLE']) continue; ?> - - - [' . $bitrixDeliveryService['NAME'] . ']: ' . $profile['TITLE']; ?> - - - - - - - From 48a19f8ce5e9404481b99860351096f4cb5c8e85 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 27 Jan 2014 19:14:43 +0400 Subject: [PATCH 03/10] workin' ver --- .../classes/general/ICrmOrderActions.php | 31 +++++++++++++++++-- intaro.intarocrm/lang/ru/options.php | 1 - 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index c0370b2b..c0ef372f 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -370,7 +370,7 @@ class ICrmOrderActions // pushing existing orders foreach ($orderHistory as $order) { - if(!isset($order['externalId']) && !$order['externalId']) { + if(!isset($order['externalId']) || !$order['externalId']) { // we dont need new orders without any customers (can check only for externalId) if(!isset($order['customer']['externalId']) && !$order['customer']['externalId']) @@ -710,6 +710,16 @@ class ICrmOrderActions if($arFields['CANCELED'] == 'Y') $wasCanaceled = true; + $resultDeliveryTypeId = $optionsDelivTypes[$order['deliveryType']]; + + if(isset($order['deliveryService']) && !empty($order['deliveryService'])) { + if (strpos($order['deliveryService']['code'], "-") !== false) + $deliveryServiceCode = explode("-", $order['deliveryService']['code'], 2); + + if ($deliveryServiceCode) + $resultDeliveryTypeId = $resultDeliveryTypeId . ':' . $deliveryServiceCode[1]; + } + // orderUpdate $arFields = self::clearArr(array( 'PRICE_DELIVERY' => $order['deliveryCost'], @@ -719,7 +729,7 @@ class ICrmOrderActions 'PAY_SYSTEM_ID' => $optionsPayTypes[$order['paymentType']], //'PAYED' => $optionsPayment[$order['paymentStatus']], //'PERSON_TYPE_ID' => $optionsOrderTypes[$order['orderType']], - 'DELIVERY_ID' => $optionsDelivTypes[$order['deliveryType']], + 'DELIVERY_ID' => $resultDeliveryTypeId, 'STATUS_ID' => $optionsPayStatuses[$order['status']], 'REASON_CANCELED' => $order['statusComment'], 'USER_DESCRIPTION' => $order['customerComment'], @@ -884,6 +894,22 @@ class ICrmOrderActions else $resultDeliveryTypeId = $arFields['DELIVERY_ID']; + // deliveryService + $deliveryService = array(); + if(count($arId) > 1) { + $dbDeliveryType = CSaleDeliveryHandler::GetBySID($arId[0]); + + if ($arDeliveryType = $dbDeliveryType->GetNext()) { + foreach($arDeliveryType['PROFILES'] as $id => $profile) { + if($id == $arId[1]) { + $deliveryService = array( + 'code' => $arId[0] . '-' . $id, + 'name' => $profile['TITLE'] + ); + } + } + } + } $resOrder = array(); $resOrderDeliveryAddress = array(); @@ -993,6 +1019,7 @@ class ICrmOrderActions 'paymentStatus' => $arParams['optionsPayment'][$arFields['PAYED']], 'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']], 'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId], + 'deliveryService' => $deliveryService, 'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']], 'statusComment' => $arFields['REASON_CANCELED'], 'customerComment' => $arFields['USER_DESCRIPTION'], diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 442fccdb..cfee84b5 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -52,4 +52,3 @@ $MESS ['HOUSE'] = 'Строение / корпус'; $MESS ['ADDRESS_SHORT'] = 'Краткий адрес'; $MESS ['ADDRESS_FULL'] = 'Детальный адрес'; -$MESS ['ORDER_TYPE_INFO'] = 'Тип заказа:'; \ No newline at end of file From fb148315d7fd4a0f7a504ec7b207fb1a57635b51 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 28 Jan 2014 12:44:20 +0400 Subject: [PATCH 04/10] create users --- .../classes/general/ICrmOrderActions.php | 66 +++++++++++++++++-- intaro.intarocrm/classes/general/RestApi.php | 22 ++++++- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index c0ef372f..751460be 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -358,14 +358,22 @@ class ICrmOrderActions $optionsSites = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_SITES, 0)); $optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0)); + //use email as login for new customers + $loginEmail = true; + $api = new IntaroCrm\RestApi($api_host, $api_key); $dateStart = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY_DATE, null); + + if(!$dateStart) { + $dateStart = new \DateTime(); + $dateStart = $dateStart->format('Y-m-d H:i:s'); + } + $orderHistory = $api->orderHistory($dateStart); - if($dateStart) - $dateStart = new \DateTime($dateStart); + $dateStart = new \DateTime($dateStart); // pushing existing orders foreach ($orderHistory as $order) { @@ -373,8 +381,58 @@ class ICrmOrderActions if(!isset($order['externalId']) || !$order['externalId']) { // we dont need new orders without any customers (can check only for externalId) - if(!isset($order['customer']['externalId']) && !$order['customer']['externalId']) - continue; + if(!isset($order['customer']['externalId']) && !$order['customer']['externalId']) { + if($loginEmail) { + if (!$order['email']) { + $login = 'user_' . (microtime(true) * 100); + $server_name = 0 < strlen(SITE_SERVER_NAME)? + SITE_SERVER_NAME : 'server.com'; + $order['email'] = $login . '@' . $server_name; + $registerNewUser = true; + } else { + // if email already used + $dbUser = CUser::GetList(($by = 'ID'), ($sort = 'ASC'), array('=EMAIL' => $order['email'])); + if ($dbUser->SelectedRowsCount() == 0) { + $loginEmail ? $login = $order['email'] : $login = 'user_' . (microtime(true) * 100); + $registerNewUser = true; + } elseif ($dbUser->SelectedRowsCount() == 1) { + $arUser = $dbUser->Fetch(); + $registeredUserID = $arUser['ID']; + } else { + $loginEmail ? $login = $order['email'] : $login = 'user_' . (microtime(true) * 100); + $registerNewUser = true; + } + } + + if($registerNewUser) { + $useCaptcha = COption::GetOptionString('main', 'captcha_registration', 'N'); + if ($useCaptcha == 'Y') + COption::SetOptionString('main', 'captcha_registration', 'N'); + $userPassword = randString(10); + $newUser = $USER->Register($login, $order['customer']['firstName'], $order['customer']['lastName'], + $userPassword, $userPassword, $order['email']); + if ($useCaptcha == 'Y') + COption::SetOptionString('main', 'captcha_registration', 'Y'); + if ($newUser['TYPE'] == 'ERROR') { + self::eventLog('ICrmOrderActions::orderHistory', 'CUser::Register', $newUser['MESSAGE']); + continue; + } else { + $registeredUserID = $USER->GetID(); + $USER->Logout(); + } + } + + $order['customer']['externalId'] = $registeredUserID; + } + + $api->customerFixExternalIds(array(array('id' => $order['customer']['id'], 'externalId' => $order['customer']['externalId']))); + + if ($api->getStatusCode() != 200) { + //handle err - write log & continue + self::eventLog('ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::customerFixExternalIds', $api->getLastError()); + continue; + } + } // new order $newOrderFields = array( diff --git a/intaro.intarocrm/classes/general/RestApi.php b/intaro.intarocrm/classes/general/RestApi.php index 3050e68e..3200b2db 100644 --- a/intaro.intarocrm/classes/general/RestApi.php +++ b/intaro.intarocrm/classes/general/RestApi.php @@ -122,12 +122,12 @@ class RestApi /** * Обновление externalId у заказов с переданными id * - * @param array $orders- массив, содержащий id и externalId заказа + * @param array $orders - массив, содержащий id и externalId заказа * @return array */ - public function orderFixExternalIds($order) + public function orderFixExternalIds($orders) { - $dataJson = json_encode($order); + $dataJson = json_encode($orders); $this->parameters['orders'] = $dataJson; $url = $this->apiUrl.'orders/fix-external-ids'; @@ -241,6 +241,22 @@ class RestApi return $result; } + /** + * Обновление externalId у клиентов с переданными id + * + * @param array $customers- массив, содержащий id и externalId заказа + * @return array + */ + public function customerFixExternalIds($customers) + { + $dataJson = json_encode($customers); + $this->parameters['customers'] = $dataJson; + + $url = $this->apiUrl.'customers/fix-external-ids'; + $result = $this->curlRequest($url, 'POST'); + return $result; + } + /** * Удаление клиента * From f08b54033e724395a983e7ef1548d5eebb40ed5c Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 28 Jan 2014 12:53:36 +0400 Subject: [PATCH 05/10] email from customer obj --- intaro.intarocrm/classes/general/ICrmOrderActions.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 751460be..f16cbdd4 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -383,23 +383,23 @@ class ICrmOrderActions // we dont need new orders without any customers (can check only for externalId) if(!isset($order['customer']['externalId']) && !$order['customer']['externalId']) { if($loginEmail) { - if (!$order['email']) { + if (!$order['customer']['email']) { $login = 'user_' . (microtime(true) * 100); $server_name = 0 < strlen(SITE_SERVER_NAME)? SITE_SERVER_NAME : 'server.com'; - $order['email'] = $login . '@' . $server_name; + $order['customer']['email'] = $login . '@' . $server_name; $registerNewUser = true; } else { // if email already used $dbUser = CUser::GetList(($by = 'ID'), ($sort = 'ASC'), array('=EMAIL' => $order['email'])); if ($dbUser->SelectedRowsCount() == 0) { - $loginEmail ? $login = $order['email'] : $login = 'user_' . (microtime(true) * 100); + $loginEmail ? $login = $order['customer']['email'] : $login = 'user_' . (microtime(true) * 100); $registerNewUser = true; } elseif ($dbUser->SelectedRowsCount() == 1) { $arUser = $dbUser->Fetch(); $registeredUserID = $arUser['ID']; } else { - $loginEmail ? $login = $order['email'] : $login = 'user_' . (microtime(true) * 100); + $loginEmail ? $login = $order['customer']['email'] : $login = 'user_' . (microtime(true) * 100); $registerNewUser = true; } } @@ -410,7 +410,7 @@ class ICrmOrderActions COption::SetOptionString('main', 'captcha_registration', 'N'); $userPassword = randString(10); $newUser = $USER->Register($login, $order['customer']['firstName'], $order['customer']['lastName'], - $userPassword, $userPassword, $order['email']); + $userPassword, $userPassword, $order['customer']['email']); if ($useCaptcha == 'Y') COption::SetOptionString('main', 'captcha_registration', 'Y'); if ($newUser['TYPE'] == 'ERROR') { From 83f84ebb7f6d89ba3fc29392bf246100d472910d Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 28 Jan 2014 12:55:49 +0400 Subject: [PATCH 06/10] version fix --- intaro.intarocrm/install/version.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index eb218f79..0d5f1cb3 100644 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ "0.5.2", - "VERSION_DATE" => "2013-12-26 00:40:00", + "VERSION" => "0.5.3", + "VERSION_DATE" => "2014-01-28 12:55:00", ); \ No newline at end of file From 08c51694175ba3f39793b594b2358a1605959ca8 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 28 Jan 2014 17:44:21 +0400 Subject: [PATCH 07/10] fix orderHistory init time; --- .../classes/general/ICrmOrderActions.php | 37 +++++++++++-------- .../classes/general/events/ICrmOrderEvent.php | 4 +- intaro.intarocrm/install/index.php | 4 +- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index f16cbdd4..d499a58f 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -20,6 +20,7 @@ class ICrmOrderActions /** * Mass order uploading, without repeating; always returns true, but writes error log + * @param $pSize * @param $failed -- flag to export failed orders * @return boolean */ @@ -365,7 +366,6 @@ class ICrmOrderActions $dateStart = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY_DATE, null); - if(!$dateStart) { $dateStart = new \DateTime(); $dateStart = $dateStart->format('Y-m-d H:i:s'); @@ -373,8 +373,15 @@ class ICrmOrderActions $orderHistory = $api->orderHistory($dateStart); + echo $dateStart; + echo '
'; + $dateStart = new \DateTime($dateStart); + echo json_encode($orderHistory); + + self::eventLog('ICrmOrderActions::orderHistory', 'history_log', json_encode($orderHistory)); + // pushing existing orders foreach ($orderHistory as $order) { @@ -399,7 +406,7 @@ class ICrmOrderActions $arUser = $dbUser->Fetch(); $registeredUserID = $arUser['ID']; } else { - $loginEmail ? $login = $order['customer']['email'] : $login = 'user_' . (microtime(true) * 100); + $login = 'user_' . (microtime(true) * 100); $registerNewUser = true; } } @@ -504,7 +511,7 @@ class ICrmOrderActions break; } - if (count($optionsOrderProps[$arFields['PERSON_TYPE_ID']] > 4)) { + if (count($optionsOrderProps[$arFields['PERSON_TYPE_ID']]) > 4) { switch ($ar['CODE']) { /* case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['country']: $resOrderDeliveryAddress['country'] = self::toJSON($ar['VALUE']); break; @@ -573,7 +580,7 @@ class ICrmOrderActions if (isset($order['deliveryAddress']['text'])) self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['text'], self::fromJSON($order['deliveryAddress']['text']), $order['externalId']); - if (count($optionsOrderProps[$arFields['PERSON_TYPE_ID']] > 4)) { + if (count($optionsOrderProps[$arFields['PERSON_TYPE_ID']]) > 4) { if (isset($order['deliveryAddress']['street'])) self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['street'], self::fromJSON($order['deliveryAddress']['street']), $order['externalId']); @@ -875,10 +882,10 @@ class ICrmOrderActions * * creates order or returns array of order and customer for mass upload * - * @param type $orderId - * @param type $api - * @param type $arParams - * @param type $send + * @param array $arFields + * @param $api + * @param $arParams + * @param $send * @return boolean * @return array - array('order' = $order, 'customer' => $customer) */ @@ -1117,7 +1124,7 @@ class ICrmOrderActions * removes all empty fields from arrays * working with nested arrs * - * @param type $arr + * @param array $arr * @return boolean */ public static function clearArr($arr) { @@ -1137,9 +1144,9 @@ class ICrmOrderActions /** * - * @global type $APPLICATION - * @param type $str in SITE_CHARSET - * @return type $str in utf-8 + * @global $APPLICATION + * @param $str in SITE_CHARSET + * @return $str in utf-8 */ public static function toJSON($str) { global $APPLICATION; @@ -1149,9 +1156,9 @@ class ICrmOrderActions /** * - * @global type $APPLICATION - * @param type $str in utf-8 - * @return type $str in SITE_CHARSET + * @global $APPLICATION + * @param $str in utf-8 + * @return $str in SITE_CHARSET */ public static function fromJSON($str) { global $APPLICATION; diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index 0ebb4e3b..d2bc424f 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -75,7 +75,9 @@ class ICrmOrderEvent { /** * writeDataOnOrderCreate via api * - * @param integer $ID - Order Id + * @param $ID - Order Id + * @param array $arFields + * @return boolean */ function writeDataOnOrderCreate($ID, $arFields) { diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 6fe9aa43..e09548ab 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -807,7 +807,6 @@ class intaro_intarocrm extends CModule { COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_DISCHARGE, 1); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS, serialize(array())); - COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_HISTORY_DATE, date('Y-m-d H:i:s')); $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), @@ -1159,6 +1158,9 @@ class intaro_intarocrm extends CModule { $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key); $this->INTARO_CRM_API->statisticUpdate(); + // in fin order + COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_HISTORY_DATE, date('Y-m-d H:i:s')); + $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step6.php' From a8f746d1bd4d4683fd0f171a2fa2391422fd828a Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 28 Jan 2014 17:46:27 +0400 Subject: [PATCH 08/10] fix orderHistory init time; --- intaro.intarocrm/classes/general/ICrmOrderActions.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index d499a58f..a0ada56b 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -373,15 +373,10 @@ class ICrmOrderActions $orderHistory = $api->orderHistory($dateStart); - echo $dateStart; - echo '
'; - $dateStart = new \DateTime($dateStart); echo json_encode($orderHistory); - self::eventLog('ICrmOrderActions::orderHistory', 'history_log', json_encode($orderHistory)); - // pushing existing orders foreach ($orderHistory as $order) { From 2de20770554a36086953756ea2f8fb7b409311ca Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Wed, 29 Jan 2014 18:42:52 +0400 Subject: [PATCH 09/10] opt export DeliveryServices --- .../classes/general/ICrmOrderActions.php | 93 +++++++++---------- intaro.intarocrm/install/index.php | 1 + .../lang/ru/icml_export_setup.php | 17 +--- intaro.intarocrm/lang/ru/options.php | 3 +- intaro.intarocrm/options.php | 63 +++++++++++++ 5 files changed, 109 insertions(+), 68 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index a0ada56b..004d859f 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -359,9 +359,6 @@ class ICrmOrderActions $optionsSites = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_SITES, 0)); $optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0)); - //use email as login for new customers - $loginEmail = true; - $api = new IntaroCrm\RestApi($api_host, $api_key); $dateStart = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY_DATE, null); @@ -375,8 +372,6 @@ class ICrmOrderActions $dateStart = new \DateTime($dateStart); - echo json_encode($orderHistory); - // pushing existing orders foreach ($orderHistory as $order) { @@ -384,58 +379,56 @@ class ICrmOrderActions // we dont need new orders without any customers (can check only for externalId) if(!isset($order['customer']['externalId']) && !$order['customer']['externalId']) { - if($loginEmail) { - if (!$order['customer']['email']) { - $login = 'user_' . (microtime(true) * 100); - $server_name = 0 < strlen(SITE_SERVER_NAME)? - SITE_SERVER_NAME : 'server.com'; - $order['customer']['email'] = $login . '@' . $server_name; + if (!$order['customer']['email']) { + $login = 'user_' . (microtime(true) * 100); + $server_name = 0 < strlen(SITE_SERVER_NAME)? + SITE_SERVER_NAME : 'server.com'; + $order['customer']['email'] = $login . '@' . $server_name; + $registerNewUser = true; + } else { + // if email already used + $dbUser = CUser::GetList(($by = 'ID'), ($sort = 'ASC'), array('=EMAIL' => $order['email'])); + if ($dbUser->SelectedRowsCount() == 0) { + $login = $order['customer']['email']; $registerNewUser = true; + } elseif ($dbUser->SelectedRowsCount() == 1) { + $arUser = $dbUser->Fetch(); + $registeredUserID = $arUser['ID']; } else { - // if email already used - $dbUser = CUser::GetList(($by = 'ID'), ($sort = 'ASC'), array('=EMAIL' => $order['email'])); - if ($dbUser->SelectedRowsCount() == 0) { - $loginEmail ? $login = $order['customer']['email'] : $login = 'user_' . (microtime(true) * 100); - $registerNewUser = true; - } elseif ($dbUser->SelectedRowsCount() == 1) { - $arUser = $dbUser->Fetch(); - $registeredUserID = $arUser['ID']; - } else { - $login = 'user_' . (microtime(true) * 100); - $registerNewUser = true; - } + $login = 'user_' . (microtime(true) * 100); + $registerNewUser = true; } - - if($registerNewUser) { - $useCaptcha = COption::GetOptionString('main', 'captcha_registration', 'N'); - if ($useCaptcha == 'Y') - COption::SetOptionString('main', 'captcha_registration', 'N'); - $userPassword = randString(10); - $newUser = $USER->Register($login, $order['customer']['firstName'], $order['customer']['lastName'], - $userPassword, $userPassword, $order['customer']['email']); - if ($useCaptcha == 'Y') - COption::SetOptionString('main', 'captcha_registration', 'Y'); - if ($newUser['TYPE'] == 'ERROR') { - self::eventLog('ICrmOrderActions::orderHistory', 'CUser::Register', $newUser['MESSAGE']); - continue; - } else { - $registeredUserID = $USER->GetID(); - $USER->Logout(); - } + } + if($registerNewUser) { + $useCaptcha = COption::GetOptionString('main', 'captcha_registration', 'N'); + if ($useCaptcha == 'Y') + COption::SetOptionString('main', 'captcha_registration', 'N'); + $userPassword = randString(10); + $newUser = $USER->Register($login, $order['customer']['firstName'], $order['customer']['lastName'], + $userPassword, $userPassword, $order['customer']['email']); + if ($useCaptcha == 'Y') + COption::SetOptionString('main', 'captcha_registration', 'Y'); + if ($newUser['TYPE'] == 'ERROR') { + self::eventLog('ICrmOrderActions::orderHistory', 'CUser::Register', $newUser['MESSAGE']); + continue; + } else { + $registeredUserID = $USER->GetID(); + $USER->Logout(); } - - $order['customer']['externalId'] = $registeredUserID; } - $api->customerFixExternalIds(array(array('id' => $order['customer']['id'], 'externalId' => $order['customer']['externalId']))); - - if ($api->getStatusCode() != 200) { - //handle err - write log & continue - self::eventLog('ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::customerFixExternalIds', $api->getLastError()); - continue; - } + $order['customer']['externalId'] = $registeredUserID; } + $api->customerFixExternalIds(array(array('id' => $order['customer']['id'], 'externalId' => $order['customer']['externalId']))); + + if ($api->getStatusCode() != 200) { + //handle err - write log & continue + self::eventLog('ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::customerFixExternalIds', $api->getLastError()); + continue; + } + + // new order $newOrderFields = array( 'LID' => $defaultSiteId, @@ -1120,7 +1113,7 @@ class ICrmOrderActions * working with nested arrs * * @param array $arr - * @return boolean + * @return array */ public static function clearArr($arr) { if(!$arr || !is_array($arr)) diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index e09548ab..2163f70f 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -668,6 +668,7 @@ class intaro_intarocrm extends CModule { do { //auto delivery types $deliveryTypesArr[$arDeliveryServicesList['SID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryServicesList['SID']])); + } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); } } elseif (htmlspecialchars(trim($_POST['delivery-types-export'])) == 'true') { diff --git a/intaro.intarocrm/lang/ru/icml_export_setup.php b/intaro.intarocrm/lang/ru/icml_export_setup.php index 4b2983b6..7dc07010 100644 --- a/intaro.intarocrm/lang/ru/icml_export_setup.php +++ b/intaro.intarocrm/lang/ru/icml_export_setup.php @@ -23,21 +23,6 @@ $MESS["PROPERTY_OFFER_HEADER_NAME"] = "Свойство торгового пр $MESS["PROPERTY_ARTICLE_HEADER_NAME"] = "Артикул"; $MESS["PROPERTY_MANUFACTURER_HEADER_NAME"] = "Производитель"; $MESS["PROPERTY_COLOR_HEADER_NAME"] = "Цвет"; -$MESS["PROPERTY_WEIGHT_HEADER_NAME"] = "Вес (габариты)"; -$MESS["PROPERTY_LENGTH_HEADER_NAME"] = "Длина (габариты)"; -$MESS["PROPERTY_WIDTH_HEADER_NAME"] = "Ширина (габариты)"; -$MESS["PROPERTY_HEIGHT_HEADER_NAME"] = "Высота (габариты)"; +$MESS["PROPERTY_WEIGHT_HEADER_NAME"] = "Вес"; $MESS["PROPERTY_SIZE_HEADER_NAME"] = "Размер"; -$MESS["SELECT_FIELD_NAME"] = "Поле"; -$MESS["SELECT_PROPERTY_NAME"] = "Свойства"; -$MESS["SELECT_WEIGHT_PROPERTY_NAME"] = "Вec (грамм)"; -$MESS["SELECT_LENGTH_PROPERTY_NAME"] = "Длина (мм.)"; -$MESS["SELECT_WIDTH_PROPERTY_NAME"] = "Ширина (мм.)"; -$MESS["SELECT_HEIGHT_PROPERTY_NAME"] = "Высота (мм.)"; -$MESS["UNIT_MEASUREMENT_MM"] = "мм."; -$MESS["UNIT_MEASUREMENT_CM"] = "см."; -$MESS["UNIT_MEASUREMENT_M"] = "м."; -$MESS["UNIT_MEASUREMENT_MG"] = "мг."; -$MESS["UNIT_MEASUREMENT_G"] = "г."; -$MESS["UNIT_MEASUREMENT_KG"] = "кг."; ?> \ No newline at end of file diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index cfee84b5..0eed5b14 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -50,5 +50,4 @@ $MESS ['FLOOR'] = 'Этаж'; $MESS ['BLOCK'] = 'Подъезд'; $MESS ['HOUSE'] = 'Строение / корпус'; $MESS ['ADDRESS_SHORT'] = 'Краткий адрес'; -$MESS ['ADDRESS_FULL'] = 'Детальный адрес'; - +$MESS ['ADDRESS_FULL'] = 'Детальный адрес'; \ No newline at end of file diff --git a/intaro.intarocrm/options.php b/intaro.intarocrm/options.php index 8965a4ac..fcc7a5a8 100755 --- a/intaro.intarocrm/options.php +++ b/intaro.intarocrm/options.php @@ -92,6 +92,69 @@ $arResult['orderProps'] = array( ) ); +//ajax update deliveryServices +if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) { + $result = array(); + + $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); + + //check connection & apiKey valid + if ((int) $api->getStatusCode() != 200) { + $APPLICATION->RestartBuffer(); + header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); + die(json_encode(array('success' => false, 'errMsg' => $api->getStatusCode()))); + } + + $optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0)); + + // bitrix deliveryServicesList + $dbDeliveryServicesList = CSaleDeliveryHandler::GetList( + array( + 'SORT' => 'ASC', + 'NAME' => 'ASC' + ), + array( + 'ACTIVE' => 'Y' + ) + ); + + if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) { + do { + + if(!$optionsDelivTypes[$arDeliveryServicesList['SID']]) { + self::eventLog('options.php', 'No delivery type relations established', $arDeliveryServicesList['SID'] . ':' . $id); + continue; + } + + foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) { + + // send to crm + $this->INTARO_CRM_API->deliveryServiceEdit(ICrmOrderActions::clearArr(array( + 'code' => $arDeliveryServicesList['SID'] . '-' . $id, + 'name' => ICrmOrderActions::toJSON($profile['TITLE']), + 'deliveryType' => $arDeliveryServicesList['SID'] + ))); + + // error pushing dt + if ($this->INTARO_CRM_API->getStatusCode() != 200) { + if ($this->INTARO_CRM_API->getStatusCode() != 201) { + //handle err + self::eventLog('options.php', 'IntaroCrm\RestApi::deliveryServiceEdit', $this->INTARO_CRM_API->getLastError()); + } + } + } + + } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); + } + + $APPLICATION->RestartBuffer(); + header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); + die(json_encode(array('success' => true))); +} + //update connection settings if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $api_host = htmlspecialchars(trim($_POST['api_host'])); From 4469c448611e09fb01224ef9ff85f7f890722ff8 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 30 Jan 2014 12:17:58 +0400 Subject: [PATCH 10/10] deliveryServices export in options.php; several fixes. --- .../lang/ru/icml_export_setup.php | 18 ++++++- intaro.intarocrm/lang/ru/options.php | 8 ++- intaro.intarocrm/options.php | 51 ++++++++++++++++--- 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/intaro.intarocrm/lang/ru/icml_export_setup.php b/intaro.intarocrm/lang/ru/icml_export_setup.php index 7dc07010..22becf48 100644 --- a/intaro.intarocrm/lang/ru/icml_export_setup.php +++ b/intaro.intarocrm/lang/ru/icml_export_setup.php @@ -23,6 +23,20 @@ $MESS["PROPERTY_OFFER_HEADER_NAME"] = "Свойство торгового пр $MESS["PROPERTY_ARTICLE_HEADER_NAME"] = "Артикул"; $MESS["PROPERTY_MANUFACTURER_HEADER_NAME"] = "Производитель"; $MESS["PROPERTY_COLOR_HEADER_NAME"] = "Цвет"; -$MESS["PROPERTY_WEIGHT_HEADER_NAME"] = "Вес"; +$MESS["PROPERTY_WEIGHT_HEADER_NAME"] = "Вес (габариты)"; +$MESS["PROPERTY_LENGTH_HEADER_NAME"] = "Длина (габариты)"; +$MESS["PROPERTY_WIDTH_HEADER_NAME"] = "Ширина (габариты)"; +$MESS["PROPERTY_HEIGHT_HEADER_NAME"] = "Высота (габариты)"; $MESS["PROPERTY_SIZE_HEADER_NAME"] = "Размер"; -?> \ No newline at end of file +$MESS["SELECT_FIELD_NAME"] = "Поле"; +$MESS["SELECT_PROPERTY_NAME"] = "Свойства"; +$MESS["SELECT_WEIGHT_PROPERTY_NAME"] = "Вec (грамм)"; +$MESS["SELECT_LENGTH_PROPERTY_NAME"] = "Длина (мм.)"; +$MESS["SELECT_WIDTH_PROPERTY_NAME"] = "Ширина (мм.)"; +$MESS["SELECT_HEIGHT_PROPERTY_NAME"] = "Высота (мм.)"; +$MESS["UNIT_MEASUREMENT_MM"] = "мм."; +$MESS["UNIT_MEASUREMENT_CM"] = "см."; +$MESS["UNIT_MEASUREMENT_M"] = "м."; +$MESS["UNIT_MEASUREMENT_MG"] = "мг."; +$MESS["UNIT_MEASUREMENT_G"] = "г."; +$MESS["UNIT_MEASUREMENT_KG"] = "кг."; \ No newline at end of file diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 0eed5b14..dfb341ba 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -50,4 +50,10 @@ $MESS ['FLOOR'] = 'Этаж'; $MESS ['BLOCK'] = 'Подъезд'; $MESS ['HOUSE'] = 'Строение / корпус'; $MESS ['ADDRESS_SHORT'] = 'Краткий адрес'; -$MESS ['ADDRESS_FULL'] = 'Детальный адрес'; \ No newline at end of file +$MESS ['ADDRESS_FULL'] = 'Детальный адрес'; + +$MESS ['UPDATE_DELIVERY_SERVICES'] = 'Выгрузка служб доставок'; + +$MESS ['MESS_1'] = 'Произошла ошибка при выгрузке одной или нескольких служб доставок, попробуйте еще раз. Если проблема повторилась, обратитесь в Интаро Софт.'; +$MESS ['MESS_2'] = 'Произошла ошибка сервера, обратитесь в Интаро Софт.'; + diff --git a/intaro.intarocrm/options.php b/intaro.intarocrm/options.php index fcc7a5a8..44708b42 100755 --- a/intaro.intarocrm/options.php +++ b/intaro.intarocrm/options.php @@ -101,6 +101,8 @@ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_RE $api = new IntaroCrm\RestApi($api_host, $api_key); + $api->paymentStatusesList(); + //check connection & apiKey valid if ((int) $api->getStatusCode() != 200) { $APPLICATION->RestartBuffer(); @@ -125,24 +127,24 @@ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_RE do { if(!$optionsDelivTypes[$arDeliveryServicesList['SID']]) { - self::eventLog('options.php', 'No delivery type relations established', $arDeliveryServicesList['SID'] . ':' . $id); + ICrmOrderActions::eventLog('options.php', 'No delivery type relations established', $arDeliveryServicesList['SID'] . ':' . $id); continue; } foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) { // send to crm - $this->INTARO_CRM_API->deliveryServiceEdit(ICrmOrderActions::clearArr(array( + $api->deliveryServiceEdit(ICrmOrderActions::clearArr(array( 'code' => $arDeliveryServicesList['SID'] . '-' . $id, 'name' => ICrmOrderActions::toJSON($profile['TITLE']), 'deliveryType' => $arDeliveryServicesList['SID'] ))); // error pushing dt - if ($this->INTARO_CRM_API->getStatusCode() != 200) { - if ($this->INTARO_CRM_API->getStatusCode() != 201) { + if ($api->getStatusCode() != 200) { + if ($api->getStatusCode() != 201) { //handle err - self::eventLog('options.php', 'IntaroCrm\RestApi::deliveryServiceEdit', $this->INTARO_CRM_API->getLastError()); + ICrmOrderActions::eventLog('options.php', 'IntaroCrm\RestApi::deliveryServiceEdit', $api->getLastError()); } } } @@ -518,10 +520,42 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $('tr.address-detail-' + orderType).hide('slow'); }); }); + + $('input[name="update-delivery-services"]').live('click', function() { + BX.showWait(); + var updButton = this; + // hide next step button + $(updButton).css('opacity', '0.5').attr('disabled', 'disabled'); + + var handlerUrl = $(this).parents('form').attr('action'); + var data = 'ajax=1'; + + $.ajax({ + type: 'POST', + url: handlerUrl, + data: data, + dataType: 'json', + success: function(response) { + BX.closeWait(); + $(updButton).css('opacity', '1').removeAttr('disabled'); + + if(!response.success) + alert(''); + }, + error: function () { + BX.closeWait(); + $(updButton).css('opacity', '1').removeAttr('disabled'); + + alert(''); + } + }); + + return false; + });
-BeginNextTab(); ?> @@ -572,6 +606,11 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { + + + + +