diff --git a/intaro.intarocrm/classes/general/ICMLLoader.php b/intaro.intarocrm/classes/general/ICMLLoader.php index db1ce1f5..db0b587e 100644 --- a/intaro.intarocrm/classes/general/ICMLLoader.php +++ b/intaro.intarocrm/classes/general/ICMLLoader.php @@ -25,6 +25,8 @@ class ICMLLoader { protected $logFile = '/bitrix/catalog_export/i_crm_load_log.txt'; protected $fpLog; + protected $MODULE_ID = 'intaro.intarocrm'; + protected $CRM_CATALOG_BASE_PRICE = 'catalog_base_price'; protected $measurement = array ( 'mm' => 1, // 1 mm = 1 mm @@ -218,6 +220,10 @@ class ICMLLoader { protected function BuildOffers(&$allCategories) { + + $basePriceId = COption::GetOptionString($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE, 1); + + foreach ($this->iblocks as $key => $id) { // Get Info by infoblocks @@ -238,7 +244,7 @@ class ICMLLoader { "DETAIL_PICTURE", "LANG_DIR", "DETAIL_PAGE_URL", - "CATALOG_GROUP_1" + "CATALOG_GROUP_" . $basePriceId ); // Set selected properties foreach ($this->propertiesProduct[$id] as $key => $propProduct) { @@ -256,7 +262,7 @@ class ICMLLoader { "DETAIL_PAGE_URL", "DETAIL_PICTURE", 'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'], - "CATALOG_GROUP_1" + "CATALOG_GROUP_" . $basePriceId ); // Set selected properties foreach ($this->propertiesSKU[$id] as $key => $propSKU) { @@ -394,7 +400,7 @@ class ICMLLoader { $offer['PICTURE'] = $product["PICTURE"]; $offer['PRODUCT_NAME'] = $product["NAME"]; $offer['PRODUCT_ACTIVE'] = $product["ACTIVE"]; - $offer['PRICE'] = $offer['CATALOG_PRICE_1']; + $offer['PRICE'] = $offer['CATALOG_PRICE_' . $basePriceId]; $offer['PURCHASE_PRICE'] = $offer['CATALOG_PURCHASING_PRICE']; $offer['QUANTITY'] = $offer["CATALOG_QUANTITY"]; diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 180fe864..333c739b 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -606,7 +606,7 @@ class ICrmOrderActions if(isset($order['externalId']) && $order['externalId']) { - // custom orderType functunion + // custom orderType function if(function_exists('intarocrm_set_order_type')) { $orderType = intarocrm_set_order_type($order); if($orderType) @@ -821,6 +821,12 @@ class ICrmOrderActions if (!$p) { $p = CIBlockElement::GetByID($item['offer']['externalId'])->Fetch(); + // select iblock to obtain an CATALOG_XML_ID + $iblock = CIBlock::GetByID($p['IBLOCK_ID'])->Fetch(); + $p['CATALOG_XML_ID'] = $iblock['XML_ID']; + // product field XML_ID is called PRODUCT_XML_ID in basket + $p['PRODUCT_XML_ID'] = $p['XML_ID']; + unset($p['XML_ID']); } else { //for basket props updating (in props we save cancel status) @@ -973,27 +979,28 @@ class ICrmOrderActions //'PERSON_TYPE_ID' => $optionsOrderTypes[$order['orderType']], 'DELIVERY_ID' => $resultDeliveryTypeId, 'STATUS_ID' => $optionsPayStatuses[$order['status']], - 'REASON_CANCELED' => $order['statusComment'], - 'USER_DESCRIPTION' => $order['customerComment'], - 'COMMENTS' => $order['managerComment'] + 'REASON_CANCELED' => self::fromJSON($order['statusComment']), + 'USER_DESCRIPTION' => self::fromJSON($order['customerComment']), + 'COMMENTS' => self::fromJSON($order['managerComment']) )); - CSaleOrder::Update($order['externalId'], $arFields); + if(!empty($arFields)) + CSaleOrder::Update($order['externalId'], $arFields); // set STATUS_ID - if($order['status'] && $optionsPayStatuses[$order['status']]) + if(isset($order['status']) && $order['status'] && $optionsPayStatuses[$order['status']]) CSaleOrder::StatusOrder($order['externalId'], $optionsPayStatuses[$order['status']]); // uncancel order - if($wasCanaceled && ($optionsPayStatuses[$order['status']] != 'YY')) + if(isset($order['status']) && $order['status'] && $wasCanaceled && ($optionsPayStatuses[$order['status']] != 'YY')) CSaleOrder::CancelOrder($order['externalId'], "N", $order['statusComment']); // cancel order - if($optionsPayStatuses[$order['status']] == 'YY') + if(isset($order['status']) && $order['status'] && $optionsPayStatuses[$order['status']] == 'YY') CSaleOrder::CancelOrder($order['externalId'], "Y", $order['statusComment']); // set PAYED - if($optionsPayment[$order['paymentStatus']]) + if(isset($order['paymentStatus']) && $order['paymentStatus'] && $optionsPayment[$order['paymentStatus']]) CSaleOrder::PayOrder($order['externalId'], $optionsPayment[$order['paymentStatus']]); } } @@ -1053,6 +1060,19 @@ class ICrmOrderActions return 'ICrmOrderActions::orderHistoryAgent();'; } + /** + * + * Agent function + * + * @return self name + */ + + public static function orderAgent() { + self::uploadOrdersAgent(); + self::orderHistory(); + return 'ICrmOrderActions::orderAgent();'; + } + /** * * creates order or returns array of order and customer for mass upload @@ -1087,6 +1107,11 @@ class ICrmOrderActions $lastName = self::toJSON($arUser['LAST_NAME']); $patronymic = self::toJSON($arUser['SECOND_NAME']); + // convert encoding for comment + $statusComment = self::toJson($arFields['REASON_CANCELED']); + $customerComment = self::toJson($arFields['USER_DESCRIPTION']); + $managerComment = self::toJson($arFields['COMMENTS']); + $phones = array(); $phonePersonal = array( @@ -1114,26 +1139,6 @@ class ICrmOrderActions 'createdAt' => $createdAt )); - if($send) { - try { - $customer = $api->customerEdit($customer); - } catch (\IntaroCrm\Exception\ApiException $e) { - self::eventLog( - 'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit', - $e->getCode() . ': ' . $e->getMessage() - ); - - return false; - } catch (\IntaroCrm\Exception\CurlException $e) { - self::eventLog( - 'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit::CurlException', - $e->getCode() . ': ' . $e->getMessage() - ); - - return false; - } - } - // delivery types $arId = array(); if (strpos($arFields['DELIVERY_ID'], ":") !== false) @@ -1284,6 +1289,7 @@ class ICrmOrderActions } $resOrder = array( + 'customer' => $customer, 'number' => $arFields['ACCOUNT_NUMBER'], 'phone' => $resOrder['phone'], 'email' => $resOrder['email'], @@ -1298,9 +1304,9 @@ class ICrmOrderActions /*'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId], 'deliveryService' => ($arParams['optionsDelivTypes'][$resultDeliveryTypeId]) ? $deliveryService : '',*/ 'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']], - 'statusComment' => $arFields['REASON_CANCELED'], - 'customerComment' => $arFields['USER_DESCRIPTION'], - 'managerComment' => $arFields['COMMENTS'], + 'statusComment' => $statusComment, + 'customerComment' => $customerComment, + 'managerComment' => $managerComment, 'createdAt' => $createdAt, //'deliveryAddress' => $resOrderDeliveryAddress, 'delivery' => $delivery, @@ -1308,7 +1314,6 @@ class ICrmOrderActions 'items' => $items ); - if(isset($arParams['optionsSites']) && is_array($arParams['optionsSites']) && in_array($arFields['LID'], $arParams['optionsSites'])) $resOrder['site'] = $arFields['LID']; @@ -1322,7 +1327,7 @@ class ICrmOrderActions $resOrder['patronymic'] = $contactNameArr[2]; } - // custom orderType functunion + // custom orderType function if(function_exists('intarocrm_get_order_type')) { $orderType = intarocrm_get_order_type($arFields); if($orderType) @@ -1331,9 +1336,42 @@ class ICrmOrderActions $orderType['orderType'] = 'new'; } + // custom order & customer fields function + if(function_exists('intarocrm_before_order_send')) { + $newResOrder = intarocrm_before_order_send($resOrder); + + if(is_array($newResOrder) && !empty($newResOrder)) + $resOrder = $newResOrder; + + } + $resOrder = self::clearArr($resOrder); + if(isset($resOrder['customer']) && is_array($resOrder['customer']) && !empty($resOrder['customer'])) { + $customer = $resOrder['customer']; + unset($resOrder['customer']); + } + if($send) { + + try { + $customer = $api->customerEdit($customer); + } catch (\IntaroCrm\Exception\ApiException $e) { + self::eventLog( + 'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit', + $e->getCode() . ': ' . $e->getMessage() + ); + + return false; + } catch (\IntaroCrm\Exception\CurlException $e) { + self::eventLog( + 'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit::CurlException', + $e->getCode() . ': ' . $e->getMessage() + ); + + return false; + } + try { return $api->orderEdit($resOrder); } catch (\IntaroCrm\Exception\ApiException $e) { diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index c12dcb53..0bc1adbf 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -25,6 +25,27 @@ class ICrmOrderEvent { $GLOBALS['INTARO_CRM_ORDER_ADD'] = true; return; } + + /** + * OnSaleBeforeReserveOrder + * + * @param mixed $arFields - Order arFields + */ + function OnSaleBeforeReserveOrder($arFields = array()) { + $GLOBALS['INTARO_CRM_ORDER_RESERVE'] = true; + return; + } + + /** + * OnSaleReserveOrder + * + * @param mixed $arFields - Order arFields + */ + function OnSaleReserveOrder($arFields = array()) { + if(isset($GLOBALS['INTARO_CRM_ORDER_RESERVE']) && $GLOBALS['INTARO_CRM_ORDER_RESERVE']) + unset($GLOBALS['INTARO_CRM_ORDER_RESERVE']); + return; + } /** * onUpdateOrder @@ -36,6 +57,9 @@ class ICrmOrderEvent { if(isset($GLOBALS['INTARO_CRM_ORDER_ADD']) && $GLOBALS['INTARO_CRM_ORDER_ADD']) return; + + if(isset($GLOBALS['INTARO_CRM_ORDER_RESERVE']) && $GLOBALS['INTARO_CRM_ORDER_RESERVE']) + return; if(isset($GLOBALS['INTARO_CRM_FROM_HISTORY']) && $GLOBALS['INTARO_CRM_FROM_HISTORY']) return; @@ -302,5 +326,7 @@ class ICrmOrderEvent { function onBeforeOrderAccountNumberSet($ID, $value) { if(isset($GLOBALS['ICRM_ACCOUNT_NUMBER']) && $GLOBALS['ICRM_ACCOUNT_NUMBER']) return $GLOBALS['ICRM_ACCOUNT_NUMBER']; + + return false; } } \ No newline at end of file diff --git a/intaro.intarocrm/export/export_setup.php b/intaro.intarocrm/export/export_setup.php index f4c666a5..ac2390b9 100644 --- a/intaro.intarocrm/export/export_setup.php +++ b/intaro.intarocrm/export/export_setup.php @@ -15,6 +15,19 @@ if(!check_bitrix_sessid()) return; __IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/icml_export_setup.php")); +$MODULE_ID = 'intaro.intarocrm'; +$CRM_CATALOG_BASE_PRICE = 'catalog_base_price'; +$basePriceId = COption::GetOptionString($MODULE_ID, $CRM_CATALOG_BASE_PRICE, 1); + +$arResult['PRICE_TYPES'] = array(); +$dbPriceType = CCatalogGroup::GetList( + array("SORT" => "ASC"), array(), array(), array(), array("ID", "NAME", "BASE") +); + +while ($arPriceType = $dbPriceType->Fetch()) { + $arResult['PRICE_TYPES'][$arPriceType['ID']] = $arPriceType; +} + if (($ACTION == 'EXPORT' || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && $STEP == 1) { @@ -550,6 +563,20 @@ if ($STEP==1) <br> <br> + <font class="text"><?=GetMessage("BASE_PRICE");?> </font> + <select name="price-types" class="typeselect"> + <option value=""></option> + <?php foreach($arResult['PRICE_TYPES'] as $priceType): ?> + <option value="<?php echo $priceType['ID']; ?>" + <?php if($priceType['ID'] == $basePriceId) echo 'selected'; ?>> + <?php echo $priceType['NAME']; ?> + </option> + <?php endforeach; ?> + </select> + + <br> + <br> + <br> <?if ($ACTION=="EXPORT_SETUP" || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY'):?> <font class="text"><?=GetMessage("PROFILE_NAME");?><br><br></font> @@ -563,7 +590,6 @@ if ($STEP==1) <br> <?endif;?> - <script type="text/javascript" src="/bitrix/js/main/jquery/jquery-1.7.min.js"></script> <script type="text/javascript"> function checkAll(obj,cnt) @@ -667,6 +693,7 @@ if ($STEP==1) } elseif ($STEP==2) { + COption::SetOptionString($MODULE_ID, $CRM_CATALOG_BASE_PRICE, htmlspecialchars(trim($_POST['price-types']))); $FINITE = true; } diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 75c5fe38..461a47e6 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -36,6 +36,7 @@ class intaro_intarocrm extends CModule { var $CRM_ORDER_DISCHARGE = 'order_discharge'; var $CRM_ORDER_FAILED_IDS = 'order_failed_ids'; var $CRM_ORDER_HISTORY_DATE = 'order_history_date'; + var $CRM_CATALOG_BASE_PRICE = 'catalog_base_price'; var $INSTALL_PATH; function intaro_intarocrm() { @@ -980,6 +981,17 @@ class intaro_intarocrm extends CModule { if (!CModule::IncludeModule("catalog")) { $arResult['errCode'] = 'ERR_CATALOG'; } + + $arResult['PRICE_TYPES'] = array(); + + $dbPriceType = CCatalogGroup::GetList( + array("SORT" => "ASC"), array(), array(), array(), array("ID", "NAME", "BASE") + ); + + while ($arPriceType = $dbPriceType->Fetch()) { + $arResult['PRICE_TYPES'][$arPriceType['ID']] = $arPriceType; + } + $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step5.php' @@ -1095,6 +1107,11 @@ class intaro_intarocrm extends CModule { RegisterModuleDependences("sale", "OnOrderNewSendEmail", $this->MODULE_ID, "ICrmOrderEvent", "onSendOrderMail"); RegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "ICrmOrderEvent", "onUpdateOrder"); RegisterModuleDependences("sale", "OnBeforeOrderAdd", $this->MODULE_ID, "ICrmOrderEvent", "onBeforeOrderAdd"); + RegisterModuleDependences("sale", "OnSaleBeforeReserveOrder", $this->MODULE_ID, "ICrmOrderEvent", "OnSaleBeforeReserveOrder"); + RegisterModuleDependences("sale", "OnSaleReserveOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleReserveOrder"); + + COption::SetOptionString($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE, htmlspecialchars(trim($_POST['price-types']))); + $this->CopyFiles(); if (isset($_POST['LOAD_NOW'])) { @@ -1208,29 +1225,17 @@ class intaro_intarocrm extends CModule { } //agent - $dateAgent = new DateTime(); $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec; $dateAgent->add($intAgent); CAgent::AddAgent( - "ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID, "N", 600, // interval - 10 mins + "ICrmOrderActions::orderAgent();", $this->MODULE_ID, "N", 600, // interval - 10 mins $dateAgent->format('d.m.Y H:i:s'), // date of first check "Y", // agent is active $dateAgent->format('d.m.Y H:i:s'), // date of first start 30 ); - - CAgent::AddAgent( - "ICrmOrderActions::orderHistoryAgent();", - $this->MODULE_ID, - "N", - 600, // interval - 10 mins - $dateAgent->format('d.m.Y H:i:s'), // date of first check - "Y", // agent is active - $dateAgent->format('d.m.Y H:i:s'), // date of first start - 30 - ); $api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0); @@ -1264,6 +1269,7 @@ class intaro_intarocrm extends CModule { CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID); CAgent::RemoveAgent("ICrmOrderActions::orderHistoryAgent();", $this->MODULE_ID); + CAgent::RemoveAgent("ICrmOrderActions::orderAgent();", $this->MODULE_ID); COption::RemoveOption($this->MODULE_ID, $this->CRM_API_HOST_OPTION); COption::RemoveOption($this->MODULE_ID, $this->CRM_API_KEY_OPTION); @@ -1277,6 +1283,7 @@ class intaro_intarocrm extends CModule { COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_DISCHARGE); COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS); COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_HISTORY_DATE); + COption::RemoveOption($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE); UnRegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder"); UnRegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); @@ -1284,6 +1291,8 @@ class intaro_intarocrm extends CModule { UnRegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "ICrmOrderEvent", "onUpdateOrder"); UnRegisterModuleDependences("sale", "OnBeforeOrderAdd", $this->MODULE_ID, "ICrmOrderEvent", "onBeforeOrderAdd"); UnRegisterModuleDependences("sale", "OnBeforeOrderAccountNumberSet", $this->MODULE_ID, "ICrmOrderEvent", "onBeforeOrderAccountNumberSet"); + UnRegisterModuleDependences("sale", "OnSaleBeforeReserveOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleBeforeReserveOrder"); + UnRegisterModuleDependences("sale", "OnSaleReserveOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleReserveOrder"); if (CModule::IncludeModule("catalog")) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/' . $this->INTARO_CRM_EXPORT . '_run.php')) { $dbProfile = CCatalogExport::GetList(array(), array("FILE_NAME" => $this->INTARO_CRM_EXPORT)); diff --git a/intaro.intarocrm/install/step5.php b/intaro.intarocrm/install/step5.php index ec67d21b..2c172979 100644 --- a/intaro.intarocrm/install/step5.php +++ b/intaro.intarocrm/install/step5.php @@ -477,6 +477,18 @@ if (!empty($oldValues)) { <input id="load-now" type="checkbox" name="LOAD_NOW" value="now" checked > <br> <br> + <font class="text"><?=GetMessage("BASE_PRICE");?> </font> + <select name="price-types" class="typeselect"> + <option value=""></option> + <?php foreach($arResult['PRICE_TYPES'] as $priceType): ?> + <option value="<?php echo $priceType['ID']; ?>" + <?php if($priceType['BASE'] == 'Y') echo 'selected'; ?>> + <?php echo $priceType['NAME']; ?> + </option> + <?php endforeach; ?> + </select> + <br> + <br> <br> <div id="profile-field" > diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index 818ce40e..4ec990a5 100644 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ <? $arModuleVersion = array( - "VERSION" => "1.0.5", - "VERSION_DATE" => "2014-05-16 13:42:00", + "VERSION" => "1.0.7", + "VERSION_DATE" => "2014-05-29 19:33:00" ); diff --git a/intaro.intarocrm/lang/ru/icml_export_setup.php b/intaro.intarocrm/lang/ru/icml_export_setup.php index 76a3818f..67985777 100644 --- a/intaro.intarocrm/lang/ru/icml_export_setup.php +++ b/intaro.intarocrm/lang/ru/icml_export_setup.php @@ -40,4 +40,5 @@ $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 +$MESS["UNIT_MEASUREMENT_KG"] = "кг."; +$MESS['BASE_PRICE'] = 'Базовая цена'; \ No newline at end of file diff --git a/intaro.intarocrm/lang/ru/install/step5.php b/intaro.intarocrm/lang/ru/install/step5.php index c1abb978..d6ce27c1 100755 --- a/intaro.intarocrm/lang/ru/install/step5.php +++ b/intaro.intarocrm/lang/ru/install/step5.php @@ -21,4 +21,5 @@ $MESS ['PROFILE_NAME_EXAMPLE'] = 'Выгрузка каталога IntaroCRM'; $MESS ['ERR_FIELDS_PROFILE'] = 'Неверно заполнено поле имени профиля'; $MESS ['ERR_FIELDS_IBLOCK'] = 'Не выбрано ни одного информационного блока'; $MESS ['ERR_FIELDS_ARTICLE'] = 'Не выбраны артикулы'; -$MESS ['ERR_FIELDS_FILE'] = 'Не указано имя файла'; \ No newline at end of file +$MESS ['ERR_FIELDS_FILE'] = 'Не указано имя файла'; +$MESS ['BASE_PRICE'] = 'Базовая цена'; \ No newline at end of file