From f684763ea9985bb2f04e719c1aae5208d0f367ad Mon Sep 17 00:00:00 2001 From: "m.korolev" Date: Mon, 2 Sep 2013 17:40:21 +0400 Subject: [PATCH 01/13] At now articles load from Product InfoBlock --- intaro.intarocrm/classes/general/ICMLLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intaro.intarocrm/classes/general/ICMLLoader.php b/intaro.intarocrm/classes/general/ICMLLoader.php index fa9a725a..cb5715c5 100644 --- a/intaro.intarocrm/classes/general/ICMLLoader.php +++ b/intaro.intarocrm/classes/general/ICMLLoader.php @@ -220,7 +220,7 @@ class ICMLLoader { $arOffer['PREVIEW_PICTURE'] = $product["PREVIEW_PICTURE"]; $arOffer['PRODUCT_NAME'] = $product["NAME"]; if (isset($this->articleProperties[$id])) - $arOffer['ARTICLE'] = $arOffer["PROPERTY_" . $this->articleProperties[$id] . "_VALUE"]; + $arOffer['ARTICLE'] = $product["PROPERTY_" . $this->articleProperties[$id] . "_VALUE"]; $dbPrice = GetCatalogProductPrice($arOffer["ID"],1); $arOffer['PRICE'] = $dbPrice['PRICE']; From c1c298b4eb729cb67e597b4c69d6be34dccad066 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 3 Sep 2013 13:22:05 +0400 Subject: [PATCH 02/13] timezone fix; v0.3.9.1 --- intaro.intarocrm/install/index.php | 7 +++++++ intaro.intarocrm/lang/ru/install/index.php | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index a36d588c..f3456341 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -64,6 +64,13 @@ class intaro_intarocrm extends CModule return false; } + if (!date_default_timezone_get()) { + if (!ini_get('date.timezone')) { + $APPLICATION->ThrowException(GetMessage("DATE_TIMEZONE_ERR")); + return false; + } + } + include($this->INSTALL_PATH . '/../classes/general/RestApi.php'); include($this->INSTALL_PATH . '/../classes/general/ICrmOrderActions.php'); include($this->INSTALL_PATH . '/../classes/general/ICMLLoader.php'); diff --git a/intaro.intarocrm/lang/ru/install/index.php b/intaro.intarocrm/lang/ru/install/index.php index 4637485b..60196348 100755 --- a/intaro.intarocrm/lang/ru/install/index.php +++ b/intaro.intarocrm/lang/ru/install/index.php @@ -11,4 +11,5 @@ $MESS ['ERR_IBLOCK'] = 'Отсутствует модуль iblock! Дальне $MESS ['ERR_CATALOG'] = 'Отсутствует модуль catalog! Дальнейшая установка невозможна.'; $MESS ['ERR_CATALOG'] = 'Отсутствует модуль catalog! Дальнейшая установка невозможна.'; $MESS ['INTAROCRM_CURL_ERR'] = 'Для работы модуля интеграции с IntaroCRM требуется PHP-расширение CURL.'; -$MESS ['ERR_ARTICLE_IBLOCK'] = 'Не установлены артикулы'; \ No newline at end of file +$MESS ['ERR_ARTICLE_IBLOCK'] = 'Не установлены артикулы'; +$MESS ['DATE_TIMEZONE_ERR'] = 'Не указана временная зона в настройках php.'; \ No newline at end of file From a3a72718f82820aff7e65df0bb174f280d561a4e Mon Sep 17 00:00:00 2001 From: "m.korolev" Date: Wed, 4 Sep 2013 12:20:33 +0400 Subject: [PATCH 03/13] At now categories load from IB of product --- .../classes/general/ICMLLoader.php | 38 +++++++++++++++---- intaro.intarocrm/export/export_setup.php | 2 +- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICMLLoader.php b/intaro.intarocrm/classes/general/ICMLLoader.php index cb5715c5..13181e37 100644 --- a/intaro.intarocrm/classes/general/ICMLLoader.php +++ b/intaro.intarocrm/classes/general/ICMLLoader.php @@ -22,7 +22,11 @@ class ICMLLoader { $categories = $this->GetCategories(); - $offers = $this->GetOffers(); + $newCategories = array(); + $offers = $this->GetOffers($newCategories); + foreach ($newCategories as $newCategory) { + $categories[] = $this->BuildCategory($newCategory); + } $this->PrepareFile(); @@ -141,8 +145,8 @@ class ICMLLoader { } - protected function GetOffers() - { + protected function GetOffers(&$newCategories) + { $offers = Array(); foreach ($this->iblocks as $key => $id) { @@ -205,12 +209,21 @@ class ICMLLoader { $rsOffers = CIBlockElement::GetList(array(), $arFilterOffer, false, false, $arSelectOffer); while ($arOffer = $rsOffers->GetNext()) { - $dbResCategories = CIBlockElement::GetElementGroups($arOffer['ID'], true); + $dbResCategories = CIBlockElement::GetElementGroups($product['ID'], true); while ($arResCategory = $dbResCategories->Fetch()) { $categoriesString .= "" . $arResCategory["ID"] . "\n"; } - if ($categoriesString == '') - $categoriesString .= "" . ($this->mainSection + $id) . "\n"; + if ($categoriesString == '') { + + $catId = $this->mainSection + $id; + $categoriesString .= "" . ($catId) . "\n"; + + $category = array(); + $category['ID'] = $catId; + $category['NAME'] = 'Основная группа инфоблока ' . $iblock['IBLOCK_DB']['NAME']; + + $newCategories[$catId] = $category; + } $offer = CCatalogProduct::GetByID($arOffer['ID']); $arOffer['QUANTITY'] = $offer["QUANTITY"]; @@ -236,8 +249,17 @@ class ICMLLoader { while ($arResCategory = $dbResCategories->Fetch()) { $categoriesString .= "" . $arResCategory["ID"] . "\n"; } - if ($categoriesString == '') - $categoriesString .= "" . ($this->mainSection + $id) . "\n"; + if ($categoriesString == '') { + + $catId = $this->mainSection + $id; + $categoriesString .= "" . ($catId) . "\n"; + + $category = array(); + $category['ID'] = $catId; + $category['NAME'] = 'Основная группа инфоблока ' . $iblock['IBLOCK_DB']['NAME']; + + $newCategories[$catId] = $category; + } $offer = CCatalogProduct::GetByID($product['ID']); $product['QUANTITY'] = $offer["QUANTITY"]; diff --git a/intaro.intarocrm/export/export_setup.php b/intaro.intarocrm/export/export_setup.php index d0c92f81..1fafdeee 100644 --- a/intaro.intarocrm/export/export_setup.php +++ b/intaro.intarocrm/export/export_setup.php @@ -190,7 +190,7 @@ if ($STEP==1) if ($arIBlock['OLD_PROPERTY_SELECT'] == $prop["CODE"]){ echo " selected"; } else { - if ($arIBlock['OLD_PROPERTY_SELECT'] != "") { + if ($arIBlock['OLD_PROPERTY_SELECT'] == "") { if ($prop["CODE"] == "ARTICLE" || $prop["CODE"] == "ART" || $prop["CODE"] == "ARTNUMBER" ) From 8d7ee7b1328691b7bb625c1ce44f89cc13a9bbbd Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 5 Sep 2013 09:38:38 +0400 Subject: [PATCH 04/13] fix 0.3.11 --- intaro.intarocrm/install/version.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index 7f630053..2f95ded1 100755 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ "0.3.9", - "VERSION_DATE" => "2013-08-21 18:32:00", -); \ No newline at end of file + "VERSION" => "0.3.11", + "VERSION_DATE" => "2013-09-05 09:40:00", +); From 0812440edc6bdbfd33b7f7577ab4a1113dcebc38 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 9 Sep 2013 16:26:01 +0400 Subject: [PATCH 05/13] fixed fio parsing --- .../classes/general/ICrmOrderActions.php | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index b4e6e634..36cd518f 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -252,6 +252,7 @@ class ICrmOrderActions $resOrder = array(); $resOrderDeliveryAddress = array(); + $contactNameArr = array(); $rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID'])); while ($ar = $rsOrderProps->Fetch()) { @@ -267,7 +268,7 @@ class ICrmOrderActions $resOrderDeliveryAddress['city'] = self::toJSON($resOrderDeliveryAddress['city']['CITY_NAME_LANG']); } break; - case 'FIO': $resOrder['contactName'] = explode(" ", self::toJSON($ar['VALUE'])); + case 'FIO': $contactNameArr = self::explodeFIO($ar['VALUE']); break; case 'PHONE': $resOrder['phone'] = $ar['VALUE']; break; @@ -306,10 +307,7 @@ class ICrmOrderActions $createdAt = new \DateTime($arFields['DATE_INSERT']); $createdAt = $createdAt->format('Y-m-d H:i:s'); - $resOrder = self::clearArr(array( - 'lastName' => $resOrder['contactName'][0], - 'firstName' => $resOrder['contactName'][1], - 'patronymic' => $resOrder['contactName'][2], + $resOrder = array( 'phone' => $resOrder['phone'], 'email' => $resOrder['email'], 'deliveryCost' => $arFields['PRICE_DELIVERY'], @@ -326,7 +324,18 @@ class ICrmOrderActions 'createdAt' => $createdAt, 'deliveryAddress' => $resOrderDeliveryAddress, 'items' => $items - )); + ); + + // parse fio + if(count($contactNameArr) == 1) { + $resOrder['firstName'] = $contactNameArr[0]; + } else { + $resOrder['lastName'] = $contactNameArr['contactName'][0], + $resOrder['firstName'] = $contactNameArr['contactName'][1], + $resOrder['patronymic'] = $contactNameArr['contactName'][2], + } + + $resOrder = self::clearArr($resOrder); if($send) return $api->createOrder($resOrder); @@ -382,4 +391,17 @@ class ICrmOrderActions return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET); } + + public static function expodeFIO($str) { + if(!$str) + return array(); + + $array = expolde(" ", ICrmOrderActions::toJSON($str), 3); + + foreach($array as &$ar) + if(!$ar) + unset($ar); + + return $array; + } } From 2ccc2999e617743d9ff114725f675be6c45da0c6 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 9 Sep 2013 16:35:22 +0400 Subject: [PATCH 06/13] fixes --- intaro.intarocrm/classes/general/ICrmOrderActions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 36cd518f..89382065 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -330,9 +330,9 @@ class ICrmOrderActions if(count($contactNameArr) == 1) { $resOrder['firstName'] = $contactNameArr[0]; } else { - $resOrder['lastName'] = $contactNameArr['contactName'][0], - $resOrder['firstName'] = $contactNameArr['contactName'][1], - $resOrder['patronymic'] = $contactNameArr['contactName'][2], + $resOrder['lastName'] = $contactNameArr['contactName'][0]; + $resOrder['firstName'] = $contactNameArr['contactName'][1]; + $resOrder['patronymic'] = $contactNameArr['contactName'][2]; } $resOrder = self::clearArr($resOrder); From fc469781b2ec2fd0540d1558166cc0bf7f0c6d94 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 9 Sep 2013 17:53:58 +0400 Subject: [PATCH 07/13] fix explode --- intaro.intarocrm/classes/general/ICrmOrderActions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 89382065..8c180f01 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -396,7 +396,7 @@ class ICrmOrderActions if(!$str) return array(); - $array = expolde(" ", ICrmOrderActions::toJSON($str), 3); + $array = explode(" ", self::toJSON($str), 3); foreach($array as &$ar) if(!$ar) From 0397aad60261b071d148acf3f4ed63dd7f6c0998 Mon Sep 17 00:00:00 2001 From: "m.korolev" Date: Tue, 10 Sep 2013 09:25:17 +0400 Subject: [PATCH 08/13] Before commit: Collect data about categories, then format this, collect data about offers, then format this, and then write all to file. After commit: Collect all data, then format all data and write all --- .../classes/general/ICMLLoader.php | 124 ++++++++++-------- 1 file changed, 68 insertions(+), 56 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICMLLoader.php b/intaro.intarocrm/classes/general/ICMLLoader.php index 13181e37..7a578eae 100644 --- a/intaro.intarocrm/classes/general/ICMLLoader.php +++ b/intaro.intarocrm/classes/general/ICMLLoader.php @@ -22,12 +22,8 @@ class ICMLLoader { $categories = $this->GetCategories(); - $newCategories = array(); - $offers = $this->GetOffers($newCategories); - foreach ($newCategories as $newCategory) { - $categories[] = $this->BuildCategory($newCategory); - } - + $offers = $this->GetOffers($categories); + $this->PrepareFile(); $this->PreWriteCatalog(); @@ -76,7 +72,7 @@ class ICMLLoader { { @fwrite($this->fp, "\n"); foreach ($categories as $category) { - @fwrite($this->fp, $category . "\n"); + @fwrite($this->fp, $this->BuildCategory($category) . "\n"); } @fwrite($this->fp, "\n"); } @@ -84,7 +80,7 @@ class ICMLLoader { { @fwrite($this->fp, "\n"); foreach ($offers as $offer) { - @fwrite($this->fp, $offer . "\n"); + @fwrite($this->fp, $this->BuildOffer($offer['OFFER'], $offer['CATEGORIES'], $offer['IBLOCK']) . "\n"); } @fwrite($this->fp, "\n"); } @@ -117,7 +113,7 @@ class ICMLLoader { $dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter); while ($arRes = $dbRes->Fetch()) { - $categories[] = $this->BuildCategory($arRes); + $categories[] = $arRes; } if (count($categories) == 0) { @@ -125,7 +121,7 @@ class ICMLLoader { $arRes['ID'] = $this->mainSection + $id; $arRes['IBLOCK_SECTION_ID'] = 0; $arRes['NAME'] = "Основной раздел каталога"; - $categories[] = $this->BuildCategory($arRes); + $categories[] = $arRes; } } return $categories; @@ -145,7 +141,7 @@ class ICMLLoader { } - protected function GetOffers(&$newCategories) + protected function GetOffers(&$allCategories) { $offers = Array(); foreach ($this->iblocks as $key => $id) @@ -187,14 +183,14 @@ class ICMLLoader { $product = $product->GetFields(); - $categoriesString = ""; + $categories = Array(); $existOffer = false; if (!empty($iblockOffer['IBLOCK_ID'])) { $arFilterOffer = Array ( 'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'], - 'PROPERTY_'.$iblockOffer['SKU_PROPERTY_ID'] => $product["ID"] + 'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => $product["ID"] ); $arSelectOffer = Array ( 'ID', @@ -205,25 +201,29 @@ class ICMLLoader { ); if (isset($this->articleProperties[$id])) $arSelectOffer[] = "PROPERTY_" . $this->articleProperties[$id]; + + $dbResCategories = CIBlockElement::GetElementGroups($product['ID'], true); + while ($arResCategory = $dbResCategories->Fetch()) { + $categories[$arResCategory["ID"]] = array( + 'ID' => $arResCategory["ID"], + 'NAME' => $arResCategory["NAME"], + ); + } + if (count($categories) == 0) { + + $catId = $this->mainSection + $id;; + + $category = array(); + $category['ID'] = $catId; + $category['NAME'] = 'Основная группа инфоблока ' . $iblock['IBLOCK_DB']['NAME']; + + $categories[$catId] = $category; + $allCategories[$catId] = $category; + } $rsOffers = CIBlockElement::GetList(array(), $arFilterOffer, false, false, $arSelectOffer); while ($arOffer = $rsOffers->GetNext()) { - $dbResCategories = CIBlockElement::GetElementGroups($product['ID'], true); - while ($arResCategory = $dbResCategories->Fetch()) { - $categoriesString .= "" . $arResCategory["ID"] . "\n"; - } - if ($categoriesString == '') { - - $catId = $this->mainSection + $id; - $categoriesString .= "" . ($catId) . "\n"; - - $category = array(); - $category['ID'] = $catId; - $category['NAME'] = 'Основная группа инфоблока ' . $iblock['IBLOCK_DB']['NAME']; - - $newCategories[$catId] = $category; - } $offer = CCatalogProduct::GetByID($arOffer['ID']); $arOffer['QUANTITY'] = $offer["QUANTITY"]; @@ -238,41 +238,52 @@ class ICMLLoader { $dbPrice = GetCatalogProductPrice($arOffer["ID"],1); $arOffer['PRICE'] = $dbPrice['PRICE']; - - - $offers[] = $this->BuildOffer($arOffer, $categoriesString, $iblock); + $offers[] = Array( + 'OFFER' => $arOffer, + 'CATEGORIES' => $categories, + 'IBLOCK' => $iblock + ); + $existOffer = true; } } if (!$existOffer) { - $dbResCategories = CIBlockElement::GetElementGroups($product["ID"], true); - while ($arResCategory = $dbResCategories->Fetch()) { - $categoriesString .= "" . $arResCategory["ID"] . "\n"; - } - if ($categoriesString == '') { - - $catId = $this->mainSection + $id; - $categoriesString .= "" . ($catId) . "\n"; + + $dbResCategories = CIBlockElement::GetElementGroups($product["ID"], true); + while ($arResCategory = $dbResCategories->Fetch()) { + $categories[$arResCategory["ID"]] = array( + 'ID' => $arResCategory["ID"], + 'NAME' => $arResCategory["NAME"], + ); + } + if (count($categories) == 0) { - $category = array(); - $category['ID'] = $catId; - $category['NAME'] = 'Основная группа инфоблока ' . $iblock['IBLOCK_DB']['NAME']; + $catId = $this->mainSection + $id; + $category = array(); + $category['ID'] = $catId; + $category['NAME'] = 'Основная группа инфоблока ' . $iblock['IBLOCK_DB']['NAME']; - $newCategories[$catId] = $category; - } + $categories[$catId] = $category; + $allCategories[$catId] = $category; + } - $offer = CCatalogProduct::GetByID($product['ID']); - $product['QUANTITY'] = $offer["QUANTITY"]; + + $offer = CCatalogProduct::GetByID($product['ID']); + $product['QUANTITY'] = $offer["QUANTITY"]; - $product['PRODUCT_ID'] = $product["ID"]; - $product['PRODUCT_NAME'] = $product["NAME"]; - if (isset($this->articleProperties[$id])) - $product['ARTICLE'] = $product["PROPERTY_" . $this->articleProperties[$id] . "_VALUE"]; + $product['PRODUCT_ID'] = $product["ID"]; + $product['PRODUCT_NAME'] = $product["NAME"]; + if (isset($this->articleProperties[$id])) + $product['ARTICLE'] = $product["PROPERTY_" . $this->articleProperties[$id] . "_VALUE"]; - $dbPrice = GetCatalogProductPrice($product["ID"],1); - $product['PRICE'] = $dbPrice['PRICE']; + $dbPrice = GetCatalogProductPrice($product["ID"],1); + $product['PRICE'] = $dbPrice['PRICE']; - $offers[] = $this->BuildOffer($product, $categoriesString, $iblock); + $offers[] = Array( + 'OFFER' => $product, + 'CATEGORIES' => $categories, + 'IBLOCK' => $iblock + ); } } } @@ -280,8 +291,8 @@ class ICMLLoader { } - protected function BuildOffer($arOffer, $categoriesString, $iblock) - { + protected function BuildOffer($arOffer, $categories, $iblock) + { $offer = ""; $offer .= "PrepareValue($arOffer["ID"]) . "\" ". "productId=\"" . $this->PrepareValue($arOffer["PRODUCT_ID"]) . "\" ". @@ -289,7 +300,8 @@ class ICMLLoader { $offer .= "http://" . $this->PrepareValue($iblock['IBLOCK_DB']['SERVER_NAME']) . $this->PrepareValue($arOffer['DETAIL_PAGE_URL']) . "\n"; $offer .= "" . $this->PrepareValue($arOffer['PRICE']) . "\n"; - $offer .= $categoriesString; + foreach ($categories as $category) + $offer .= "" . $category['ID'] . "\n"; $detailPicture = intval($arOffer["DETAIL_PICTURE"]); $previewPicture = intval($arOffer["PREVIEW_PICTURE"]); From 5ef7ec6538e4a17abb5c60625b1f3836be0c5c3e Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 10 Sep 2013 17:15:41 +0400 Subject: [PATCH 09/13] mode change in options --- .../classes/general/ICrmOrderActions.php | 4 +- .../classes/general/events/ICrmOrderEvent.php | 5 +- intaro.intarocrm/lang/ru/options.php | 7 ++- intaro.intarocrm/options.php | 51 +++++++++++++++++++ 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 8c180f01..7a5c79d5 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -338,7 +338,7 @@ class ICrmOrderActions $resOrder = self::clearArr($resOrder); if($send) - return $api->createOrder($resOrder); + return $api->orderEdit($resOrder); return array( 'order' => $resOrder, @@ -392,7 +392,7 @@ class ICrmOrderActions return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET); } - public static function expodeFIO($str) { + public static function explodeFIO($str) { if(!$str) return array(); diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index 5e9470ff..13c19c78 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -21,8 +21,9 @@ class ICrmOrderEvent { * @param mixed $arFields - Order arFields */ function onUpdateOrder($ID, $arFields = array()) { - //self::writeDataOnOrderCreate($ID); + self::writeDataOnOrderCreate($ID); } + /** * onSendOrderMail @@ -61,7 +62,7 @@ class ICrmOrderEvent { } $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0); - $api_key = COption::GetOptionString(Iself::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0); + $api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0); //saved cat params $optionsOrderTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_TYPES_ARR, 0)); diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 34572124..688b15fa 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -22,4 +22,9 @@ $MESS ['ERR_403'] = 'Неверный apiKey.'; $MESS ['ERR_0'] = 'Превышено время ожидания ответа от сервера.'; $MESS ['ICRM_OPTIONS_OK'] = 'Изменения успешно сохранены.'; $MESS ['CANCELED'] = 'Флаг «Отменен»'; -$MESS ['INFO_1'] = ' Задайте соответствие между справочниками 1C-Битрикс и справочниками IntaroCRM.'; \ No newline at end of file +$MESS ['INFO_1'] = ' Задайте соответствие между справочниками 1C-Битрикс и справочниками IntaroCRM.'; + +$MESS ['ICRM_OPTIONS_ORDER_DISCHARGE_TAB'] = 'Режим выгрузки заказов'; +$MESS ['ORDER_DISCH'] = 'Режим выгрузки заказов'; +$MESS ['DISCHARGE_AGENT'] = 'Выгрузка заказов с помощью агента'; +$MESS ['DISCHARGE_EVENTS'] = 'Выгрузка заказов по событию'; \ No newline at end of file diff --git a/intaro.intarocrm/options.php b/intaro.intarocrm/options.php index 3f1d439a..e6122189 100755 --- a/intaro.intarocrm/options.php +++ b/intaro.intarocrm/options.php @@ -11,6 +11,7 @@ $CRM_PAYMENT_TYPES = 'pay_types_arr'; $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; $CRM_PAYMENT = 'payment_arr'; //order payment Y/N $CRM_ORDER_LAST_ID = 'order_last_id'; +$CRM_ORDER_DISCHARGE = 'order_discharge'; if(!CModule::IncludeModule('intaro.intarocrm') || !CModule::IncludeModule('sale')) @@ -132,11 +133,42 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y'])); $paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N'])); + $previousDischarge = COption::GetOptionString($mid, $CRM_ORDER_DISCHARGE, 0); + //order discharge mode + // 0 - agent + // 1 - event + $orderDischarge = 0; + $orderDischarge = (int) htmlspecialchars(trim($_POST['order-discharge'])); + + if (($orderDischarge != $previousDischarge) && ($orderDischarge == 0)) { + // remove depenedencies + UnRegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail"); + UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder"); + // new agent + $dateAgent = new DateTime(); + $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec; + $dateAgent->add($intAgent); + CAgent::AddAgent( + "ICrmOrderActions::uploadOrdersAgent();", $mid, "N", 600, // interval - 10 mins + $dateAgent->format('d.m.Y H:i:s'), // date of first check + "Y", // агент активен + $dateAgent->format('d.m.Y H:i:s'), // date of first start + 30 + ); + } else if (($orderDischarge != $previousDischarge) && ($orderDischarge == 1)) { + // remove agent + CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $mid); + // event dependencies + RegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail"); + RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder"); + } + COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr)); COption::SetOptionString($mid, $CRM_PAYMENT_TYPES, serialize($paymentTypesArr)); COption::SetOptionString($mid, $CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr)); COption::SetOptionString($mid, $CRM_PAYMENT, serialize($paymentArr)); + COption::SetOptionString($mid, $CRM_ORDER_DISCHARGE, $orderDischarge); $uri .= '&ok=Y'; LocalRedirect($uri); @@ -249,6 +281,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $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)); + $optionsDischarge = COption::GetOptionString($mid, $CRM_ORDER_DISCHARGE, 0); $aTabs = array( array( @@ -263,6 +296,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_CATALOG_CAPTION') ), + array( + "DIV" => "edit4", + "TAB" => GetMessage('ICRM_OPTIONS_ORDER_DISCHARGE_TAB'), + "ICON" => '', + "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_DISCHARGE_CAPTION') + ) ); $tabControl = new CAdminTabControl("tabControl", $aTabs); $tabControl->Begin(); @@ -394,6 +433,18 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { BeginNextTab(); ?> + + + + + + + + + + + + Buttons(); ?> From 6db7bc93e1de2158b58f0162ef77a58cf0877cae Mon Sep 17 00:00:00 2001 From: "m.korolev" Date: Wed, 11 Sep 2013 15:37:50 +0400 Subject: [PATCH 10/13] Writing offers to file has been paginate --- .../classes/general/ICMLLoader.php | 302 +++++++++--------- 1 file changed, 147 insertions(+), 155 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICMLLoader.php b/intaro.intarocrm/classes/general/ICMLLoader.php index 7a578eae..18715118 100644 --- a/intaro.intarocrm/classes/general/ICMLLoader.php +++ b/intaro.intarocrm/classes/general/ICMLLoader.php @@ -1,18 +1,18 @@ iblocks) < count($this->articleProperties)) return false; - $categories = $this->GetCategories(); - - $offers = $this->GetOffers($categories); - $this->PrepareFile(); $this->PreWriteCatalog(); - + + $categories = $this->GetCategories(); + $this->WriteCategories($categories); - $this->WriteOffers($offers); + + $this->PreWriteOffers(); + $this->BuildOffers($categories); + $this->PostWriteOffers(); $this->PostWriteCatalog(); $this->CloseFile(); return true; - - } - - protected function PrepareValue($text) + + } + + protected function PrepareValue($text) { $newText = $this->application->ConvertCharset($text, LANG_CHARSET, $this->encoding); $newText = strip_tags($newText); $newText = str_replace("&", "&", $newText); return $newText; } - - protected function PrepareFile() - { + + protected function PrepareFile() + { $fullFilename = $_SERVER["DOCUMENT_ROOT"] . $this->filename; CheckDirPath($fullFilename); @@ -55,10 +56,10 @@ class ICMLLoader { return false; else return true; - } - - protected function PreWriteCatalog() - { + } + + protected function PreWriteCatalog() + { @fwrite($this->fp, "PrepareValue(Date("Y-m-d H:i:s")) . "\">\n"); @fwrite($this->fp, "\n"); @@ -66,39 +67,47 @@ class ICMLLoader { @fwrite($this->fp, "".$this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."\n"); - } - - protected function WriteCategories($categories) - { + } + + protected function WriteCategories($categories) + { + $stringCategories = ""; @fwrite($this->fp, "\n"); foreach ($categories as $category) { - @fwrite($this->fp, $this->BuildCategory($category) . "\n"); + $stringCategories .= $this->BuildCategory($category); } + @fwrite($this->fp, $stringCategories); @fwrite($this->fp, "\n"); - } - protected function WriteOffers($offers) - { + } + protected function PreWriteOffers() + { @fwrite($this->fp, "\n"); - foreach ($offers as $offer) { - @fwrite($this->fp, $this->BuildOffer($offer['OFFER'], $offer['CATEGORIES'], $offer['IBLOCK']) . "\n"); - } + } + + protected function PostWriteOffers() + { @fwrite($this->fp, "\n"); - } - - protected function PostWriteCatalog() - { + } + + protected function WriteOffers($offers) + { + @fwrite($this->fp, $offers); + } + + protected function PostWriteCatalog() + { @fwrite($this->fp, "\n"); @fwrite($this->fp, "\n"); - } - - protected function CloseFile() - { + } + + protected function CloseFile() + { @fclose($this->fp); - } - - - protected function GetCategories() - { + } + + + protected function GetCategories() + { $categories = array(); foreach ($this->iblocks as $id) { @@ -109,27 +118,30 @@ class ICMLLoader { "GLOBAL_ACTIVE" => "Y" ); - $dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter); + $hasCategories = false; while ($arRes = $dbRes->Fetch()) { - $categories[] = $arRes; + $categories[$arRes['ID']] = $arRes; + $hasCategories = true; } - if (count($categories) == 0) + if (!$hasCategories) { + $iblock = CIBlock::GetByID($id)->Fetch(); + $arRes = Array(); $arRes['ID'] = $this->mainSection + $id; $arRes['IBLOCK_SECTION_ID'] = 0; - $arRes['NAME'] = "Основной раздел каталога"; - $categories[] = $arRes; + $arRes['NAME'] = "Основной раздел каталога " . $iblock['NAME']; + $categories[$arRes['ID']] = $arRes; } } return $categories; - } - - protected function BuildCategory($arCategory) - { + } + + protected function BuildCategory($arCategory) + { return " PrepareValue($arCategory["ID"]) . "\"" . ( intval($arCategory["IBLOCK_SECTION_ID"] ) > 0 ? @@ -137,13 +149,12 @@ class ICMLLoader { :"") . ">" . $this->PrepareValue($arCategory["NAME"]) - . ""; - - } - - protected function GetOffers(&$allCategories) + . "\n"; + + } + + protected function BuildOffers(&$allCategories) { - $offers = Array(); foreach ($this->iblocks as $key => $id) { @@ -177,97 +188,71 @@ class ICMLLoader { "ACTIVE" => "Y", "INCLUDE_SUBSECTIONS" => "Y" ); - + $count = 0; $dbResProducts = CIBlockElement::GetList(array(), $filter, false, false, $arSelect); + $stringOffers = ""; while ($product = $dbResProducts->GetNextElement()) { - + $product = $product->GetFields(); + // Get categories in InfoBlock $categories = Array(); + $dbResCategories = CIBlockElement::GetElementGroups($product['ID'], true); + while ($arResCategory = $dbResCategories->Fetch()) { + $categories[$arResCategory["ID"]] = array( + 'ID' => $arResCategory["ID"], + 'NAME' => $arResCategory["NAME"], + ); + } + if (count($categories) == 0) { + + $catId = $this->mainSection + $id; + $categories[$catId] = $allCategories[$catId]; + } - + $existOffer = false; if (!empty($iblockOffer['IBLOCK_ID'])) { - $arFilterOffer = Array ( - 'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'], - 'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => $product["ID"] - ); - $arSelectOffer = Array ( - 'ID', - "NAME", - "DETAIL_TEXT", - "DETAIL_PAGE_URL", - "DETAIL_PICTURE" - ); + + + $arFilterOffer = Array ( + 'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'], + 'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => $product["ID"] + ); + $arSelectOffer = Array ( + 'ID', + "NAME", + "DETAIL_TEXT", + "DETAIL_PAGE_URL", + "DETAIL_PICTURE" + ); + if (isset($this->articleProperties[$id])) + $arSelectOffer[] = "PROPERTY_" . $this->articleProperties[$id]; + + + $rsOffers = CIBlockElement::GetList(array(), $arFilterOffer, false, false, $arSelectOffer); + while ($arOffer = $rsOffers->GetNext()) { + + $offer = CCatalogProduct::GetByID($arOffer['ID']); + $arOffer['QUANTITY'] = $offer["QUANTITY"]; + + $arOffer['PRODUCT_ID'] = $product["ID"]; + $arOffer['DETAIL_PAGE_URL'] = $product["DETAIL_PAGE_URL"]; + $arOffer['DETAIL_PICTURE'] = $product["DETAIL_PICTURE"]; + $arOffer['PREVIEW_PICTURE'] = $product["PREVIEW_PICTURE"]; + $arOffer['PRODUCT_NAME'] = $product["NAME"]; if (isset($this->articleProperties[$id])) - $arSelectOffer[] = "PROPERTY_" . $this->articleProperties[$id]; - - $dbResCategories = CIBlockElement::GetElementGroups($product['ID'], true); - while ($arResCategory = $dbResCategories->Fetch()) { - $categories[$arResCategory["ID"]] = array( - 'ID' => $arResCategory["ID"], - 'NAME' => $arResCategory["NAME"], - ); - } - if (count($categories) == 0) { + $arOffer['ARTICLE'] = $product["PROPERTY_" . $this->articleProperties[$id] . "_VALUE"]; - $catId = $this->mainSection + $id;; + $dbPrice = GetCatalogProductPrice($arOffer["ID"],1); + $arOffer['PRICE'] = $dbPrice['PRICE']; - $category = array(); - $category['ID'] = $catId; - $category['NAME'] = 'Основная группа инфоблока ' . $iblock['IBLOCK_DB']['NAME']; - - $categories[$catId] = $category; - $allCategories[$catId] = $category; - } - - $rsOffers = CIBlockElement::GetList(array(), $arFilterOffer, false, false, $arSelectOffer); - while ($arOffer = $rsOffers->GetNext()) { - - $offer = CCatalogProduct::GetByID($arOffer['ID']); - $arOffer['QUANTITY'] = $offer["QUANTITY"]; - - $arOffer['PRODUCT_ID'] = $product["ID"]; - $arOffer['DETAIL_PAGE_URL'] = $product["DETAIL_PAGE_URL"]; - $arOffer['DETAIL_PICTURE'] = $product["DETAIL_PICTURE"]; - $arOffer['PREVIEW_PICTURE'] = $product["PREVIEW_PICTURE"]; - $arOffer['PRODUCT_NAME'] = $product["NAME"]; - if (isset($this->articleProperties[$id])) - $arOffer['ARTICLE'] = $product["PROPERTY_" . $this->articleProperties[$id] . "_VALUE"]; - - $dbPrice = GetCatalogProductPrice($arOffer["ID"],1); - $arOffer['PRICE'] = $dbPrice['PRICE']; - - $offers[] = Array( - 'OFFER' => $arOffer, - 'CATEGORIES' => $categories, - 'IBLOCK' => $iblock - ); - - $existOffer = true; - } + $stringOffers .= $this->BuildOffer($arOffer, $categories, $iblock); + $existOffer = true; + } } if (!$existOffer) { - $dbResCategories = CIBlockElement::GetElementGroups($product["ID"], true); - while ($arResCategory = $dbResCategories->Fetch()) { - $categories[$arResCategory["ID"]] = array( - 'ID' => $arResCategory["ID"], - 'NAME' => $arResCategory["NAME"], - ); - } - if (count($categories) == 0) { - - $catId = $this->mainSection + $id; - $category = array(); - $category['ID'] = $catId; - $category['NAME'] = 'Основная группа инфоблока ' . $iblock['IBLOCK_DB']['NAME']; - - $categories[$catId] = $category; - $allCategories[$catId] = $category; - } - - $offer = CCatalogProduct::GetByID($product['ID']); $product['QUANTITY'] = $offer["QUANTITY"]; @@ -279,24 +264,33 @@ class ICMLLoader { $dbPrice = GetCatalogProductPrice($product["ID"],1); $product['PRICE'] = $dbPrice['PRICE']; - $offers[] = Array( - 'OFFER' => $product, - 'CATEGORIES' => $categories, - 'IBLOCK' => $iblock - ); + $stringOffers .= $this->BuildOffer($product, $categories, $iblock); } + + $count++; + if ($count == 1000) { + $this->WriteOffers($stringOffers); + $stringOffers = ""; + } + } + + if ($stringOffers != "") { + $this->WriteOffers($stringOffers); + $stringOffers = ""; + } + } - return $offers; - } - - + } + + protected function BuildOffer($arOffer, $categories, $iblock) { $offer = ""; $offer .= "PrepareValue($arOffer["ID"]) . "\" ". "productId=\"" . $this->PrepareValue($arOffer["PRODUCT_ID"]) . "\" ". "quantity=\"" . $this->PrepareValue(DoubleVal($arOffer['QUANTITY'])) . "\">\n"; + $offer .= "http://" . $this->PrepareValue($iblock['IBLOCK_DB']['SERVER_NAME']) . $this->PrepareValue($arOffer['DETAIL_PAGE_URL']) . "\n"; $offer .= "" . $this->PrepareValue($arOffer['PRICE']) . "\n"; @@ -334,8 +328,6 @@ class ICMLLoader { $offer.= "\n"; return $offer; - } - - - + } + } \ No newline at end of file From c6e2a8c1b7895cfbb8126cb70e9f518491ad80b4 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 12 Sep 2013 11:32:50 +0400 Subject: [PATCH 11/13] fix order last id in event --- intaro.intarocrm/classes/general/events/ICrmOrderEvent.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index 13c19c78..dac49742 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -88,6 +88,8 @@ class ICrmOrderEvent { ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'ICrmOrderActions::orderCreate', 'error during creating order'); return true; } + + COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $ID); return true; } From 3e9f019f7e7dff409fe31d9d61d041138ee648c5 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 12 Sep 2013 16:27:43 +0400 Subject: [PATCH 12/13] fio fix --- .../classes/general/ICrmOrderActions.php | 18 +++++++++++------- .../classes/general/events/ICrmOrderEvent.php | 2 -- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 7a5c79d5..4d78e8ea 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -320,7 +320,7 @@ class ICrmOrderActions 'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']], 'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId], 'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']], - 'statusComment' => $arFields['REASON_CANCELED'], + 'statusComment' => $arFields['USER_DESCRIPTION'], 'createdAt' => $createdAt, 'deliveryAddress' => $resOrderDeliveryAddress, 'items' => $items @@ -330,9 +330,9 @@ class ICrmOrderActions if(count($contactNameArr) == 1) { $resOrder['firstName'] = $contactNameArr[0]; } else { - $resOrder['lastName'] = $contactNameArr['contactName'][0]; - $resOrder['firstName'] = $contactNameArr['contactName'][1]; - $resOrder['patronymic'] = $contactNameArr['contactName'][2]; + $resOrder['lastName'] = $contactNameArr[0]; + $resOrder['firstName'] = $contactNameArr[1]; + $resOrder['patronymic'] = $contactNameArr[2]; } $resOrder = self::clearArr($resOrder); @@ -397,11 +397,15 @@ class ICrmOrderActions return array(); $array = explode(" ", self::toJSON($str), 3); + $newArray = array(); - foreach($array as &$ar) + foreach($array as $ar) { if(!$ar) - unset($ar); + continue; + + $newArray[] = $ar; + } - return $array; + return $newArray; } } diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index dac49742..13c19c78 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -88,8 +88,6 @@ class ICrmOrderEvent { ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'ICrmOrderActions::orderCreate', 'error during creating order'); return true; } - - COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $ID); return true; } From 3f1840b323d342270958b0f28de3b520c8a7be97 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 12 Sep 2013 16:29:55 +0400 Subject: [PATCH 13/13] last id fix --- intaro.intarocrm/classes/general/events/ICrmOrderEvent.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index 13c19c78..7b7e8178 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -89,6 +89,8 @@ class ICrmOrderEvent { return true; } + COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $ID); + return true; }