From d8b2b3bab22f741d5705fb108cafbf62dfa160b2 Mon Sep 17 00:00:00 2001 From: "m.korolev" Date: Mon, 29 Jul 2013 17:58:41 +0400 Subject: [PATCH 01/23] Add article field --- .../install/export/intarocrm_run.php | 196 ++++++++++-------- 1 file changed, 107 insertions(+), 89 deletions(-) diff --git a/intaro.intarocrm/install/export/intarocrm_run.php b/intaro.intarocrm/install/export/intarocrm_run.php index e27a5c54..54e880af 100755 --- a/intaro.intarocrm/install/export/intarocrm_run.php +++ b/intaro.intarocrm/install/export/intarocrm_run.php @@ -3,6 +3,7 @@ __IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/export_crm.php")); set_time_limit(0); + CModule::IncludeModule("iblock"); $db_res = CIBlock::GetList(Array("IBLOCK_TYPE"=>"ASC", "NAME"=>"ASC"),array('CHECK_PERMISSIONS' => 'Y','MIN_PERMISSION' => 'W')); $IBLOCK_ID = Array(); @@ -244,30 +245,44 @@ if ($XML_DATA && CheckSerializedData($XML_DATA)) $XML_DATA = unserialize(stripslashes($XML_DATA)); if (!is_array($XML_DATA)) $XML_DATA = array(); } -$XML_DATA = Array(); -$XML_DATA["TYPE"] = null; -$XML_DATA["CURRENCY"] = Array ( - "RUB" => Array ( - "rate" => SITE, - "plus" => null - ) - ); -$XML_DATA["XML_DATA"] = Array(); -$XML_DATA["SKU_EXPORT"] = Array ( - "SKU_URL_TEMPLATE_TYPE" => 1, - "SKU_URL_TEMPLATE" => null, - "SKU_EXPORT_COND" => 1, - "SKU_PROP_COND" => Array ( - "PROP_ID" => 0, - "COND" => null, - "VALUES" => Array() - ) - ); +$XML_DATA = Array(); foreach ($arIBlockId as $id) { - $IBLOCK_ID = $id; - $IBLOCK_ID = intval($IBLOCK_ID); + $IBLOCK_ID = $id; + $IBLOCK_ID = intval($IBLOCK_ID); + + + $XML_DATA[$IBLOCK_ID]["TYPE"] = null; + $XML_DATA[$IBLOCK_ID]["CURRENCY"] = Array ( + "RUB" => Array ( + "rate" => SITE, + "plus" => null + ) + ); + $XML_DATA[$IBLOCK_ID]["XML_DATA"] = Array(); + $XML_DATA[$IBLOCK_ID]["SKU_EXPORT"] = Array ( + "SKU_URL_TEMPLATE_TYPE" => 1, + "SKU_URL_TEMPLATE" => null, + "SKU_EXPORT_COND" => 1, + "SKU_PROP_COND" => Array ( + "PROP_ID" => 0, + "COND" => null, + "VALUES" => Array() + ) + ); + + $properties = CIBlockProperty::GetList( + Array(), + Array( + "ACTIVE"=>"Y", + "IBLOCK_ID"=>$IBLOCK_ID, + "CODE" => "ARTICLE" + ) + )->Fetch(); + + $XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'][] = $properties['ID']; + $db_iblock = CIBlock::GetByID($IBLOCK_ID); $ar_iblock[$IBLOCK_ID] = $db_iblock->Fetch(); if (!($ar_iblock[$IBLOCK_ID])) @@ -378,13 +393,13 @@ foreach ($arIBlockId as $id) } if (true == $boolOffers) { - if (empty($XML_DATA['SKU_EXPORT'])) + if (empty($XML_DATA[$IBLOCK_ID]['SKU_EXPORT'])) { $arRunErrors[] = GetMessage('YANDEX_ERR_SKU_SETTINGS_ABSENT'); } else { - $arSKUExport = $XML_DATA['SKU_EXPORT'];; + $arSKUExport = $XML_DATA[$IBLOCK_ID]['SKU_EXPORT'];; if (empty($arSKUExport['SKU_EXPORT_COND']) || !in_array($arSKUExport['SKU_EXPORT_COND'],$arOffersSelectKeys)) { $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_CONDITION_ABSENT'); @@ -450,11 +465,11 @@ if (empty($arRunErrors)) } } -if (!empty($XML_DATA['PRICE'])) +if (!empty($XML_DATA[$IBLOCK_ID]['PRICE'])) { - if (intval($XML_DATA['PRICE']) > 0) + if (intval($XML_DATA[$IBLOCK_ID]['PRICE']) > 0) { - $rsCatalogGroups = CCatalogGroup::GetGroupsList(array('CATALOG_GROUP_ID' => $XML_DATA['PRICE'],'GROUP_ID' => 2)); + $rsCatalogGroups = CCatalogGroup::GetGroupsList(array('CATALOG_GROUP_ID' => $XML_DATA[$IBLOCK_ID]['PRICE'],'GROUP_ID' => 2)); if (!($arCatalogGroup = $rsCatalogGroups->Fetch())) { $arRunErrors[] = GetMessage('YANDEX_ERR_BAD_PRICE_TYPE'); @@ -536,9 +551,9 @@ if (empty($arRunErrors)) $arCurrencyAllowed = array($RUR, 'USD', 'EUR', 'UAH', 'BYR', 'KZT'); $BASE_CURRENCY = CCurrency::GetBaseCurrency(); - if (is_array($XML_DATA['CURRENCY'])) + if (is_array($XML_DATA[$IBLOCK_ID]['CURRENCY'])) { - foreach ($XML_DATA['CURRENCY'] as $CURRENCY => $arCurData) + foreach ($XML_DATA[$IBLOCK_ID]['CURRENCY'] as $CURRENCY => $arCurData) { if (in_array($CURRENCY, $arCurrencyAllowed)) { @@ -663,7 +678,7 @@ if (empty($arRunErrors)) while ($obElement = $res->GetNextElement()) { $arAcc = $obElement->GetFields(); - if (is_array($XML_DATA['XML_DATA'])) + if (is_array($XML_DATA[$IBLOCK_ID]['XML_DATA'])) { $arAcc["PROPERTIES"] = $obElement->GetProperties(); } @@ -688,11 +703,11 @@ if (empty($arRunErrors)) $minPriceGroup = 0; $minPriceCurrency = ""; - if ($XML_DATA['PRICE'] > 0) + if ($XML_DATA[$IBLOCK_ID]['PRICE'] > 0) { $rsPrices = CPrice::GetListEx(array(),array( 'PRODUCT_ID' => $arAcc['ID'], - 'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], + 'CATALOG_GROUP_ID' => $XML_DATA[$IBLOCK_ID]['PRICE'], 'CAN_BUY' => 'Y', 'GROUP_GROUP_ID' => array(2), '+<=QUANTITY_FROM' => 1, @@ -721,7 +736,7 @@ if (empty($arRunErrors)) $arDiscounts = CCatalogDiscount::GetDiscount( $arAcc['ID'], $IBLOCK_ID, - array($XML_DATA['PRICE']), + array($XML_DATA[$IBLOCK_ID]['PRICE']), array(2), 'N', $ar_iblock['LID'], @@ -798,8 +813,8 @@ if (empty($arRunErrors)) else $arAcc['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arAcc['DETAIL_PAGE_URL']); - if (is_array($XML_DATA) && $XML_DATA['TYPE'] && $XML_DATA['TYPE'] != 'none') - $str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA['TYPE']).'"'; + if (is_array($XML_DATA[$IBLOCK_ID]) && $XML_DATA[$IBLOCK_ID]['TYPE'] && $XML_DATA[$IBLOCK_ID]['TYPE'] != 'none') + $str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA[$IBLOCK_ID]['TYPE']).'"'; else $str_TYPE = ''; @@ -837,7 +852,7 @@ if (empty($arRunErrors)) switch ($key) { case 'name': - if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) + if (is_array($XML_DATA[$IBLOCK_ID]) && ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model' || $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title')) continue; $strTmpOff .= "".yandex_text2xml($arAcc["NAME"], true)."\n"; @@ -852,10 +867,11 @@ if (empty($arRunErrors)) "\n"; break; case 'param': - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) + if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'])) { - foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) + foreach ($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'] as $key => $prop_id) { + $strParamValue = ''; if ($prop_id) { @@ -876,12 +892,12 @@ if (empty($arRunErrors)) break; case 'model': case 'title': - if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) + if (!is_array($XML_DATA[$IBLOCK_ID]) || !is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) || !$XML_DATA[$IBLOCK_ID]['XML_DATA'][$key]) { if ( - $key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' + $key == 'model' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model' || - $key == 'title' && $XML_DATA['TYPE'] == 'artist.title' + $key == 'title' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title' ) $strTmpOff.= "<".$key.">".yandex_text2xml($arAcc["NAME"], true)."\n"; @@ -889,14 +905,14 @@ if (empty($arRunErrors)) else { $strValue = ''; - $strValue = yandex_get_value($arAcc, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); + $strValue = yandex_get_value($arAcc, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID); if ('' != $strValue) $strTmpOff .= $strValue."\n"; } break; case 'year': $y++; - if ($XML_DATA['TYPE'] == 'artist.title') + if ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title') { if ($y == 1) continue; } @@ -908,10 +924,10 @@ if (empty($arRunErrors)) // no break here default: - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) + if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key]) { $strValue = ''; - $strValue = yandex_get_value($arAcc, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); + $strValue = yandex_get_value($arAcc, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID); if ('' != $strValue) $strTmpOff .= $strValue."\n"; } @@ -1053,11 +1069,11 @@ if (empty($arRunErrors)) { $arOfferItem = $obOfferItem->GetFields(); $minPrice = -1; - if ($XML_DATA['PRICE'] > 0) + if ($XML_DATA[$IBLOCK_ID]['PRICE'] > 0) { $rsPrices = CPrice::GetListEx(array(),array( 'PRODUCT_ID' => $arOfferItem['ID'], - 'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], + 'CATALOG_GROUP_ID' => $XML_DATA[$IBLOCK_ID]['PRICE'], 'CAN_BUY' => 'Y', 'GROUP_GROUP_ID' => array(2), '+<=QUANTITY_FROM' => 1, @@ -1086,7 +1102,7 @@ if (empty($arRunErrors)) $arDiscounts = CCatalogDiscount::GetDiscount( $arOfferItem['ID'], $intOfferIBlockID, - array($XML_DATA['PRICE']), + array($XML_DATA[$IBLOCK_ID]['PRICE']), array(2), 'N', $arOfferIBlock['LID'], @@ -1215,8 +1231,8 @@ if (empty($arRunErrors)) else $arOfferItem['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arOfferItem['DETAIL_PAGE_URL']); - if (is_array($XML_DATA) && $XML_DATA['TYPE'] && $XML_DATA['TYPE'] != 'none') - $str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA['TYPE']).'"'; + if (is_array($XML_DATA[$IBLOCK_ID]) && $XML_DATA[$IBLOCK_ID]['TYPE'] && $XML_DATA[$IBLOCK_ID]['TYPE'] != 'none') + $str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA[$IBLOCK_ID]['TYPE']).'"'; else $str_TYPE = ''; @@ -1262,7 +1278,7 @@ if (empty($arRunErrors)) switch ($key) { case 'name': - if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) + if (is_array($XML_DATA[$IBLOCK_ID]) && ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model' || $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title')) continue; $strOfferYandex .= "".yandex_text2xml($arOfferItem["NAME"], true)."\n"; @@ -1284,10 +1300,11 @@ if (empty($arRunErrors)) $strOfferYandex .= "\n"; break; case 'param': - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) + if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'])) { - foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) + foreach ($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'] as $key => $prop_id) { + $strParamValue = ''; if ($prop_id) { @@ -1306,26 +1323,26 @@ if (empty($arRunErrors)) break; case 'model': case 'title': - if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) + if (!is_array($XML_DATA[$IBLOCK_ID]) || !is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) || !$XML_DATA[$IBLOCK_ID]['XML_DATA'][$key]) { if ( - $key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' + $key == 'model' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model' || - $key == 'title' && $XML_DATA['TYPE'] == 'artist.title' + $key == 'title' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title' ) $strOfferYandex .= "<".$key.">".yandex_text2xml($arOfferItem["NAME"], true)."\n"; } else { $strValue = ''; - $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); + $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID); if ('' != $strValue) $strOfferYandex .= $strValue."\n"; } break; case 'year': $y++; - if ($XML_DATA['TYPE'] == 'artist.title') + if ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title') { if ($y == 1) continue; } @@ -1335,10 +1352,10 @@ if (empty($arRunErrors)) } // no break here default: - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) + if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key]) { $strValue = ''; - $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); + $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID); if ('' != $strValue) $strOfferYandex .= $strValue."\n"; } @@ -1386,11 +1403,11 @@ if (empty($arRunErrors)) $arOfferItem['YANDEX_AVAILABLE'] = 'false'; $minPrice = -1; - if ($XML_DATA['PRICE'] > 0) + if ($XML_DATA[$IBLOCK_ID]['PRICE'] > 0) { $rsPrices = CPrice::GetListEx(array(),array( 'PRODUCT_ID' => $arOfferItem['ID'], - 'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], + 'CATALOG_GROUP_ID' => $XML_DATA[$IBLOCK_ID]['PRICE'], 'CAN_BUY' => 'Y', 'GROUP_GROUP_ID' => array(2), '+<=QUANTITY_FROM' => 1, @@ -1419,7 +1436,7 @@ if (empty($arRunErrors)) $arDiscounts = CCatalogDiscount::GetDiscount( $arOfferItem['ID'], $intOfferIBlockID, - array($XML_DATA['PRICE']), + array($XML_DATA[$IBLOCK_ID]['PRICE']), array(2), 'N', $arOfferIBlock['LID'], @@ -1471,8 +1488,8 @@ if (empty($arRunErrors)) else $arOfferItem['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arOfferItem['DETAIL_PAGE_URL']); - if (is_array($XML_DATA) && $XML_DATA['TYPE'] && $XML_DATA['TYPE'] != 'none') - $str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA['TYPE']).'"'; + if (is_array($XML_DATA[$IBLOCK_ID]) && $XML_DATA[$IBLOCK_ID]['TYPE'] && $XML_DATA[$IBLOCK_ID]['TYPE'] != 'none') + $str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA[$IBLOCK_ID]['TYPE']).'"'; else $str_TYPE = ''; @@ -1518,7 +1535,7 @@ if (empty($arRunErrors)) switch ($key) { case 'name': - if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) + if (is_array($XML_DATA[$IBLOCK_ID]) && ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model' || $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title')) continue; $strOfferYandex .= "".yandex_text2xml($arOfferItem["NAME"], true)."\n"; @@ -1540,9 +1557,9 @@ if (empty($arRunErrors)) $strOfferYandex .= "\n"; break; case 'param': - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) + if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'])) { - foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) + foreach ($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'] as $key => $prop_id) { $strParamValue = ''; if ($prop_id) @@ -1562,26 +1579,26 @@ if (empty($arRunErrors)) break; case 'model': case 'title': - if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) + if (!is_array($XML_DATA[$IBLOCK_ID]) || !is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) || !$XML_DATA[$IBLOCK_ID]['XML_DATA'][$key]) { if ( - $key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' + $key == 'model' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model' || - $key == 'title' && $XML_DATA['TYPE'] == 'artist.title' + $key == 'title' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title' ) $strOfferYandex .= "<".$key.">".yandex_text2xml($arOfferItem["NAME"], true)."\n"; } else { $strValue = ''; - $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); + $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID); if ('' != $strValue) $strOfferYandex .= $strValue."\n"; } break; case 'year': $y++; - if ($XML_DATA['TYPE'] == 'artist.title') + if ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title') { if ($y == 1) continue; } @@ -1591,10 +1608,10 @@ if (empty($arRunErrors)) } // no break here default: - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) + if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key]) { $strValue = ''; - $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); + $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID); if ('' != $strValue) $strOfferYandex .= $strValue."\n"; } @@ -1630,11 +1647,11 @@ if (empty($arRunErrors)) $minPriceGroup = 0; $minPriceCurrency = ""; - if ($XML_DATA['PRICE'] > 0) + if ($XML_DATA[$IBLOCK_ID]['PRICE'] > 0) { $rsPrices = CPrice::GetListEx(array(),array( 'PRODUCT_ID' => $arItem['ID'], - 'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], + 'CATALOG_GROUP_ID' => $XML_DATA[$IBLOCK_ID]['PRICE'], 'CAN_BUY' => 'Y', 'GROUP_GROUP_ID' => array(2), '+<=QUANTITY_FROM' => 1, @@ -1663,7 +1680,7 @@ if (empty($arRunErrors)) $arDiscounts = CCatalogDiscount::GetDiscount( $arItem['ID'], $IBLOCK_ID, - array($XML_DATA['PRICE']), + array($XML_DATA[$IBLOCK_ID]['PRICE']), array(2), 'N', $ar_iblock['LID'], @@ -1726,8 +1743,8 @@ if (empty($arRunErrors)) $arItem['~DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arItem['~DETAIL_PAGE_URL']); } - if (is_array($XML_DATA) && $XML_DATA['TYPE'] && $XML_DATA['TYPE'] != 'none') - $str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA['TYPE']).'"'; + if (is_array($XML_DATA[$IBLOCK_ID]) && $XML_DATA[$IBLOCK_ID]['TYPE'] && $XML_DATA[$IBLOCK_ID]['TYPE'] != 'none') + $str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA[$IBLOCK_ID]['TYPE']).'"'; else $str_TYPE = ''; if (!isset($arItem["ID"])) @@ -1754,7 +1771,7 @@ if (empty($arRunErrors)) switch ($key) { case 'name': - if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) + if (is_array($XML_DATA[$IBLOCK_ID]) && ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model' || $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title')) continue; $strValue = "".yandex_text2xml($arItem["NAME"], true)."\n"; @@ -1769,9 +1786,9 @@ if (empty($arRunErrors)) "\n"; break; case 'param': - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) + if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'])) { - foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) + foreach ($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'] as $key => $prop_id) { $strParamValue = ''; if ($prop_id) @@ -1791,26 +1808,26 @@ if (empty($arRunErrors)) break; case 'model': case 'title': - if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) + if (!is_array($XML_DATA[$IBLOCK_ID]) || !is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) || !$XML_DATA[$IBLOCK_ID]['XML_DATA'][$key]) { if ( - $key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' + $key == 'model' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model' || - $key == 'title' && $XML_DATA['TYPE'] == 'artist.title' + $key == 'title' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title' ) $strValue = "<".$key.">".yandex_text2xml($arItem["NAME"], true)."\n"; } else { - $strValue = yandex_get_value($arItem, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); + $strValue = yandex_get_value($arItem, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID); if ('' != $strValue) $strValue .= "\n"; } break; case 'year': $y++; - if ($XML_DATA['TYPE'] == 'artist.title') + if ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title') { if ($y == 1) continue; } @@ -1822,9 +1839,9 @@ if (empty($arRunErrors)) // no break here default: - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) + if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key]) { - $strValue = yandex_get_value($arItem, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); + $strValue = yandex_get_value($arItem, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID); if ('' != $strValue) $strValue .= "\n"; } @@ -1868,6 +1885,7 @@ if (empty($arRunErrors)) @fwrite($fp, "\n"); @fclose($fp); + } From bef6efeead4c8612373f66086facb6f6f3c0e021 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 29 Jul 2013 18:42:33 +0400 Subject: [PATCH 02/23] send city fix --- .../classes/general/ICrmOrderActions.php | 5 + .../classes/general/ICrmOrderActions.php~ | 372 ++++++++++++++++++ 2 files changed, 377 insertions(+) create mode 100755 intaro.intarocrm/classes/general/ICrmOrderActions.php~ diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 7fde6192..9f7140eb 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -256,6 +256,11 @@ class ICrmOrderActions break; case 'ADDRESS': $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']); break; + case 'LOCATION': if(!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) { + $resOrderDeliveryAddress['city'] = CSaleLocation::GetByID($ar['VALUE']); + $resOrderDeliveryAddress['city'] = self::toJSON($resOrderDeliveryAddress['city']['CITY_NAME_LANG']); + } + break; case 'FIO': $resOrder['contactName'] = explode(" ", self::toJSON($ar['VALUE'])); break; case 'PHONE': $resOrder['phone'] = $ar['VALUE']; diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php~ b/intaro.intarocrm/classes/general/ICrmOrderActions.php~ new file mode 100755 index 00000000..7fde6192 --- /dev/null +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php~ @@ -0,0 +1,372 @@ + "ASC"), array('>ID' => $lastUpOrderId)); + + $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_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)); + $optionsDelivTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_DELIVERY_TYPES_ARR, 0)); + $optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0)); + $optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses + $optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0)); + + $api = new IntaroCrm\RestApi($api_host, $api_key); + + $arParams = array( + 'optionsOrderTypes' => $optionsOrderTypes, + 'optionsDelivTypes' => $optionsDelivTypes, + 'optionsPayTypes' => $optionsPayTypes, + 'optionsPayStatuses' => $optionsPayStatuses, + 'optionsPayment' => $optionsPayment + ); + + // pack mode enable / disable + // can send data evry 500 rows + if (!$steps) { + + while ($arOrder = $dbOrder->GetNext()) { //here orders by id asc; with offset + + $order = self::orderCreate($arOrder['ID'], $api, $arParams); + + if (!$order) + continue; + + $resOrders[] = $order; + + $lastOrderId = $arOrder['ID']; + } + + if (!empty($resOrders)) { + $orders = $api->orderUpload($resOrders); + + // error pushing orders + if ($api->getStatusCode() != 201) { + //handle err + self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError()); + + if ($api->getStatusCode() != 460) // some orders were sent + return true; + } + } + + } else { // package mode (by default runs after install) + $orderCount = 0; + + while ($arOrder = $dbOrder->GetNext()) { // here orders by id asc + + $order = self::orderCreate($arOrder['ID'], $api, $arParams); + + if (!$order) + continue; + + $orderCount++; + + $resOrders[] = $order; + + $lastOrderId = $arOrder['ID']; + + if($orderCount >= $pSize) { + $orders = $api->orderUpload($resOrders); + + // error pushing orders + if ($api->getStatusCode() != 201) { + //handle err + self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError()); + + if($api->getStatusCode() != 460) // some orders were sent + return false; // in pack mode return errors + + if($lastOrderId) + COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId); + } + + return true; // end of pack + } + } + + if (!empty($resOrders)) { + $orders = $api->orderUpload($resOrders); + + // error pushing orders + if ($api->getStatusCode() != 201) { + //handle err + self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError()); + + if ($api->getStatusCode() != 460) // some orders were sent + return false; // in pack mode return errors + } + } + } + + if($lastOrderId) + COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId); + + return true; //all ok! + } + + /** + * + * w+ event in bitrix log + */ + private static function eventLog($auditType, $itemId, $description) { + CEventLog::Add(array( + "SEVERITY" => "SECURITY", + "AUDIT_TYPE_ID" => $auditType, + "MODULE_ID" => self::$MODULE_ID, + "ITEM_ID" => $itemId, + "DESCRIPTION" => $description, + )); + } + + /** + * + * Agent function + * + * @return self name + */ + + public static function uploadOrdersAgent() { + + if(self::uploadOrders()) + return 'ICrmOrderActions::uploadOrdersAgent();'; + + else return; + } + + public static function orderCreate($orderId, $api, $arParams, $send = false) { + if(!$api || empty($arParams) || !$orderId) { // add cond to check $arParams + return false; + } + + $arFields = CSaleOrder::GetById($orderId); + + if (empty($arFields)) { + //handle err + self::eventLog('ICrmOrderActions::orderCreate', 'empty($arFields)', 'incorrect order'); + + return false; + } + + $rsUser = CUser::GetByID($arFields['USER_ID']); + $arUser = $rsUser->Fetch(); + + $createdAt = new \DateTime($arUser['DATE_REGISTER']); + $createdAt = $createdAt->format('Y-m-d H:i:s'); + + // push customer (for crm) + $firstName = self::toJSON($arUser['NAME']); + $lastName = self::toJSON($arUser['LAST_NAME']); + $patronymic = self::toJSON($arUser['SECOND_NAME']); + + $phonePersonal = array( + 'number' => self::toJSON($arUser['PERSONAL_PHONE']), + 'type' => 'mobile' + ); + $phones[] = $phonePersonal; + + $phoneWork = array( + 'number' => self::toJSON($arUser['WORK_PHONE']), + 'type' => 'work' + ); + $phones[] = $phoneWork; + + $result = self::clearArr(array( + 'externalId' => $arFields['USER_ID'], + 'lastName' => $lastName, + 'firstName' => $firstName, + 'patronymic' => $patronymic, + 'phones' => $phones, + 'createdAt' => $createdAt + )); + + $customer = $api->customerEdit($result); + + // error pushing customer + if (!$customer) { + //handle err + self::eventLog('ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit', $api->getLastError()); + return false; + } + + // delivery types + $arId = array(); + if (strpos($arFields['DELIVERY_ID'], ":") !== false) + $arId = explode(":", $arFields["DELIVERY_ID"]); + + if ($arId) + $resultDeliveryTypeId = $arId[0]; + else + $resultDeliveryTypeId = $arFields['DELIVERY_ID']; + + + $resOrder = array(); + $resOrderDeliveryAddress = array(); + + $rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID'])); + while ($ar = $rsOrderProps->Fetch()) { + switch ($ar['CODE']) { + case 'ZIP': $resOrderDeliveryAddress['index'] = self::toJSON($ar['VALUE']); + break; + case 'CITY': $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); + break; + case 'ADDRESS': $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']); + break; + case 'FIO': $resOrder['contactName'] = explode(" ", self::toJSON($ar['VALUE'])); + break; + case 'PHONE': $resOrder['phone'] = $ar['VALUE']; + break; + case 'EMAIL': $resOrder['email'] = $ar['VALUE']; + break; + } + } + + $items = array(); + + $rsOrderBasket = CSaleBasket::GetList(array('PRODUCT_ID' => 'ASC'), array('ORDER_ID' => $arFields['ID'])); + while ($p = $rsOrderBasket->Fetch()) { + $pr = CCatalogProduct::GetList(array('ID' => $p['PRODUCT_ID']))->Fetch(); + if ($pr) + $pr = $pr['PURCHASING_PRICE']; + else + $pr = ''; + + if($p['DISCOUNT_VALUE']) + $p['DISCOUNT_PRICE'] = null; + + $items[] = array( + 'initialPrice' => (double) $p['PRICE'] + (double) $p['DISCOUNT_PRICE'], + 'purchasePrice' => $pr, + 'discount' => $p['DISCOUNT_PRICE'], + 'discountPercent' => $p['DISCOUNT_VALUE'], + 'quantity' => $p['QUANTITY'], + 'productId' => $p['PRODUCT_ID'], + 'productName' => self::toJSON($p['NAME']) + ); + } + + if($arFields['CANCELED'] == 'Y') + $arFields['STATUS_ID'] = $arFields['CANCELED']; + + $createdAt = new \DateTime($arFields['DATE_INSERT']); + $createdAt = $createdAt->format('Y-m-d H:i:s'); + + $resOrder = self::clearArr(array( + 'firstName' => $resOrder['contactName'][0], + 'lastName' => $resOrder['contactName'][1], + 'patronymic' => $resOrder['contactName'][2], + 'phone' => $resOrder['phone'], + 'email' => $resOrder['email'], + 'deliveryCost' => $arFields['PRICE_DELIVERY'], + 'summ' => $arFields['PRICE'], + 'markDateTime' => $arFields['DATE_MARKED'], + 'externalId' => $arFields['ID'], + 'customerId' => $arFields['USER_ID'], + 'paymentType' => $arParams['optionsPayTypes'][$arFields['PAY_SYSTEM_ID']], + 'paymentStatus' => $arParams['optionsPayment'][$arFields['PAYED']], + 'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']], + 'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId], + 'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']], + 'statusComment' => $arFields['REASON_CANCELED'], + 'createdAt' => $createdAt, + 'deliveryAddress' => $resOrderDeliveryAddress, + 'items' => $items + )); + + if($send) + return $api->createOrder($resOrder); + + return $resOrder; + + } + + /** + * removes all empty fields from arrays + * working with nested arrs + * + * @param type $arr + * @return boolean + */ + public static function clearArr($arr) { + if(!$arr || !is_array($arr)) + return false; + + foreach($arr as $key => $value) { + if(!$value || (is_array($value) && empty($value))) + unset($arr[$key]); + + if(is_array($value) && !empty($value)) + $arr[$key] = self::clearArr($value); + } + + return $arr; + } + + /** + * + * @global type $APPLICATION + * @param type $str in SITE_CHARSET + * @return type $str in utf-8 + */ + protected static function toJSON($str) { + global $APPLICATION; + + return $APPLICATION->ConvertCharset($str, SITE_CHARSET, 'utf-8'); + } + + /** + * + * @global type $APPLICATION + * @param type $str in utf-8 + * @return type $str in SITE_CHARSET + */ + public static function fromJSON($str) { + global $APPLICATION; + + return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET); + } +} From 9efc6460668356099419afe26a2aea7241ec3e53 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 29 Jul 2013 18:43:04 +0400 Subject: [PATCH 03/23] send city fix --- .../classes/general/ICrmOrderActions.php~ | 372 ------------------ 1 file changed, 372 deletions(-) delete mode 100755 intaro.intarocrm/classes/general/ICrmOrderActions.php~ diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php~ b/intaro.intarocrm/classes/general/ICrmOrderActions.php~ deleted file mode 100755 index 7fde6192..00000000 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php~ +++ /dev/null @@ -1,372 +0,0 @@ - "ASC"), array('>ID' => $lastUpOrderId)); - - $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_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)); - $optionsDelivTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_DELIVERY_TYPES_ARR, 0)); - $optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0)); - $optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses - $optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0)); - - $api = new IntaroCrm\RestApi($api_host, $api_key); - - $arParams = array( - 'optionsOrderTypes' => $optionsOrderTypes, - 'optionsDelivTypes' => $optionsDelivTypes, - 'optionsPayTypes' => $optionsPayTypes, - 'optionsPayStatuses' => $optionsPayStatuses, - 'optionsPayment' => $optionsPayment - ); - - // pack mode enable / disable - // can send data evry 500 rows - if (!$steps) { - - while ($arOrder = $dbOrder->GetNext()) { //here orders by id asc; with offset - - $order = self::orderCreate($arOrder['ID'], $api, $arParams); - - if (!$order) - continue; - - $resOrders[] = $order; - - $lastOrderId = $arOrder['ID']; - } - - if (!empty($resOrders)) { - $orders = $api->orderUpload($resOrders); - - // error pushing orders - if ($api->getStatusCode() != 201) { - //handle err - self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError()); - - if ($api->getStatusCode() != 460) // some orders were sent - return true; - } - } - - } else { // package mode (by default runs after install) - $orderCount = 0; - - while ($arOrder = $dbOrder->GetNext()) { // here orders by id asc - - $order = self::orderCreate($arOrder['ID'], $api, $arParams); - - if (!$order) - continue; - - $orderCount++; - - $resOrders[] = $order; - - $lastOrderId = $arOrder['ID']; - - if($orderCount >= $pSize) { - $orders = $api->orderUpload($resOrders); - - // error pushing orders - if ($api->getStatusCode() != 201) { - //handle err - self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError()); - - if($api->getStatusCode() != 460) // some orders were sent - return false; // in pack mode return errors - - if($lastOrderId) - COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId); - } - - return true; // end of pack - } - } - - if (!empty($resOrders)) { - $orders = $api->orderUpload($resOrders); - - // error pushing orders - if ($api->getStatusCode() != 201) { - //handle err - self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError()); - - if ($api->getStatusCode() != 460) // some orders were sent - return false; // in pack mode return errors - } - } - } - - if($lastOrderId) - COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId); - - return true; //all ok! - } - - /** - * - * w+ event in bitrix log - */ - private static function eventLog($auditType, $itemId, $description) { - CEventLog::Add(array( - "SEVERITY" => "SECURITY", - "AUDIT_TYPE_ID" => $auditType, - "MODULE_ID" => self::$MODULE_ID, - "ITEM_ID" => $itemId, - "DESCRIPTION" => $description, - )); - } - - /** - * - * Agent function - * - * @return self name - */ - - public static function uploadOrdersAgent() { - - if(self::uploadOrders()) - return 'ICrmOrderActions::uploadOrdersAgent();'; - - else return; - } - - public static function orderCreate($orderId, $api, $arParams, $send = false) { - if(!$api || empty($arParams) || !$orderId) { // add cond to check $arParams - return false; - } - - $arFields = CSaleOrder::GetById($orderId); - - if (empty($arFields)) { - //handle err - self::eventLog('ICrmOrderActions::orderCreate', 'empty($arFields)', 'incorrect order'); - - return false; - } - - $rsUser = CUser::GetByID($arFields['USER_ID']); - $arUser = $rsUser->Fetch(); - - $createdAt = new \DateTime($arUser['DATE_REGISTER']); - $createdAt = $createdAt->format('Y-m-d H:i:s'); - - // push customer (for crm) - $firstName = self::toJSON($arUser['NAME']); - $lastName = self::toJSON($arUser['LAST_NAME']); - $patronymic = self::toJSON($arUser['SECOND_NAME']); - - $phonePersonal = array( - 'number' => self::toJSON($arUser['PERSONAL_PHONE']), - 'type' => 'mobile' - ); - $phones[] = $phonePersonal; - - $phoneWork = array( - 'number' => self::toJSON($arUser['WORK_PHONE']), - 'type' => 'work' - ); - $phones[] = $phoneWork; - - $result = self::clearArr(array( - 'externalId' => $arFields['USER_ID'], - 'lastName' => $lastName, - 'firstName' => $firstName, - 'patronymic' => $patronymic, - 'phones' => $phones, - 'createdAt' => $createdAt - )); - - $customer = $api->customerEdit($result); - - // error pushing customer - if (!$customer) { - //handle err - self::eventLog('ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit', $api->getLastError()); - return false; - } - - // delivery types - $arId = array(); - if (strpos($arFields['DELIVERY_ID'], ":") !== false) - $arId = explode(":", $arFields["DELIVERY_ID"]); - - if ($arId) - $resultDeliveryTypeId = $arId[0]; - else - $resultDeliveryTypeId = $arFields['DELIVERY_ID']; - - - $resOrder = array(); - $resOrderDeliveryAddress = array(); - - $rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID'])); - while ($ar = $rsOrderProps->Fetch()) { - switch ($ar['CODE']) { - case 'ZIP': $resOrderDeliveryAddress['index'] = self::toJSON($ar['VALUE']); - break; - case 'CITY': $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); - break; - case 'ADDRESS': $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']); - break; - case 'FIO': $resOrder['contactName'] = explode(" ", self::toJSON($ar['VALUE'])); - break; - case 'PHONE': $resOrder['phone'] = $ar['VALUE']; - break; - case 'EMAIL': $resOrder['email'] = $ar['VALUE']; - break; - } - } - - $items = array(); - - $rsOrderBasket = CSaleBasket::GetList(array('PRODUCT_ID' => 'ASC'), array('ORDER_ID' => $arFields['ID'])); - while ($p = $rsOrderBasket->Fetch()) { - $pr = CCatalogProduct::GetList(array('ID' => $p['PRODUCT_ID']))->Fetch(); - if ($pr) - $pr = $pr['PURCHASING_PRICE']; - else - $pr = ''; - - if($p['DISCOUNT_VALUE']) - $p['DISCOUNT_PRICE'] = null; - - $items[] = array( - 'initialPrice' => (double) $p['PRICE'] + (double) $p['DISCOUNT_PRICE'], - 'purchasePrice' => $pr, - 'discount' => $p['DISCOUNT_PRICE'], - 'discountPercent' => $p['DISCOUNT_VALUE'], - 'quantity' => $p['QUANTITY'], - 'productId' => $p['PRODUCT_ID'], - 'productName' => self::toJSON($p['NAME']) - ); - } - - if($arFields['CANCELED'] == 'Y') - $arFields['STATUS_ID'] = $arFields['CANCELED']; - - $createdAt = new \DateTime($arFields['DATE_INSERT']); - $createdAt = $createdAt->format('Y-m-d H:i:s'); - - $resOrder = self::clearArr(array( - 'firstName' => $resOrder['contactName'][0], - 'lastName' => $resOrder['contactName'][1], - 'patronymic' => $resOrder['contactName'][2], - 'phone' => $resOrder['phone'], - 'email' => $resOrder['email'], - 'deliveryCost' => $arFields['PRICE_DELIVERY'], - 'summ' => $arFields['PRICE'], - 'markDateTime' => $arFields['DATE_MARKED'], - 'externalId' => $arFields['ID'], - 'customerId' => $arFields['USER_ID'], - 'paymentType' => $arParams['optionsPayTypes'][$arFields['PAY_SYSTEM_ID']], - 'paymentStatus' => $arParams['optionsPayment'][$arFields['PAYED']], - 'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']], - 'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId], - 'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']], - 'statusComment' => $arFields['REASON_CANCELED'], - 'createdAt' => $createdAt, - 'deliveryAddress' => $resOrderDeliveryAddress, - 'items' => $items - )); - - if($send) - return $api->createOrder($resOrder); - - return $resOrder; - - } - - /** - * removes all empty fields from arrays - * working with nested arrs - * - * @param type $arr - * @return boolean - */ - public static function clearArr($arr) { - if(!$arr || !is_array($arr)) - return false; - - foreach($arr as $key => $value) { - if(!$value || (is_array($value) && empty($value))) - unset($arr[$key]); - - if(is_array($value) && !empty($value)) - $arr[$key] = self::clearArr($value); - } - - return $arr; - } - - /** - * - * @global type $APPLICATION - * @param type $str in SITE_CHARSET - * @return type $str in utf-8 - */ - protected static function toJSON($str) { - global $APPLICATION; - - return $APPLICATION->ConvertCharset($str, SITE_CHARSET, 'utf-8'); - } - - /** - * - * @global type $APPLICATION - * @param type $str in utf-8 - * @return type $str in SITE_CHARSET - */ - public static function fromJSON($str) { - global $APPLICATION; - - return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET); - } -} From 7adaec8435c4271d700c862ea11d8fbfe599eb4c Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 29 Jul 2013 20:22:35 +0400 Subject: [PATCH 04/23] orders export fix --- intaro.intarocrm/classes/general/ICrmOrderActions.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 9f7140eb..e2794de5 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -121,10 +121,11 @@ class ICrmOrderActions if($api->getStatusCode() != 460) // some orders were sent return false; // in pack mode return errors - if($lastOrderId) - COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId); } + if($lastOrderId) + COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId); + return true; // end of pack } } From bb7a7ad88529e2df8798f529f91750c9f720d4bb Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Mon, 29 Jul 2013 21:47:25 +0400 Subject: [PATCH 05/23] fix FIO exploding --- .../classes/general/ICrmOrderActions.php | 124 +++++++++--------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index e2794de5..9d0542c4 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -11,40 +11,40 @@ class ICrmOrderActions protected static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N protected static $CRM_ORDER_LAST_ID = 'order_last_id'; - + /** * Mass order uploading, without repeating; always returns true, but writes error log * @return boolean */ public static function uploadOrders($steps = false, $pSize = 50) { - + //COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 0); // -- for test - + if (!CModule::IncludeModule("iblock")) { //handle err self::eventLog('ICrmOrderActions::uploadOrders', 'iblock', 'module not found'); return true; } - + if (!CModule::IncludeModule("sale")) { //handle err self::eventLog('ICrmOrderActions::uploadOrders', 'sale', 'module not found'); return true; } - + if (!CModule::IncludeModule("catalog")) { //handle err self::eventLog('ICrmOrderActions::uploadOrders', 'catalog', 'module not found'); return true; } - + $resOrders = array(); - + $lastUpOrderId = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 0); $lastOrderId = 0; - + $dbOrder = CSaleOrder::GetList(array("ID" => "ASC"), array('>ID' => $lastUpOrderId)); - + $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0); @@ -56,7 +56,7 @@ class ICrmOrderActions $optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0)); $api = new IntaroCrm\RestApi($api_host, $api_key); - + $arParams = array( 'optionsOrderTypes' => $optionsOrderTypes, 'optionsDelivTypes' => $optionsDelivTypes, @@ -64,26 +64,26 @@ class ICrmOrderActions 'optionsPayStatuses' => $optionsPayStatuses, 'optionsPayment' => $optionsPayment ); - + // pack mode enable / disable // can send data evry 500 rows if (!$steps) { - + while ($arOrder = $dbOrder->GetNext()) { //here orders by id asc; with offset - + $order = self::orderCreate($arOrder['ID'], $api, $arParams); if (!$order) continue; $resOrders[] = $order; - + $lastOrderId = $arOrder['ID']; } - + if (!empty($resOrders)) { $orders = $api->orderUpload($resOrders); - + // error pushing orders if ($api->getStatusCode() != 201) { //handle err @@ -93,39 +93,39 @@ class ICrmOrderActions return true; } } - + } else { // package mode (by default runs after install) $orderCount = 0; - + while ($arOrder = $dbOrder->GetNext()) { // here orders by id asc - + $order = self::orderCreate($arOrder['ID'], $api, $arParams); if (!$order) continue; - + $orderCount++; - + $resOrders[] = $order; - + $lastOrderId = $arOrder['ID']; - + if($orderCount >= $pSize) { $orders = $api->orderUpload($resOrders); - + // error pushing orders if ($api->getStatusCode() != 201) { //handle err self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError()); - + if($api->getStatusCode() != 460) // some orders were sent return false; // in pack mode return errors - + } - + if($lastOrderId) COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId); - + return true; // end of pack } } @@ -141,9 +141,9 @@ class ICrmOrderActions if ($api->getStatusCode() != 460) // some orders were sent return false; // in pack mode return errors } - } + } } - + if($lastOrderId) COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId); @@ -151,7 +151,7 @@ class ICrmOrderActions } /** - * + * * w+ event in bitrix log */ private static function eventLog($auditType, $itemId, $description) { @@ -163,27 +163,27 @@ class ICrmOrderActions "DESCRIPTION" => $description, )); } - + /** - * + * * Agent function - * + * * @return self name */ - + public static function uploadOrdersAgent() { - + if(self::uploadOrders()) return 'ICrmOrderActions::uploadOrdersAgent();'; - + else return; } - + public static function orderCreate($orderId, $api, $arParams, $send = false) { if(!$api || empty($arParams) || !$orderId) { // add cond to check $arParams return false; } - + $arFields = CSaleOrder::GetById($orderId); if (empty($arFields)) { @@ -195,7 +195,7 @@ class ICrmOrderActions $rsUser = CUser::GetByID($arFields['USER_ID']); $arUser = $rsUser->Fetch(); - + $createdAt = new \DateTime($arUser['DATE_REGISTER']); $createdAt = $createdAt->format('Y-m-d H:i:s'); @@ -270,7 +270,7 @@ class ICrmOrderActions break; } } - + $items = array(); $rsOrderBasket = CSaleBasket::GetList(array('PRODUCT_ID' => 'ASC'), array('ORDER_ID' => $arFields['ID'])); @@ -280,10 +280,10 @@ class ICrmOrderActions $pr = $pr['PURCHASING_PRICE']; else $pr = ''; - + if($p['DISCOUNT_VALUE']) $p['DISCOUNT_PRICE'] = null; - + $items[] = array( 'initialPrice' => (double) $p['PRICE'] + (double) $p['DISCOUNT_PRICE'], 'purchasePrice' => $pr, @@ -294,16 +294,16 @@ class ICrmOrderActions 'productName' => self::toJSON($p['NAME']) ); } - + if($arFields['CANCELED'] == 'Y') $arFields['STATUS_ID'] = $arFields['CANCELED']; - + $createdAt = new \DateTime($arFields['DATE_INSERT']); $createdAt = $createdAt->format('Y-m-d H:i:s'); - + $resOrder = self::clearArr(array( - 'firstName' => $resOrder['contactName'][0], - 'lastName' => $resOrder['contactName'][1], + 'lastName' => $resOrder['contactName'][0], + 'firstName' => $resOrder['contactName'][1], 'patronymic' => $resOrder['contactName'][2], 'phone' => $resOrder['phone'], 'email' => $resOrder['email'], @@ -322,57 +322,57 @@ class ICrmOrderActions 'deliveryAddress' => $resOrderDeliveryAddress, 'items' => $items )); - + if($send) return $api->createOrder($resOrder); - + return $resOrder; - + } - + /** * removes all empty fields from arrays * working with nested arrs - * + * * @param type $arr * @return boolean */ public static function clearArr($arr) { if(!$arr || !is_array($arr)) return false; - + foreach($arr as $key => $value) { if(!$value || (is_array($value) && empty($value))) unset($arr[$key]); - + if(is_array($value) && !empty($value)) $arr[$key] = self::clearArr($value); } - + return $arr; } - + /** - * + * * @global type $APPLICATION * @param type $str in SITE_CHARSET * @return type $str in utf-8 */ protected static function toJSON($str) { global $APPLICATION; - + return $APPLICATION->ConvertCharset($str, SITE_CHARSET, 'utf-8'); } - + /** - * + * * @global type $APPLICATION * @param type $str in utf-8 * @return type $str in SITE_CHARSET */ public static function fromJSON($str) { global $APPLICATION; - + return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET); } } From e7d54bf4e8cbf99ca645e357558366fb59ddac00 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Mon, 29 Jul 2013 21:59:24 +0400 Subject: [PATCH 06/23] fix messages --- intaro.intarocrm/lang/ru/install/index.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/intaro.intarocrm/lang/ru/install/index.php b/intaro.intarocrm/lang/ru/install/index.php index b2c7819e..c08d0e33 100755 --- a/intaro.intarocrm/lang/ru/install/index.php +++ b/intaro.intarocrm/lang/ru/install/index.php @@ -1,11 +1,11 @@ Date: Tue, 30 Jul 2013 16:14:04 +0400 Subject: [PATCH 07/23] Added curl checking --- intaro.intarocrm/install/index.php | 207 +++++++++++---------- intaro.intarocrm/lang/ru/install/index.php | 2 + 2 files changed, 108 insertions(+), 101 deletions(-) diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index dc5166e0..6250d562 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -10,7 +10,7 @@ IncludeModuleLangFile(__FILE__); if (class_exists('intaro_intarocrm')) return; -class intaro_intarocrm extends CModule +class intaro_intarocrm extends CModule { var $MODULE_ID = 'intaro.intarocrm'; var $MODULE_VERSION; @@ -21,7 +21,7 @@ class intaro_intarocrm extends CModule var $PARTNER_NAME; var $PARTNER_URI; var $INTARO_CRM_API; - + var $CRM_API_HOST_OPTION = 'api_host'; var $CRM_API_KEY_OPTION = 'api_key'; var $CRM_ORDER_TYPES_ARR = 'order_types_arr'; @@ -31,9 +31,9 @@ class intaro_intarocrm extends CModule var $CRM_PAYMENT = 'payment_arr'; //order payment Y/N var $CRM_ORDER_LAST_ID = 'order_last_id'; - + var $INSTALL_PATH; - + function intaro_intarocrm() { $arModuleVersion = array(); @@ -48,51 +48,56 @@ class intaro_intarocrm extends CModule $this->PARTNER_NAME = GetMessage('MODULE_PARTNER_NAME'); $this->PARTNER_URI = GetMessage('MODULE_PARTNER_URI'); } - - /** - * Functions DoInstall and DoUninstall are + + /** + * Functions DoInstall and DoUninstall are * All other functions are optional */ - - function DoInstall() + + function DoInstall() { global $APPLICATION, $step, $arResult; - + + if (!in_array('curl', get_loaded_extensions())) { + $APPLICATION->ThrowException( GetMessage("INTAROCRM_CURL_ERR") ); + return false; + } + include($this->INSTALL_PATH . '/../classes/general/RestApi.php'); include($this->INSTALL_PATH . '/../classes/general/ICrmOrderActions.php'); - + $step = intval($_REQUEST['step']); - - if ($step <= 1) { + + if ($step <= 1) { if(!CModule::IncludeModule("sale")) { $arResult['errCode'] = 'ERR_SALE'; } - + if(!CModule::IncludeModule("iblock")) { $arResult['errCode'] = 'ERR_IBLOCK'; } - + if(!CModule::IncludeModule("catalog")) { $arResult['errCode'] = 'ERR_CATALOG'; } - + $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_INSTALL_TITLE'), + GetMessage('MODULE_INSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php' ); } else if ($step == 2) { if(!CModule::IncludeModule("sale")) { $arResult['errCode'] = 'ERR_SALE'; } - + if(!CModule::IncludeModule("iblock")) { $arResult['errCode'] = 'ERR_IBLOCK'; } - + if(!CModule::IncludeModule("catalog")) { $arResult['errCode'] = 'ERR_CATALOG'; } - + if(isset($arResult['errCode']) && $arResult['errCode']) { $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), @@ -100,15 +105,15 @@ class intaro_intarocrm extends CModule ); return; } - + $api_host = htmlspecialchars(trim($_POST[$this->CRM_API_HOST_OPTION])); $api_key = htmlspecialchars(trim($_POST[$this->CRM_API_KEY_OPTION])); - + // form correct url $api_host = parse_url($api_host); $api_host = $api_host['scheme'] . '://' . $api_host['host']; - - if(!$api_host || !$api_key) { + + if(!$api_host || !$api_key) { $arResult['errCode'] = 'ERR_FIELDS_API_HOST'; $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), @@ -116,26 +121,26 @@ class intaro_intarocrm extends CModule ); return; } - + $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key); - + $this->INTARO_CRM_API->paymentStatusesList(); - + //check connection & apiKey valid if((int) $this->INTARO_CRM_API->getStatusCode() != 200) { $arResult['errCode'] = 'ERR_' . $this->INTARO_CRM_API->getStatusCode(); - + $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php' ); - + return; } - + COption::SetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, $api_host); COption::SetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, $api_key); - + //prepare crm lists $arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList(); $arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList(); @@ -143,7 +148,7 @@ class intaro_intarocrm extends CModule $arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); // --statuses $arResult['paymentList'] = $this->INTARO_CRM_API->orderStatusesList(); $arResult['paymentGroupList'] = $this->INTARO_CRM_API->orderStatusGroupsList(); // -- statuses groups - + //bitrix orderTypesList -- personTypes $dbOrderTypesList = CSalePersonType::GetList( array( @@ -157,13 +162,13 @@ class intaro_intarocrm extends CModule false, array() ); - + if ($arOrderTypesList = $dbOrderTypesList->Fetch()) { do { - $arResult['bitrixOrderTypesList'][] = $arOrderTypesList; + $arResult['bitrixOrderTypesList'][] = $arOrderTypesList; } while ($arOrderTypesList = $dbOrderTypesList->Fetch()); } - + //bitrix deliveryTypesList $dbDeliveryTypesList = CSaleDelivery::GetList( array( @@ -177,78 +182,78 @@ class intaro_intarocrm extends CModule false, array() ); - + if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) { do { - $arResult['bitrixDeliveryTypesList'][] = $arDeliveryTypesList; + $arResult['bitrixDeliveryTypesList'][] = $arDeliveryTypesList; } while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()); } - + //bitrix paymentTypesList $dbPaymentTypesList = CSalePaySystem::GetList( array( - "SORT" => "ASC", + "SORT" => "ASC", "NAME" => "ASC" - ), + ), array( "ACTIVE" => "Y" ) ); - + if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) { do { - $arResult['bitrixPaymentTypesList'][] = $arPaymentTypesList; + $arResult['bitrixPaymentTypesList'][] = $arPaymentTypesList; } while ($arPaymentTypesList = $dbPaymentTypesList->Fetch()); } - + //bitrix paymentStatusesList --statuses $dbPaymentStatusesList = CSaleStatus::GetList( array( - "SORT" => "ASC", + "SORT" => "ASC", "NAME" => "ASC" - ), + ), array( - "LID" => "ru", //ru + "LID" => "ru", //ru "ACTIVE" => "Y" ) ); - + if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) { do { - $arResult['bitrixPaymentStatusesList'][] = $arPaymentStatusesList; + $arResult['bitrixPaymentStatusesList'][] = $arPaymentStatusesList; } while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()); } - + $arResult['bitrixPaymentStatusesList'][] = array( 'ID' => 'Y', 'NAME' => GetMessage('CANCELED') ); - + $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_INSTALL_TITLE'), + GetMessage('MODULE_INSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step2.php' ); - + } else if ($step == 3) { if(!CModule::IncludeModule("sale")) { //handler } - - if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') - && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) { + + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') + && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) { ICrmOrderActions::uploadOrders(true); // each 50 - + $lastUpOrderId = COption::GetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0); $countLeft = (int) CSaleOrder::GetList(array("ID" => "ASC"), array('>ID' => $lastUpOrderId), array()); $countAll = (int) CSaleOrder::GetList(array("ID" => "ASC"), array(), array()); - + if(!isset($_POST['finish'])) $finish = 0; - else + else $finish = (int) $_POST['finish']; - + $percent = 100 - round(($countLeft * 100 / $countAll), 1); - + if(!$countLeft) { $api_host = COption::GetOptionString($mid, $this->CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString($mid, $this->CRM_API_KEY_OPTION, 0); @@ -256,20 +261,20 @@ class intaro_intarocrm extends CModule $this->INTARO_CRM_API->statisticUpdate(); $finish = 1; } - - + + $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset='.LANG_CHARSET); die(json_encode(array("finish" => $finish, "percent" => $percent))); } - + if (isset($_POST['back']) && $_POST['back']) { $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_INSTALL_TITLE'), + GetMessage('MODULE_INSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php' ); } - + //bitrix orderTypesList -- personTypes $dbOrderTypesList = CSalePersonType::GetList( array( @@ -283,15 +288,15 @@ class intaro_intarocrm extends CModule false, array() ); - + //form order types ids arr $orderTypesArr = array(); if ($arOrderTypesList = $dbOrderTypesList->Fetch()) { do { - $orderTypesArr[$arOrderTypesList['ID']] = htmlspecialchars(trim($_POST['order-type-' . $arOrderTypesList['ID']])); + $orderTypesArr[$arOrderTypesList['ID']] = htmlspecialchars(trim($_POST['order-type-' . $arOrderTypesList['ID']])); } while ($arOrderTypesList = $dbOrderTypesList->Fetch()); } - + //bitrix deliveryTypesList $dbDeliveryTypesList = CSaleDelivery::GetList( array( @@ -305,75 +310,75 @@ class intaro_intarocrm extends CModule false, array() ); - + //form delivery types ids arr $deliveryTypesArr = array(); if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) { do { - $deliveryTypesArr[$arDeliveryTypesList['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryTypesList['ID']])); + $deliveryTypesArr[$arDeliveryTypesList['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryTypesList['ID']])); } while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()); } - + //bitrix paymentTypesList $dbPaymentTypesList = CSalePaySystem::GetList( array( - "SORT" => "ASC", + "SORT" => "ASC", "NAME" => "ASC" - ), + ), array( "ACTIVE" => "Y" ) ); - + //form payment types ids arr $paymentTypesArr = array(); if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) { do { - $paymentTypesArr[$arPaymentTypesList['ID']] = htmlspecialchars(trim($_POST['payment-type-' . $arPaymentTypesList['ID']])); + $paymentTypesArr[$arPaymentTypesList['ID']] = htmlspecialchars(trim($_POST['payment-type-' . $arPaymentTypesList['ID']])); } while ($arPaymentTypesList = $dbPaymentTypesList->Fetch()); } - + //bitrix paymentStatusesList $dbPaymentStatusesList = CSaleStatus::GetList( array( - "SORT" => "ASC", + "SORT" => "ASC", "NAME" => "ASC" - ), + ), array( - "LID" => "ru", //ru + "LID" => "ru", //ru "ACTIVE" => "Y" ) ); - + //form payment statuses ids arr $paymentStatusesArr['Y'] = htmlspecialchars(trim($_POST['payment-status-Y'])); - + if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) { do { - $paymentStatusesArr[$arPaymentStatusesList['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $arPaymentStatusesList['ID']])); + $paymentStatusesArr[$arPaymentStatusesList['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $arPaymentStatusesList['ID']])); } while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()); } - + //form payment ids arr $paymentArr = array(); $paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y'])); $paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N'])); - + 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_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)); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0); - + $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_INSTALL_TITLE'), + GetMessage('MODULE_INSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step3.php' ); } else if ($step == 4) { - + RegisterModule($this->MODULE_ID); - + //agent $dateAgent = new DateTime(); $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec; @@ -389,21 +394,21 @@ class intaro_intarocrm extends CModule $dateAgent->format('d.m.Y H:i:s'), // date of first start 30 ); - + $this->CopyFiles(); - + $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_INSTALL_TITLE'), + GetMessage('MODULE_INSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step4.php' ); - } + } } function DoUninstall() { global $APPLICATION; - - CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID); - + + CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID); + COption::RemoveOption($this->MODULE_ID, $this->CRM_API_HOST_OPTION); COption::RemoveOption($this->MODULE_ID, $this->CRM_API_KEY_OPTION); COption::RemoveOption($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR); @@ -411,16 +416,16 @@ class intaro_intarocrm extends CModule COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES); COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT); COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_LAST_ID); - + $this->DeleteFiles(); - + UnRegisterModule($this->MODULE_ID); - + $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_UNINSTALL_TITLE'), + GetMessage('MODULE_UNINSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/unstep1.php' - ); - + ); + } function CopyFiles() { diff --git a/intaro.intarocrm/lang/ru/install/index.php b/intaro.intarocrm/lang/ru/install/index.php index c08d0e33..335823da 100755 --- a/intaro.intarocrm/lang/ru/install/index.php +++ b/intaro.intarocrm/lang/ru/install/index.php @@ -9,3 +9,5 @@ $MESS ['CANCELED'] = 'Флаг «Отменен»'; $MESS ['ERR_SALE'] = 'Отсутствует модуль sale! Дальнейшая установка невозможна.'; $MESS ['ERR_IBLOCK'] = 'Отсутствует модуль iblock! Дальнейшая установка невозможна.'; $MESS ['ERR_CATALOG'] = 'Отсутствует модуль catalog! Дальнейшая установка невозможна.'; +$MESS ['ERR_CATALOG'] = 'Отсутствует модуль catalog! Дальнейшая установка невозможна.'; +$MESS ['INTAROCRM_CURL_ERR'] = 'Для работы модуля интеграции с IntaroCRM требуется PHP-расширение CURL.'; From 598b40e7ac7f75b4c7532e046f3a2eaeeb9caf18 Mon Sep 17 00:00:00 2001 From: "m.korolev" Date: Tue, 30 Jul 2013 17:18:31 +0400 Subject: [PATCH 08/23] The IB added without property Catalog but with link SKU --- intaro.intarocrm/install/export/intarocrm_run.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intaro.intarocrm/install/export/intarocrm_run.php b/intaro.intarocrm/install/export/intarocrm_run.php index 54e880af..6b3b6b08 100755 --- a/intaro.intarocrm/install/export/intarocrm_run.php +++ b/intaro.intarocrm/install/export/intarocrm_run.php @@ -1624,7 +1624,7 @@ if (empty($arRunErrors)) $boolItemExport = true; } } - if ('X' == $arCatalog[$IBLOCK_ID]['CATALOG_TYPE'] && !$boolItemOffers) + if (('X' == $arCatalog[$IBLOCK_ID]['CATALOG_TYPE'] || 'P' == $arCatalog[$IBLOCK_ID]['CATALOG_TYPE']) && !$boolItemOffers) { $arItem['CATALOG_QUANTITY'] = ''; From cdef1b84c569868045dfcd249deea0232b430cb9 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 1 Aug 2013 18:10:51 +0400 Subject: [PATCH 09/23] +optionsOrderProps --- .../classes/general/ICrmOrderActions.php | 28 +++++++--- intaro.intarocrm/install/index.php | 12 +++++ intaro.intarocrm/lang/ru/options.php | 11 +++- intaro.intarocrm/options.php | 54 ++++++++++++++++++- 4 files changed, 95 insertions(+), 10 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 9d0542c4..c4c38e41 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -11,6 +11,7 @@ class ICrmOrderActions protected static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N protected static $CRM_ORDER_LAST_ID = 'order_last_id'; + protected static $CRM_ORDER_PROPS = 'order_props'; /** * Mass order uploading, without repeating; always returns true, but writes error log @@ -54,6 +55,7 @@ class ICrmOrderActions $optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0)); $optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses $optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0)); + $optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0)); $api = new IntaroCrm\RestApi($api_host, $api_key); @@ -62,7 +64,8 @@ class ICrmOrderActions 'optionsDelivTypes' => $optionsDelivTypes, 'optionsPayTypes' => $optionsPayTypes, 'optionsPayStatuses' => $optionsPayStatuses, - 'optionsPayment' => $optionsPayment + 'optionsPayment' => $optionsPayment, + 'optionsOrderProps' => $optionsOrderProps ); // pack mode enable / disable @@ -251,22 +254,31 @@ class ICrmOrderActions $rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID'])); while ($ar = $rsOrderProps->Fetch()) { switch ($ar['CODE']) { - case 'ZIP': $resOrderDeliveryAddress['index'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps']['index']: $resOrderDeliveryAddress['index'] = self::toJSON($ar['VALUE']); break; - case 'CITY': $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps']['city']: if ($arParams['optionsOrderProps']['index'] == 'LOCATION') { + if (!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) { + $resOrderDeliveryAddress['city'] = CSaleLocation::GetByID($ar['VALUE']); + $resOrderDeliveryAddress['city'] = self::toJSON($resOrderDeliveryAddress['city']['CITY_NAME_LANG']); + } + } else + $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); break; - case 'ADDRESS': $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']); + case 'CITY': if (!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) + $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); // we check both locations & city for export break; - case 'LOCATION': if(!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) { + case $arParams['optionsOrderProps']['text']: $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']); + break; + case 'LOCATION': if (!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) { $resOrderDeliveryAddress['city'] = CSaleLocation::GetByID($ar['VALUE']); $resOrderDeliveryAddress['city'] = self::toJSON($resOrderDeliveryAddress['city']['CITY_NAME_LANG']); } break; - case 'FIO': $resOrder['contactName'] = explode(" ", self::toJSON($ar['VALUE'])); + case $arParams['optionsOrderProps']['fio']: $resOrder['contactName'] = explode(" ", self::toJSON($ar['VALUE'])); break; - case 'PHONE': $resOrder['phone'] = $ar['VALUE']; + case $arParams['optionsOrderProps']['phone']: $resOrder['phone'] = $ar['VALUE']; break; - case 'EMAIL': $resOrder['email'] = $ar['VALUE']; + case $arParams['optionsOrderProps']['email']: $resOrder['email'] = $ar['VALUE']; break; } } diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 6250d562..6bf27495 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -30,6 +30,7 @@ class intaro_intarocrm extends CModule var $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; var $CRM_PAYMENT = 'payment_arr'; //order payment Y/N var $CRM_ORDER_LAST_ID = 'order_last_id'; + var $CRM_ORDER_PROPS = 'order_props'; var $INSTALL_PATH; @@ -363,6 +364,16 @@ class intaro_intarocrm extends CModule $paymentArr = array(); $paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y'])); $paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N'])); + + // orderProps assoc arr + $orderPropsArr = array( + 'city' => 'CITY', + 'fio' => 'FIO', + 'index' => 'ZIP', + 'text' => 'ADDRESS', + 'phone' => 'PHONE', + 'email' => 'EMAIL' + ); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr)); @@ -370,6 +381,7 @@ class intaro_intarocrm extends CModule COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT, serialize($paymentArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0); + COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_PROPS, serialize($orderPropsArr)); $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 473cf341..6def8ea0 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -1,6 +1,7 @@ GetMessage('CANCELED') ); + $dbProp = CSaleOrderProps::GetList(array(), array()); + //bitrix pyament Y/N $arResult['bitrixPaymentList'][0]['NAME'] = GetMessage('PAYMENT_Y'); $arResult['bitrixPaymentList'][0]['ID'] = 'Y'; $arResult['bitrixPaymentList'][1]['NAME'] = GetMessage('PAYMENT_N'); $arResult['bitrixPaymentList'][1]['ID'] = 'N'; + while ($arProp = $dbProp->GetNext()) { + $arResult['arProp'][] = $arProp; + } + //saved cat params $optionsOrderTypes = unserialize(COption::GetOptionString($mid, $CRM_ORDER_TYPES_ARR, 0)); $optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0)); $optionsPayTypes = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_TYPES, 0)); $optionsPayStatuses = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_STATUSES, 0)); // --statuses $optionsPayment = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT, 0)); - + $optionsOrderProps = unserialize(COption::GetOptionString($mid, $CRM_ORDER_PROPS, 0)); + $aTabs = array( array( "DIV" => "edit1", @@ -263,6 +287,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_CATALOG_CAPTION') ), + array( + "DIV" => "edit3", + "TAB" => GetMessage('ICRM_OPTIONS_ORDER_PROPS_TAB'), + "ICON" => '', + "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_PROPS_CAPTION') + ), ); $tabControl = new CAdminTabControl("tabControl", $aTabs); $tabControl->Begin(); @@ -390,6 +420,28 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { +BeginNextTab(); ?> + + + + + + + + + + + + + + BeginNextTab(); ?> Buttons(); ?> From 89356392654bdb3d376bea9cff87490ba9ed0916 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Fri, 2 Aug 2013 17:05:12 +0400 Subject: [PATCH 10/23] working props order settings --- .../classes/general/ICrmOrderActions.php | 33 ++++++-- intaro.intarocrm/install/index.php | 1 - intaro.intarocrm/install/version.php~ | 5 ++ intaro.intarocrm/lang/ru/options.php | 15 +++- intaro.intarocrm/options.php | 75 +++++++++++++++---- 5 files changed, 104 insertions(+), 25 deletions(-) create mode 100755 intaro.intarocrm/install/version.php~ diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index c4c38e41..d1327776 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -256,14 +256,6 @@ class ICrmOrderActions switch ($ar['CODE']) { case $arParams['optionsOrderProps']['index']: $resOrderDeliveryAddress['index'] = self::toJSON($ar['VALUE']); break; - case $arParams['optionsOrderProps']['city']: if ($arParams['optionsOrderProps']['index'] == 'LOCATION') { - if (!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) { - $resOrderDeliveryAddress['city'] = CSaleLocation::GetByID($ar['VALUE']); - $resOrderDeliveryAddress['city'] = self::toJSON($resOrderDeliveryAddress['city']['CITY_NAME_LANG']); - } - } else - $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); - break; case 'CITY': if (!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); // we check both locations & city for export break; @@ -281,6 +273,31 @@ class ICrmOrderActions case $arParams['optionsOrderProps']['email']: $resOrder['email'] = $ar['VALUE']; break; } + + if (count($arParams['optionsOrderProps'] > 5)) { + switch ($ar['CODE']) { + case $arParams['optionsOrderProps']['country']: $resOrderDeliveryAddress['country'] = self::toJSON($ar['VALUE']); + break; + case $arParams['optionsOrderProps']['region']: $resOrderDeliveryAddress['region'] = self::toJSON($ar['VALUE']); + break; + case $arParams['optionsOrderProps']['city']: $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); + break; + case $arParams['optionsOrderProps']['street']: $resOrderDeliveryAddress['street'] = self::toJSON($ar['VALUE']); + break; + case $arParams['optionsOrderProps']['building']: $resOrderDeliveryAddress['building'] = self::toJSON($ar['VALUE']); + break; + case $arParams['optionsOrderProps']['flat']: $resOrderDeliveryAddress['flat'] = self::toJSON($ar['VALUE']); + break; + case $arParams['optionsOrderProps']['inercomcode']: $resOrderDeliveryAddress['intercomcode'] = self::toJSON($ar['VALUE']); + break; + case $arParams['optionsOrderProps']['floor']: $resOrderDeliveryAddress['floor'] = self::toJSON($ar['VALUE']); + break; + case $arParams['optionsOrderProps']['block']: $resOrderDeliveryAddress['block'] = self::toJSON($ar['VALUE']); + break; + case $arParams['optionsOrderProps']['house']: $resOrderDeliveryAddress['house'] = self::toJSON($ar['VALUE']); + break; + } + } } $items = array(); diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 6bf27495..84b38aff 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -367,7 +367,6 @@ class intaro_intarocrm extends CModule // orderProps assoc arr $orderPropsArr = array( - 'city' => 'CITY', 'fio' => 'FIO', 'index' => 'ZIP', 'text' => 'ADDRESS', diff --git a/intaro.intarocrm/install/version.php~ b/intaro.intarocrm/install/version.php~ new file mode 100755 index 00000000..b0b13837 --- /dev/null +++ b/intaro.intarocrm/install/version.php~ @@ -0,0 +1,5 @@ + '0.4.6', + 'VERSION_DATE' => '2013-07-25 15:35:00', +); diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 6def8ea0..4237d5cf 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -26,8 +26,19 @@ $MESS ['CANCELED'] = 'Флаг «Отменен»'; $MESS ['ORDER_PROPS'] = 'Настройки соответствия полей заказа IntaroCRM свойствам заказа 1С-Битрикс'; $MESS ['FIO'] = 'ф.И.О.'; -$MESS ['CITY'] = 'Город'; $MESS ['ZIP'] = 'Индекс'; $MESS ['ADDRESS'] = 'Адрес (строкой)'; $MESS ['PHONE'] = 'Телефон'; -$MESS ['EMAIL'] = 'E-mail'; \ No newline at end of file +$MESS ['EMAIL'] = 'E-mail'; +$MESS ['COUNTRY'] = 'Страна'; +$MESS ['REGION'] = 'Область / Край'; +$MESS ['CITY'] = 'Город'; +$MESS ['STREET'] = 'Улица'; +$MESS ['BUILDING'] = 'Строение'; +$MESS ['FLAT'] = 'Квартира'; +$MESS ['INTERCOMCODE'] = 'Домофон'; +$MESS ['FLOOR'] = 'Этаж'; +$MESS ['BLOCK'] = 'Подъезд'; +$MESS ['HOUSE'] = 'Строение / корпус'; +$MESS ['ADDRESS_SHORT'] = 'Краткий адрес'; +$MESS ['ADDRESS_FULL'] = 'Детальный адрес'; \ No newline at end of file diff --git a/intaro.intarocrm/options.php b/intaro.intarocrm/options.php index edf81a90..534c89f1 100755 --- a/intaro.intarocrm/options.php +++ b/intaro.intarocrm/options.php @@ -26,16 +26,35 @@ if($_GET['ok'] && $_GET['ok'] == 'Y') echo CAdminMessage::ShowNote(GetMessage('I $arResult = array(); $arResult['orderProps'][0]['NAME'] = GetMessage('FIO'); $arResult['orderProps'][0]['ID'] = 'fio'; -$arResult['orderProps'][1]['NAME'] = GetMessage('CITY'); -$arResult['orderProps'][1]['ID'] = 'city'; -$arResult['orderProps'][2]['NAME'] = GetMessage('ZIP'); -$arResult['orderProps'][2]['ID'] = 'index'; -$arResult['orderProps'][3]['NAME'] = GetMessage('ADDRESS'); -$arResult['orderProps'][3]['ID'] = 'text'; -$arResult['orderProps'][4]['NAME'] = GetMessage('PHONE'); -$arResult['orderProps'][4]['ID'] = 'phone'; -$arResult['orderProps'][5]['NAME'] = GetMessage('EMAIL'); -$arResult['orderProps'][5]['ID'] = 'email'; +$arResult['orderProps'][1]['NAME'] = GetMessage('ZIP'); +$arResult['orderProps'][1]['ID'] = 'index'; +$arResult['orderProps'][2]['NAME'] = GetMessage('PHONE'); +$arResult['orderProps'][2]['ID'] = 'phone'; +$arResult['orderProps'][3]['NAME'] = GetMessage('EMAIL'); +$arResult['orderProps'][3]['ID'] = 'email'; +// address +$arResult['orderProps'][4]['NAME'] = GetMessage('ADDRESS'); +$arResult['orderProps'][4]['ID'] = 'text'; +$arResult['orderProps'][5]['NAME'] = GetMessage('COUNTRY'); +$arResult['orderProps'][5]['ID'] = 'country'; +$arResult['orderProps'][6]['NAME'] = GetMessage('REGION'); +$arResult['orderProps'][6]['ID'] = 'region'; +$arResult['orderProps'][7]['NAME'] = GetMessage('CITY'); +$arResult['orderProps'][7]['ID'] = 'city'; +$arResult['orderProps'][8]['NAME'] = GetMessage('STREET'); +$arResult['orderProps'][8]['ID'] = 'street'; +$arResult['orderProps'][9]['NAME'] = GetMessage('BUILDING'); +$arResult['orderProps'][9]['ID'] = 'building'; +$arResult['orderProps'][10]['NAME'] = GetMessage('FLAT'); +$arResult['orderProps'][10]['ID'] = 'flat'; +$arResult['orderProps'][11]['NAME'] = GetMessage('INTERCOMCODE'); +$arResult['orderProps'][11]['ID'] = 'intercomecode'; +$arResult['orderProps'][12]['NAME'] = GetMessage('FLOOR'); +$arResult['orderProps'][12]['ID'] = 'floor'; +$arResult['orderProps'][13]['NAME'] = GetMessage('BLOCK'); +$arResult['orderProps'][13]['ID'] = 'block'; +$arResult['orderProps'][14]['NAME'] = GetMessage('HOUSE'); +$arResult['orderProps'][14]['ID'] = 'house'; //update connection settings if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { @@ -145,8 +164,13 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y'])); $paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N'])); - foreach($arResult['orderProps'] as $orderProp) + $propsCount = 0; + foreach($arResult['orderProps'] as $orderProp) { + if((!(int) htmlspecialchars(trim($_POST['address-detail']))) && $propsCount > 4) + break; $orderPropsArr[$orderProp['ID']] = htmlspecialchars(trim($_POST['order-prop-' . $orderProp['ID']])); + $propsCount++; + } COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr)); @@ -297,6 +321,19 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $tabControl = new CAdminTabControl("tabControl", $aTabs); $tabControl->Begin(); ?> +AddHeadString(''); ?> + +
- - + + + + + + > + 5) echo "checked"; ?>> + + + + + 4) echo 'class="address-detail"'; if(($countProps > 4) && (count($optionsOrderProps) < 6)) echo 'style="display:none;"';?>> @@ -441,7 +488,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { - + BeginNextTab(); ?> Buttons(); ?> From 1a674a91befa2e107f92d80be415d2dcd98a5bbf Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 5 Aug 2013 14:46:13 +0400 Subject: [PATCH 11/23] added onCancelOrderEvent --- .../classes/general/ICrmOrderActions.php | 4 +- .../classes/general/events/ICrmOrderEvent.php | 156 ++++++++++++++++++ intaro.intarocrm/install/index.php | 6 +- intaro.intarocrm/install/version.php~ | 5 + 4 files changed, 167 insertions(+), 4 deletions(-) create mode 100644 intaro.intarocrm/classes/general/events/ICrmOrderEvent.php create mode 100755 intaro.intarocrm/install/version.php~ diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 9d0542c4..8019a41b 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -154,7 +154,7 @@ class ICrmOrderActions * * w+ event in bitrix log */ - private static function eventLog($auditType, $itemId, $description) { + public static function eventLog($auditType, $itemId, $description) { CEventLog::Add(array( "SEVERITY" => "SECURITY", "AUDIT_TYPE_ID" => $auditType, @@ -358,7 +358,7 @@ class ICrmOrderActions * @param type $str in SITE_CHARSET * @return type $str in utf-8 */ - protected static function toJSON($str) { + public static function toJSON($str) { global $APPLICATION; return $APPLICATION->ConvertCharset($str, SITE_CHARSET, 'utf-8'); diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php new file mode 100644 index 00000000..9d27758e --- /dev/null +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -0,0 +1,156 @@ + $optionsOrderTypes, + 'optionsDelivTypes' => $optionsDelivTypes, + 'optionsPayTypes' => $optionsPayTypes, + 'optionsPayStatuses' => $optionsPayStatuses, + 'optionsPayment' => $optionsPayment + ); + + $result = ICrmOrderActions::orderCreate($ID, $api, $arParams, true); + + if(!$result) { + ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'ICrmOrderActions::orderCreate', 'error during creating order'); + return true; + } + + return true; + } + + /** + * + * @param type $ID -- orderId + * @param type $cancel -- Y / N - cancel order status + * @param type $reason -- cancel reason + * @return boolean + */ + function onSaleCancelOrder($ID, $cancel, $reason) { + if(!$ID || !$cancel || ($cancel != 'Y')) + return true; + + if (!CModule::IncludeModule('iblock')) { + //handle err + ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'iblock', 'module not found'); + return true; + } + + if (!CModule::IncludeModule("sale")) { + //handle err + ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'sale', 'module not found'); + return true; + } + + if (!CModule::IncludeModule("catalog")) { + //handle err + ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'catalog', 'module not found'); + return true; + } + + $arFields = CSaleOrder::GetById($ID); + + if (empty($arFields)) { + //handle err + self::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'empty($arFields)', 'incorrect order'); + + return true; + } + + $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_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)); + $optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses + + $api = new IntaroCrm\RestApi($api_host, $api_key); + + $order = array( + 'externalId' => (int) $ID, + 'customerId' => (int) $arFields['USER_ID'], + 'orderType' => $optionsOrderTypes[$arFields['PERSON_TYPE_ID']], + 'status' => $optionsPayStatuses[$cancel], + 'statusComment' => ICrmOrderActions::toJSON($reason) + ); + + $api->orderEdit($order); + + // error pushing order + if ($api->getStatusCode() != 201) + ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'IntaroCrm\RestApi::orderEdit', $api->getLastError()); + + return true; + } +} \ No newline at end of file diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 6250d562..d470f618 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -378,6 +378,7 @@ class intaro_intarocrm extends CModule } else if ($step == 4) { RegisterModule($this->MODULE_ID); + RegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); //agent $dateAgent = new DateTime(); @@ -416,9 +417,10 @@ class intaro_intarocrm extends CModule COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES); COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT); COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_LAST_ID); - + UnRegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); + $this->DeleteFiles(); - + UnRegisterModule($this->MODULE_ID); $APPLICATION->IncludeAdminFile( diff --git a/intaro.intarocrm/install/version.php~ b/intaro.intarocrm/install/version.php~ new file mode 100755 index 00000000..b0b13837 --- /dev/null +++ b/intaro.intarocrm/install/version.php~ @@ -0,0 +1,5 @@ + '0.4.6', + 'VERSION_DATE' => '2013-07-25 15:35:00', +); From 47452c4f255928397e0261860e4d78054fa79a80 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 5 Aug 2013 14:49:51 +0400 Subject: [PATCH 12/23] upd orderEdit method --- .../classes/general/events/ICrmOrderEvent.php | 12 ------------ intaro.intarocrm/install/version.php~ | 5 ----- 2 files changed, 17 deletions(-) delete mode 100755 intaro.intarocrm/install/version.php~ diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index 9d27758e..bbdee5d5 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -118,29 +118,17 @@ class ICrmOrderEvent { ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'catalog', 'module not found'); return true; } - - $arFields = CSaleOrder::GetById($ID); - - if (empty($arFields)) { - //handle err - self::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'empty($arFields)', 'incorrect order'); - - return true; - } $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_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)); $optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses $api = new IntaroCrm\RestApi($api_host, $api_key); $order = array( 'externalId' => (int) $ID, - 'customerId' => (int) $arFields['USER_ID'], - 'orderType' => $optionsOrderTypes[$arFields['PERSON_TYPE_ID']], 'status' => $optionsPayStatuses[$cancel], 'statusComment' => ICrmOrderActions::toJSON($reason) ); diff --git a/intaro.intarocrm/install/version.php~ b/intaro.intarocrm/install/version.php~ deleted file mode 100755 index b0b13837..00000000 --- a/intaro.intarocrm/install/version.php~ +++ /dev/null @@ -1,5 +0,0 @@ - '0.4.6', - 'VERSION_DATE' => '2013-07-25 15:35:00', -); From d2aa99fdad142619e12430b294b22c01d296989b Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 5 Aug 2013 15:15:15 +0400 Subject: [PATCH 13/23] orderCreate upgrade --- .../classes/general/ICrmOrderActions.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 8019a41b..d038c82d 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -71,7 +71,7 @@ class ICrmOrderActions while ($arOrder = $dbOrder->GetNext()) { //here orders by id asc; with offset - $order = self::orderCreate($arOrder['ID'], $api, $arParams); + $order = self::orderCreate($arOrder, $api, $arParams); if (!$order) continue; @@ -99,7 +99,7 @@ class ICrmOrderActions while ($arOrder = $dbOrder->GetNext()) { // here orders by id asc - $order = self::orderCreate($arOrder['ID'], $api, $arParams); + $order = self::orderCreate($arOrder, $api, $arParams); if (!$order) continue; @@ -179,18 +179,16 @@ class ICrmOrderActions else return; } - public static function orderCreate($orderId, $api, $arParams, $send = false) { - if(!$api || empty($arParams) || !$orderId) { // add cond to check $arParams + public static function orderCreate($arFields, $api, $arParams, $send = false) { + if(!$api || empty($arParams)) { // add cond to check $arParams return false; } - - $arFields = CSaleOrder::GetById($orderId); - + if (empty($arFields)) { //handle err self::eventLog('ICrmOrderActions::orderCreate', 'empty($arFields)', 'incorrect order'); - return false; + return true; } $rsUser = CUser::GetByID($arFields['USER_ID']); From fb582a1752e250d663f3050ac01be88568aa9580 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 5 Aug 2013 15:16:52 +0400 Subject: [PATCH 14/23] func response fix --- 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 d038c82d..bc45cfdc 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -188,7 +188,7 @@ class ICrmOrderActions //handle err self::eventLog('ICrmOrderActions::orderCreate', 'empty($arFields)', 'incorrect order'); - return true; + return false; } $rsUser = CUser::GetByID($arFields['USER_ID']); From 07805eb6c4f31d0dcea309b34e5475e0811a7c4d Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 5 Aug 2013 15:25:19 +0400 Subject: [PATCH 15/23] orderCreate fix --- intaro.intarocrm/classes/general/ICrmOrderActions.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index d1327776..0ac3ea8f 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -74,7 +74,7 @@ class ICrmOrderActions while ($arOrder = $dbOrder->GetNext()) { //here orders by id asc; with offset - $order = self::orderCreate($arOrder['ID'], $api, $arParams); + $order = self::orderCreate($arOrder, $api, $arParams); if (!$order) continue; @@ -102,7 +102,7 @@ class ICrmOrderActions while ($arOrder = $dbOrder->GetNext()) { // here orders by id asc - $order = self::orderCreate($arOrder['ID'], $api, $arParams); + $order = self::orderCreate($arOrder, $api, $arParams); if (!$order) continue; @@ -182,13 +182,11 @@ class ICrmOrderActions else return; } - public static function orderCreate($orderId, $api, $arParams, $send = false) { - if(!$api || empty($arParams) || !$orderId) { // add cond to check $arParams + public static function orderCreate($arFields, $api, $arParams, $send = false) { + if(!$api || empty($arParams)) { // add cond to check $arParams return false; } - $arFields = CSaleOrder::GetById($orderId); - if (empty($arFields)) { //handle err self::eventLog('ICrmOrderActions::orderCreate', 'empty($arFields)', 'incorrect order'); From 7fdddd5edf71aac1956346b266981cc3e6c164a7 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 5 Aug 2013 15:39:37 +0400 Subject: [PATCH 16/23] orderCreate fix --- intaro.intarocrm/classes/general/events/ICrmOrderEvent.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index bbdee5d5..01ee9dcf 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -80,7 +80,8 @@ class ICrmOrderEvent { 'optionsPayment' => $optionsPayment ); - $result = ICrmOrderActions::orderCreate($ID, $api, $arParams, true); + $arOrder = CSaleOrder::GetById($ID); + $result = ICrmOrderActions::orderCreate($arOrder, $api, $arParams, true); if(!$result) { ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'ICrmOrderActions::orderCreate', 'error during creating order'); From 6db7f6e6561b5c221d22a48cf98fd8722d6b973c Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 6 Aug 2013 10:31:37 +0400 Subject: [PATCH 17/23] v3.7 --- intaro.intarocrm/install/version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index 14200c58..4f9db557 100755 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ '0.3.6', + 'VERSION' => '0.3.7', 'VERSION_DATE' => '2013-07-29 12:29:00', ); From 114b2f1aae379d49ef48571e60634d72e352a8e3 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 6 Aug 2013 10:38:27 +0400 Subject: [PATCH 18/23] after merge fixes --- intaro.intarocrm/classes/general/ICrmOrderActions.php | 4 ---- intaro.intarocrm/install/index.php | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index b687a8fb..4ed06d3f 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -186,11 +186,7 @@ class ICrmOrderActions if(!$api || empty($arParams)) { // add cond to check $arParams return false; } -<<<<<<< HEAD -======= - ->>>>>>> cancelEvent if (empty($arFields)) { //handle err self::eventLog('ICrmOrderActions::orderCreate', 'empty($arFields)', 'incorrect order'); diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 85236673..ab4c9b24 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -419,7 +419,7 @@ class intaro_intarocrm extends CModule function DoUninstall() { global $APPLICATION; - CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID); + CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID); COption::RemoveOption($this->MODULE_ID, $this->CRM_API_HOST_OPTION); COption::RemoveOption($this->MODULE_ID, $this->CRM_API_KEY_OPTION); @@ -453,4 +453,4 @@ class intaro_intarocrm extends CModule unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/intarocrm_run.php'); unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/intarocrm_setup.php'); } -} \ No newline at end of file +} From 2e4d520f659860d215a3e2948dae784eac77064e Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 6 Aug 2013 13:14:53 +0400 Subject: [PATCH 19/23] fix statistic update --- intaro.intarocrm/install/index.php | 14 +++++++------- intaro.intarocrm/install/version.php | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index ab4c9b24..07e1f9c8 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -255,14 +255,8 @@ class intaro_intarocrm extends CModule $percent = 100 - round(($countLeft * 100 / $countAll), 1); - if(!$countLeft) { - $api_host = COption::GetOptionString($mid, $this->CRM_API_HOST_OPTION, 0); - $api_key = COption::GetOptionString($mid, $this->CRM_API_KEY_OPTION, 0); - $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key); - $this->INTARO_CRM_API->statisticUpdate(); + if(!$countLeft) $finish = 1; - } - $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset='.LANG_CHARSET); @@ -408,6 +402,12 @@ class intaro_intarocrm extends CModule ); $this->CopyFiles(); + + //statistic update + $api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0); + $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0); + $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key); + $this->INTARO_CRM_API->statisticUpdate(); $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index 4f9db557..3d42ade4 100755 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ '0.3.7', - 'VERSION_DATE' => '2013-07-29 12:29:00', + 'VERSION_DATE' => '2013-08-06 13:13:00', ); From f1018091656a8cff119c622eda78bd9a8f988f0a Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 6 Aug 2013 15:02:11 +0400 Subject: [PATCH 20/23] Revert to 7fdddd5ed --- .../classes/general/ICrmOrderActions.php | 47 ++------ intaro.intarocrm/install/index.php | 29 ++--- intaro.intarocrm/install/version.php | 4 +- intaro.intarocrm/install/version.php~ | 5 - intaro.intarocrm/lang/ru/options.php | 22 +--- intaro.intarocrm/options.php | 101 +----------------- 6 files changed, 22 insertions(+), 186 deletions(-) delete mode 100755 intaro.intarocrm/install/version.php~ diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 4ed06d3f..bc45cfdc 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -11,7 +11,6 @@ class ICrmOrderActions protected static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N protected static $CRM_ORDER_LAST_ID = 'order_last_id'; - protected static $CRM_ORDER_PROPS = 'order_props'; /** * Mass order uploading, without repeating; always returns true, but writes error log @@ -55,7 +54,6 @@ class ICrmOrderActions $optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0)); $optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses $optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0)); - $optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0)); $api = new IntaroCrm\RestApi($api_host, $api_key); @@ -64,8 +62,7 @@ class ICrmOrderActions 'optionsDelivTypes' => $optionsDelivTypes, 'optionsPayTypes' => $optionsPayTypes, 'optionsPayStatuses' => $optionsPayStatuses, - 'optionsPayment' => $optionsPayment, - 'optionsOrderProps' => $optionsOrderProps + 'optionsPayment' => $optionsPayment ); // pack mode enable / disable @@ -186,7 +183,7 @@ class ICrmOrderActions if(!$api || empty($arParams)) { // add cond to check $arParams return false; } - + if (empty($arFields)) { //handle err self::eventLog('ICrmOrderActions::orderCreate', 'empty($arFields)', 'incorrect order'); @@ -252,50 +249,24 @@ class ICrmOrderActions $rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID'])); while ($ar = $rsOrderProps->Fetch()) { switch ($ar['CODE']) { - case $arParams['optionsOrderProps']['index']: $resOrderDeliveryAddress['index'] = self::toJSON($ar['VALUE']); + case 'ZIP': $resOrderDeliveryAddress['index'] = self::toJSON($ar['VALUE']); break; - case 'CITY': if (!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) - $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); // we check both locations & city for export + case 'CITY': $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); break; - case $arParams['optionsOrderProps']['text']: $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']); + case 'ADDRESS': $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']); break; - case 'LOCATION': if (!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) { + case 'LOCATION': if(!isset($resOrderDeliveryAddress['city']) && !$resOrderDeliveryAddress['city']) { $resOrderDeliveryAddress['city'] = CSaleLocation::GetByID($ar['VALUE']); $resOrderDeliveryAddress['city'] = self::toJSON($resOrderDeliveryAddress['city']['CITY_NAME_LANG']); } break; - case $arParams['optionsOrderProps']['fio']: $resOrder['contactName'] = explode(" ", self::toJSON($ar['VALUE'])); + case 'FIO': $resOrder['contactName'] = explode(" ", self::toJSON($ar['VALUE'])); break; - case $arParams['optionsOrderProps']['phone']: $resOrder['phone'] = $ar['VALUE']; + case 'PHONE': $resOrder['phone'] = $ar['VALUE']; break; - case $arParams['optionsOrderProps']['email']: $resOrder['email'] = $ar['VALUE']; + case 'EMAIL': $resOrder['email'] = $ar['VALUE']; break; } - - if (count($arParams['optionsOrderProps'] > 5)) { - switch ($ar['CODE']) { - case $arParams['optionsOrderProps']['country']: $resOrderDeliveryAddress['country'] = self::toJSON($ar['VALUE']); - break; - case $arParams['optionsOrderProps']['region']: $resOrderDeliveryAddress['region'] = self::toJSON($ar['VALUE']); - break; - case $arParams['optionsOrderProps']['city']: $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); - break; - case $arParams['optionsOrderProps']['street']: $resOrderDeliveryAddress['street'] = self::toJSON($ar['VALUE']); - break; - case $arParams['optionsOrderProps']['building']: $resOrderDeliveryAddress['building'] = self::toJSON($ar['VALUE']); - break; - case $arParams['optionsOrderProps']['flat']: $resOrderDeliveryAddress['flat'] = self::toJSON($ar['VALUE']); - break; - case $arParams['optionsOrderProps']['inercomcode']: $resOrderDeliveryAddress['intercomcode'] = self::toJSON($ar['VALUE']); - break; - case $arParams['optionsOrderProps']['floor']: $resOrderDeliveryAddress['floor'] = self::toJSON($ar['VALUE']); - break; - case $arParams['optionsOrderProps']['block']: $resOrderDeliveryAddress['block'] = self::toJSON($ar['VALUE']); - break; - case $arParams['optionsOrderProps']['house']: $resOrderDeliveryAddress['house'] = self::toJSON($ar['VALUE']); - break; - } - } } $items = array(); diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 07e1f9c8..d470f618 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -30,7 +30,6 @@ class intaro_intarocrm extends CModule var $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; var $CRM_PAYMENT = 'payment_arr'; //order payment Y/N var $CRM_ORDER_LAST_ID = 'order_last_id'; - var $CRM_ORDER_PROPS = 'order_props'; var $INSTALL_PATH; @@ -255,8 +254,14 @@ class intaro_intarocrm extends CModule $percent = 100 - round(($countLeft * 100 / $countAll), 1); - if(!$countLeft) + if(!$countLeft) { + $api_host = COption::GetOptionString($mid, $this->CRM_API_HOST_OPTION, 0); + $api_key = COption::GetOptionString($mid, $this->CRM_API_KEY_OPTION, 0); + $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key); + $this->INTARO_CRM_API->statisticUpdate(); $finish = 1; + } + $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset='.LANG_CHARSET); @@ -358,15 +363,6 @@ class intaro_intarocrm extends CModule $paymentArr = array(); $paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y'])); $paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N'])); - - // orderProps assoc arr - $orderPropsArr = array( - 'fio' => 'FIO', - 'index' => 'ZIP', - 'text' => 'ADDRESS', - 'phone' => 'PHONE', - 'email' => 'EMAIL' - ); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr)); @@ -374,7 +370,6 @@ class intaro_intarocrm extends CModule COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT, serialize($paymentArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0); - COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_PROPS, serialize($orderPropsArr)); $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), @@ -402,12 +397,6 @@ class intaro_intarocrm extends CModule ); $this->CopyFiles(); - - //statistic update - $api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0); - $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0); - $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key); - $this->INTARO_CRM_API->statisticUpdate(); $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), @@ -419,7 +408,7 @@ class intaro_intarocrm extends CModule function DoUninstall() { global $APPLICATION; - CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID); + CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID); COption::RemoveOption($this->MODULE_ID, $this->CRM_API_HOST_OPTION); COption::RemoveOption($this->MODULE_ID, $this->CRM_API_KEY_OPTION); @@ -453,4 +442,4 @@ class intaro_intarocrm extends CModule unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/intarocrm_run.php'); unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/intarocrm_setup.php'); } -} +} \ No newline at end of file diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index 3d42ade4..14200c58 100755 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ '0.3.7', - 'VERSION_DATE' => '2013-08-06 13:13:00', + 'VERSION' => '0.3.6', + 'VERSION_DATE' => '2013-07-29 12:29:00', ); diff --git a/intaro.intarocrm/install/version.php~ b/intaro.intarocrm/install/version.php~ deleted file mode 100755 index b0b13837..00000000 --- a/intaro.intarocrm/install/version.php~ +++ /dev/null @@ -1,5 +0,0 @@ - '0.4.6', - 'VERSION_DATE' => '2013-07-25 15:35:00', -); diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 4237d5cf..473cf341 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -1,7 +1,6 @@ 4) - break; - $orderPropsArr[$orderProp['ID']] = htmlspecialchars(trim($_POST['order-prop-' . $orderProp['ID']])); - $propsCount++; - } - 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_PROPS, serialize($orderPropsArr)); $uri .= '&ok=Y'; LocalRedirect($uri); @@ -278,26 +237,19 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { 'NAME' => GetMessage('CANCELED') ); - $dbProp = CSaleOrderProps::GetList(array(), array()); - //bitrix pyament Y/N $arResult['bitrixPaymentList'][0]['NAME'] = GetMessage('PAYMENT_Y'); $arResult['bitrixPaymentList'][0]['ID'] = 'Y'; $arResult['bitrixPaymentList'][1]['NAME'] = GetMessage('PAYMENT_N'); $arResult['bitrixPaymentList'][1]['ID'] = 'N'; - while ($arProp = $dbProp->GetNext()) { - $arResult['arProp'][] = $arProp; - } - //saved cat params $optionsOrderTypes = unserialize(COption::GetOptionString($mid, $CRM_ORDER_TYPES_ARR, 0)); $optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0)); $optionsPayTypes = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_TYPES, 0)); $optionsPayStatuses = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_STATUSES, 0)); // --statuses $optionsPayment = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT, 0)); - $optionsOrderProps = unserialize(COption::GetOptionString($mid, $CRM_ORDER_PROPS, 0)); - + $aTabs = array( array( "DIV" => "edit1", @@ -311,29 +263,10 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_CATALOG_CAPTION') ), - array( - "DIV" => "edit3", - "TAB" => GetMessage('ICRM_OPTIONS_ORDER_PROPS_TAB'), - "ICON" => '', - "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_PROPS_CAPTION') - ), ); $tabControl = new CAdminTabControl("tabControl", $aTabs); $tabControl->Begin(); ?> -AddHeadString(''); ?> - - -BeginNextTab(); ?> - - - - - - - - - - > - 5) echo "checked"; ?>> - - - - - 4) echo 'class="address-detail"'; if(($countProps > 4) && (count($optionsOrderProps) < 6)) echo 'style="display:none;"';?>> - - - - - - - - BeginNextTab(); ?> Buttons(); ?> From d2949b1a80c6cf7b3c2a5e1601038d56371fab6b Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 6 Aug 2013 15:09:27 +0400 Subject: [PATCH 21/23] fixes after revert --- intaro.intarocrm/install/index.php | 26 +++++++++++++------------- intaro.intarocrm/install/version.php | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index d470f618..334ec133 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -58,10 +58,10 @@ class intaro_intarocrm extends CModule { global $APPLICATION, $step, $arResult; - if (!in_array('curl', get_loaded_extensions())) { - $APPLICATION->ThrowException( GetMessage("INTAROCRM_CURL_ERR") ); - return false; - } + if (!in_array('curl', get_loaded_extensions())) { + $APPLICATION->ThrowException(GetMessage("INTAROCRM_CURL_ERR")); + return false; + } include($this->INSTALL_PATH . '/../classes/general/RestApi.php'); include($this->INSTALL_PATH . '/../classes/general/ICrmOrderActions.php'); @@ -254,15 +254,9 @@ class intaro_intarocrm extends CModule $percent = 100 - round(($countLeft * 100 / $countAll), 1); - if(!$countLeft) { - $api_host = COption::GetOptionString($mid, $this->CRM_API_HOST_OPTION, 0); - $api_key = COption::GetOptionString($mid, $this->CRM_API_KEY_OPTION, 0); - $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key); - $this->INTARO_CRM_API->statisticUpdate(); + if(!$countLeft) $finish = 1; - } - - + $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset='.LANG_CHARSET); die(json_encode(array("finish" => $finish, "percent" => $percent))); @@ -397,7 +391,13 @@ class intaro_intarocrm extends CModule ); $this->CopyFiles(); - + + // statistic update + $api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0); + $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0); + $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key); + $this->INTARO_CRM_API->statisticUpdate(); + $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step4.php' diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index 14200c58..477013cf 100755 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ '0.3.6', - 'VERSION_DATE' => '2013-07-29 12:29:00', + 'VERSION' => '0.3.7', + 'VERSION_DATE' => '2013-08-06 15:07:00', ); From 05bd2807fd2fdf9365892f812d01d91827d2e2ba Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 6 Aug 2013 15:38:22 +0400 Subject: [PATCH 22/23] bank-transfer --- intaro.intarocrm/install/step2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intaro.intarocrm/install/step2.php b/intaro.intarocrm/install/step2.php index 4be9c242..030c96f5 100755 --- a/intaro.intarocrm/install/step2.php +++ b/intaro.intarocrm/install/step2.php @@ -19,7 +19,7 @@ $defaultDelivTypes = array ( $defaultPayTypes = array ( 1 => 'cash', - 5 => 'bank-card', + 5 => 'bank-transfer', 6 => 'bank-transfer' ); From 0fc3b0d3df5b5fd738b6cf64083f7fd60d801674 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Tue, 6 Aug 2013 16:50:09 +0400 Subject: [PATCH 23/23] onSalePayOrder event --- .../classes/general/events/ICrmOrderEvent.php | 52 ++++++++++++++++++- intaro.intarocrm/install/index.php | 5 ++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index 01ee9dcf..5e9470ff 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -141,5 +141,55 @@ class ICrmOrderEvent { ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'IntaroCrm\RestApi::orderEdit', $api->getLastError()); return true; - } + } + + /** + * + * @param type $ID -- orderId + * @param type $payed -- Y / N - pay order status + * @return boolean + */ + function onSalePayOrder($ID, $payed) { + if(!$ID || !$payed || ($payed != 'Y')) + return true; + + if (!CModule::IncludeModule('iblock')) { + //handle err + ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'iblock', 'module not found'); + return true; + } + + if (!CModule::IncludeModule("sale")) { + //handle err + ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'sale', 'module not found'); + return true; + } + + if (!CModule::IncludeModule("catalog")) { + //handle err + ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'catalog', 'module not found'); + return true; + } + + $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0); + $api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0); + + //saved cat params + $optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0)); + + $api = new IntaroCrm\RestApi($api_host, $api_key); + + $order = array( + 'externalId' => (int) $ID, + 'paymentStatus' => $optionsPayment[$payed] + ); + + $api->orderEdit($order); + + // error pushing order + if ($api->getStatusCode() != 201) + ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'IntaroCrm\RestApi::orderEdit', $api->getLastError()); + + return true; + } } \ No newline at end of file diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 334ec133..e731ff7e 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -372,8 +372,11 @@ class intaro_intarocrm extends CModule } else if ($step == 4) { RegisterModule($this->MODULE_ID); + RegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); + RegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder"); + //agent $dateAgent = new DateTime(); $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec; @@ -417,6 +420,8 @@ class intaro_intarocrm extends CModule COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES); COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT); COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_LAST_ID); + + UnRegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder"); UnRegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); $this->DeleteFiles();