From 73ef894431e35a3d7a4dacec6736b84391b970c0 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 25 Jul 2013 15:30:00 +0400 Subject: [PATCH 01/11] corrected lang files; added groups of statuses; --- .../classes/general/ICrmOrderActions.php | 2 +- intaro.intarocrm/install/export/crm_run.php | 1829 +++++++++++++++++ intaro.intarocrm/install/export/crm_setup.php | 414 ++++ intaro.intarocrm/install/index.php | 20 +- intaro.intarocrm/install/step2.php | 16 +- intaro.intarocrm/install/step3.php | 4 + intaro.intarocrm/install/version.php | 4 +- intaro.intarocrm/lang/ru/install/step2.php | 4 +- intaro.intarocrm/lang/ru/install/step3.php | 2 +- intaro.intarocrm/lang/ru/options.php | 2 +- intaro.intarocrm/options.php | 15 +- 11 files changed, 2275 insertions(+), 37 deletions(-) create mode 100755 intaro.intarocrm/install/export/crm_run.php create mode 100755 intaro.intarocrm/install/export/crm_setup.php diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 39e438f8..6c201637 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -146,7 +146,7 @@ class ICrmOrderActions COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId); return true; //all ok! - } + } /** * diff --git a/intaro.intarocrm/install/export/crm_run.php b/intaro.intarocrm/install/export/crm_run.php new file mode 100755 index 00000000..ce91fb42 --- /dev/null +++ b/intaro.intarocrm/install/export/crm_run.php @@ -0,0 +1,1829 @@ +CRM +__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/export_crm.php")); +set_time_limit(0); + +global $USER, $APPLICATION; +$bTmpUserCreated = false; +if (!isset($USER) || !(($USER instanceof CUser) && ('CUser' == get_class($USER)))) +{ + $bTmpUserCreated = true; + if (isset($USER)) + { + $USER_TMP = $USER; + unset($USER); + } + + $USER = new CUser(); +} + +CCatalogDiscountSave::Disable(); + +$arYandexFields = array('vendor', 'vendorCode', 'model', 'author', 'name','product_name','xml_id', + 'publisher', 'series', 'year', 'ISBN', 'volume', 'part', + 'language', 'binding', 'page_extent', 'table_of_contents', + 'performed_by', 'performance_type', 'storage', 'format', + 'recording_length', 'artist', 'title', 'year', 'media', + 'starring', 'director', 'originalName', 'country', 'aliases', + 'description', 'sales_notes', 'promo', 'provider', 'tarifplan', + 'xCategory', 'additional', 'worldRegion', 'region', 'days', 'dataTour', + 'hotel_stars', 'room', 'meal', 'included', 'transport', 'price_min', + 'price_max', 'options', 'manufacturer_warranty', 'country_of_origin', + 'downloadable', 'param', 'place', 'hall', 'hall_part', 'is_premiere', + 'is_kids', 'date'); + +if (!function_exists("yandex_replace_special")) +{ + function yandex_replace_special($arg) + { + if (in_array($arg[0], array(""", "&", "<", ">"))) + return $arg[0]; + else + return " "; + } +} + +if (!function_exists("yandex_text2xml")) +{ + function yandex_text2xml($text, $bHSC = false, $bDblQuote = false) + { + global $APPLICATION; + + $bHSC = (true == $bHSC ? true : false); + $bDblQuote = (true == $bDblQuote ? true: false); + + if ($bHSC) + { + $text = htmlspecialcharsbx($text); + if ($bDblQuote) + $text = str_replace('"', '"', $text); + } + $text = preg_replace("/[\x1-\x8\xB-\xC\xE-\x1F]/", "", $text); + $text = str_replace("'", "'", $text); + $text = $APPLICATION->ConvertCharset($text, LANG_CHARSET, 'windows-1251'); + return $text; + } +} + +if (!function_exists('yandex_get_value')) +{ + function yandex_get_value($arOffer, $param, $PROPERTY) + { + global $IBLOCK_ID; + static $arProperties = null, $arUserTypes = null; + + if (!is_array($arProperties)) + { + $dbRes = CIBlockProperty::GetList( + array('ID' => 'ASC'), + array('IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N') + ); + + while ($arRes = $dbRes->Fetch()) + { + $arProperties[$arRes['ID']] = $arRes; + } + + if (!empty($arOffer['IBLOCK_ID']) && $arOffer['IBLOCK_ID'] != $IBLOCK_ID) + { + $dbRes = CIBlockProperty::GetList( + array('ID' => 'ASC'), + array('IBLOCK_ID' => $arOffer['IBLOCK_ID'], 'CHECK_PERMISSIONS' => 'N') + ); + + while ($arRes = $dbRes->Fetch()) + { + $arProperties[$arRes['ID']] = $arRes; + } + } + } + + $strProperty = ''; + $bParam = substr($param, 0, 6) == 'PARAM_'; + if (is_array($arProperties[$PROPERTY])) + { + $PROPERTY_CODE = $arProperties[$PROPERTY]['CODE']; + + $arProperty = $arOffer['PROPERTIES'][$PROPERTY_CODE] ? $arOffer['PROPERTIES'][$PROPERTY_CODE] : $arOffer['PROPERTIES'][$PROPERTY]; + + $value = ''; + $description = ''; + switch ($arProperties[$PROPERTY]['PROPERTY_TYPE']) + { + case 'E': + if (!empty($arProperty['VALUE'])) + { + $arCheckValue = array(); + if (!is_array($arProperty['VALUE'])) + { + $arProperty['VALUE'] = intval($arProperty['VALUE']); + if (0 < $arProperty['VALUE']) + $arCheckValue[] = $arProperty['VALUE']; + } + else + { + foreach ($arProperty['VALUE'] as &$intValue) + { + $intValue = intval($intValue); + if (0 < $intValue) + $arCheckValue[] = $intValue; + } + if (isset($intValue)) + unset($intValue); + } + if (!empty($arCheckValue)) + { + $dbRes = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $arProperties[$PROPERTY]['LINK_IBLOCK_ID'], 'ID' => $arCheckValue), false, false, array('NAME')); + while ($arRes = $dbRes->Fetch()) + { + $value .= ($value ? ', ' : '').$arRes['NAME']; + } + } + } + break; + case 'G': + if (!empty($arProperty['VALUE'])) + { + $arCheckValue = array(); + if (!is_array($arProperty['VALUE'])) + { + $arProperty['VALUE'] = intval($arProperty['VALUE']); + if (0 < $arProperty['VALUE']) + $arCheckValue[] = $arProperty['VALUE']; + } + else + { + foreach ($arProperty['VALUE'] as &$intValue) + { + $intValue = intval($intValue); + if (0 < $intValue) + $arCheckValue[] = $intValue; + } + if (isset($intValue)) + unset($intValue); + } + if (!empty($arCheckValue)) + { + $dbRes = CIBlockSection::GetList(array(), array('IBLOCK_ID' => $arProperty['LINK_IBLOCK_ID'], 'ID' => $arCheckValue), false, array('NAME')); + while ($arRes = $dbRes->Fetch()) + { + $value .= ($value ? ', ' : '').$arRes['NAME']; + } + } + } + break; + case 'L': + if ($arProperty['VALUE']) + { + if (is_array($arProperty['VALUE'])) + $value .= implode(', ', $arProperty['VALUE']); + else + $value .= $arProperty['VALUE']; + } + break; + default: + if ($bParam && $arProperty['WITH_DESCRIPTION'] == 'Y') + { + $description = $arProperty['DESCRIPTION']; + $value = $arProperty['VALUE']; + } + else + { + $value = is_array($arProperty['VALUE']) ? implode(', ', $arProperty['VALUE']) : $arProperty['VALUE']; + } + } + + // !!!! check multiple properties and properties like CML2_ATTRIBUTES + + if ($bParam) + { + if (is_array($description)) + { + foreach ($value as $key => $val) + { + $strProperty .= $strProperty ? "\n" : ""; + $strProperty .= ''.yandex_text2xml($val, true).''; + } + } + else + { + $strProperty .= ''.yandex_text2xml($value, true).''; + } + } + else + { + $param_h = yandex_text2xml($param, true); + $strProperty .= '<'.$param_h.'>'.yandex_text2xml($value, true).''; + } + } + + return $strProperty; + //if (is_callable(array($arParams["arUserField"]["USER_TYPE"]['CLASS_NAME'], 'getlist'))) + } +} + +$arRunErrors = array(); + +if ($XML_DATA && CheckSerializedData($XML_DATA)) +{ + $XML_DATA = unserialize(stripslashes($XML_DATA)); + if (!is_array($XML_DATA)) $XML_DATA = array(); +} + +$IBLOCK_ID = intval($IBLOCK_ID); +$db_iblock = CIBlock::GetByID($IBLOCK_ID); +if (!($ar_iblock = $db_iblock->Fetch())) +{ + $arRunErrors[] = str_replace('#ID#', $IBLOCK_ID, GetMessage('YANDEX_ERR_NO_IBLOCK_FOUND_EXT')); +} +/*elseif (!CIBlockRights::UserHasRightTo($IBLOCK_ID, $IBLOCK_ID, 'iblock_admin_display')) +{ + $arRunErrors[] = str_replace('#IBLOCK_ID#',$IBLOCK_ID,GetMessage('CET_ERROR_IBLOCK_PERM')); +} */ +else +{ + $SETUP_SERVER_NAME = trim($SETUP_SERVER_NAME); + + if (strlen($SETUP_SERVER_NAME) <= 0) + { + if (strlen($ar_iblock['SERVER_NAME']) <= 0) + { + $rsSite = CSite::GetList(($b="sort"), ($o="asc"), array("LID" => $ar_iblock["LID"])); + if($arSite = $rsSite->Fetch()) + $ar_iblock["SERVER_NAME"] = $arSite["SERVER_NAME"]; + if(strlen($ar_iblock["SERVER_NAME"])<=0 && defined("SITE_SERVER_NAME")) + $ar_iblock["SERVER_NAME"] = SITE_SERVER_NAME; + if(strlen($ar_iblock["SERVER_NAME"])<=0) + $ar_iblock["SERVER_NAME"] = COption::GetOptionString("main", "server_name", ""); + } + } + else + { + $ar_iblock['SERVER_NAME'] = $SETUP_SERVER_NAME; + } + $ar_iblock['PROPERTY'] = array(); + $rsProps = CIBlockProperty::GetList(array(),array('IBLOCK_ID' => $IBLOCK_ID, 'ACTIVE' => 'Y')); + while ($arProp = $rsProps->Fetch()) + { + $ar_iblock['PROPERTY'][$arProp['ID']] = $arProp; + } +} + +$boolOffers = false; +$arOffers = false; +$arOfferIBlock = false; +$intOfferIBlockID = 0; +$arSelectOfferProps = array(); +$arSelectedPropTypes = array('S','N','L','E','G'); +$arOffersSelectKeys = array( + YANDEX_SKU_EXPORT_ALL, + YANDEX_SKU_EXPORT_MIN_PRICE, + YANDEX_SKU_EXPORT_PROP, +); +$arCondSelectProp = array( + 'ZERO', + 'NONZERO', + 'EQUAL', + 'NONEQUAL', +); +$arPropertyMap = array(); +$arSKUExport = array(); + +$arCatalog = CCatalog::GetByIDExt($IBLOCK_ID); +if (empty($arCatalog)) +{ + $arRunErrors[] = str_replace('#ID#', $IBLOCK_ID, GetMessage('YANDEX_ERR_NO_IBLOCK_IS_CATALOG')); +} +else +{ + $arOffers = CCatalogSKU::GetInfoByProductIBlock($IBLOCK_ID); + if (!empty($arOffers['IBLOCK_ID'])) + { + $intOfferIBlockID = $arOffers['IBLOCK_ID']; + $rsOfferIBlocks = CIBlock::GetByID($intOfferIBlockID); + if (($arOfferIBlock = $rsOfferIBlocks->Fetch())) + { + $boolOffers = true; + $rsProps = CIBlockProperty::GetList(array('SORT' => 'ASC'),array('IBLOCK_ID' => $intOfferIBlockID,'ACTIVE' => 'Y')); + while ($arProp = $rsProps->Fetch()) + { + if ($arOffers['SKU_PROPERTY_ID'] != $arProp['ID']) + { + $ar_iblock['OFFERS_PROPERTY'][$arProp['ID']] = $arProp; + if (in_array($arProp['PROPERTY_TYPE'],$arSelectedPropTypes)) + $arSelectOfferProps[] = $arProp['ID']; + if (strlen($arProp['CODE']) > 0) + { + foreach ($ar_iblock['PROPERTY'] as &$arMainProp) + { + if ($arMainProp['CODE'] == $arProp['CODE']) + { + $arPropertyMap[$arProp['ID']] = $arMainProp['CODE']; + break; + } + } + if (isset($arMainProp)) + unset($arMainProp); + } + } + } + $arOfferIBlock['LID'] = $ar_iblock['LID']; + } + else + { + $arRunErrors[] = GetMessage('YANDEX_ERR_BAD_OFFERS_IBLOCK_ID'); + } + } + if (true == $boolOffers) + { + if (empty($XML_DATA['SKU_EXPORT'])) + { + $arRunErrors[] = GetMessage('YANDEX_ERR_SKU_SETTINGS_ABSENT'); + } + else + { + $arSKUExport = $XML_DATA['SKU_EXPORT'];; + if (empty($arSKUExport['SKU_EXPORT_COND']) || !in_array($arSKUExport['SKU_EXPORT_COND'],$arOffersSelectKeys)) + { + $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_CONDITION_ABSENT'); + } + if (YANDEX_SKU_EXPORT_PROP == $arSKUExport['SKU_EXPORT_COND']) + { + if (empty($arSKUExport['SKU_PROP_COND']) || !is_array($arSKUExport['SKU_PROP_COND'])) + { + $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_PROPERTY_ABSENT'); + } + else + { + if (empty($arSKUExport['SKU_PROP_COND']['PROP_ID']) || !in_array($arSKUExport['SKU_PROP_COND']['PROP_ID'],$arSelectOfferProps)) + { + $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_PROPERTY_ABSENT'); + } + if (empty($arSKUExport['SKU_PROP_COND']['COND']) || !in_array($arSKUExport['SKU_PROP_COND']['COND'],$arCondSelectProp)) + { + $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_PROPERTY_COND_ABSENT'); + } + else + { + if ($arSKUExport['SKU_PROP_COND']['COND'] == 'EQUAL' || $arSKUExport['SKU_PROP_COND']['COND'] == 'NONEQUAL') + { + if (empty($arSKUExport['SKU_PROP_COND']['VALUES'])) + { + $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_PROPERTY_VALUES_ABSENT'); + } + } + } + } + } + } + } +} + +if (empty($arRunErrors)) +{ + $bAllSections = False; + $arSections = array(); + if (is_array($V)) + { + foreach ($V as $key => $value) + { + if (trim($value)=="0") + { + $bAllSections = True; + break; + } + + if (intval($value)>0) + { + $arSections[] = intval($value); + } + } + } + + if (!$bAllSections && count($arSections)<=0) + { + $arRunErrors[] = GetMessage('YANDEX_ERR_NO_SECTION_LIST'); + } +} + +if (!empty($XML_DATA['PRICE'])) +{ + if (intval($XML_DATA['PRICE']) > 0) + { + $rsCatalogGroups = CCatalogGroup::GetGroupsList(array('CATALOG_GROUP_ID' => $XML_DATA['PRICE'],'GROUP_ID' => 2)); + if (!($arCatalogGroup = $rsCatalogGroups->Fetch())) + { + $arRunErrors[] = GetMessage('YANDEX_ERR_BAD_PRICE_TYPE'); + } + } + else + { + $arRunErrors[] = GetMessage('YANDEX_ERR_BAD_PRICE_TYPE'); + } +} + +if (strlen($SETUP_FILE_NAME) <= 0) +{ + $arRunErrors[] = GetMessage("CATI_NO_SAVE_FILE"); +} +elseif (preg_match(BX_CATALOG_FILENAME_REG,$SETUP_FILE_NAME)) +{ + $arRunErrors[] = GetMessage("CES_ERROR_BAD_EXPORT_FILENAME"); +} +else +{ + $SETUP_FILE_NAME = Rel2Abs("/", $SETUP_FILE_NAME); +} +if (empty($arRunErrors)) +{ +/* if ($GLOBALS["APPLICATION"]->GetFileAccessPermission($SETUP_FILE_NAME) < "W") + { + $arRunErrors[] = str_replace('#FILE#', $SETUP_FILE_NAME,GetMessage('YANDEX_ERR_FILE_ACCESS_DENIED')); + } */ +} + +if (empty($arRunErrors)) +{ + CheckDirPath($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME); + + if (!$fp = @fopen($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME, "wb")) + { + $arRunErrors[] = str_replace('#FILE#', $_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME, GetMessage('YANDEX_ERR_FILE_OPEN_WRITING')); + } + else + { + + if (!@fwrite($fp, '')) + { + $arRunErrors[] = str_replace('#FILE#', $_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME, GetMessage('YANDEX_ERR_SETUP_FILE_WRITE')); + @fclose($fp); + } + else + { + fwrite($fp, ''); + fwrite($fp, ''); + fwrite($fp, ''); + } + } +} + +if (empty($arRunErrors)) +{ + @fwrite($fp, ''); + @fwrite($fp, '"?>'); + @fwrite($fp, "\n\n"); + @fwrite($fp, "\n"); + @fwrite($fp, "\n"); + + @fwrite($fp, "".$APPLICATION->ConvertCharset(htmlspecialcharsbx(COption::GetOptionString("main", "site_name", "")), LANG_CHARSET, 'windows-1251')."\n"); + + @fwrite($fp, "".$APPLICATION->ConvertCharset(htmlspecialcharsbx(COption::GetOptionString("main", "site_name", "")), LANG_CHARSET, 'windows-1251')."\n"); + @fwrite($fp, "http://".htmlspecialcharsbx($ar_iblock['SERVER_NAME'])."\n"); + + $strTmp = "\n"; + + if ($arCurrency = CCurrency::GetByID('RUR')) + $RUR = 'RUR'; + else + $RUR = 'RUB'; + + $arCurrencyAllowed = array($RUR, 'USD', 'EUR', 'UAH', 'BYR', 'KZT'); + + $BASE_CURRENCY = CCurrency::GetBaseCurrency(); + if (is_array($XML_DATA['CURRENCY'])) + { + foreach ($XML_DATA['CURRENCY'] as $CURRENCY => $arCurData) + { + if (in_array($CURRENCY, $arCurrencyAllowed)) + { + $strTmp.= " 0 ? ' plus="'.intval($arCurData['plus']).'"' : '') + ." />\n"; + } + } + } + else + { + $db_acc = CCurrency::GetList(($by="sort"), ($order="asc")); + while ($arAcc = $db_acc->Fetch()) + { + if (in_array($arAcc['CURRENCY'], $arCurrencyAllowed)) + $strTmp.= "\n"; + } + } + $strTmp.= "\n"; + + @fwrite($fp, $strTmp); + + //*****************************************// + + + //*****************************************// + $intMaxSectionID = 0; + + $strTmpCat = ""; + $strTmpOff = ""; + + $arAvailGroups = array(); + if (!$bAllSections) + { + for ($i = 0, $intSectionsCount = count($arSections); $i < $intSectionsCount; $i++) + { + $filter_tmp = $filter; + $db_res = CIBlockSection::GetNavChain($IBLOCK_ID, $arSections[$i]); + $curLEFT_MARGIN = 0; + $curRIGHT_MARGIN = 0; + while ($ar_res = $db_res->Fetch()) + { + $curLEFT_MARGIN = intval($ar_res["LEFT_MARGIN"]); + $curRIGHT_MARGIN = intval($ar_res["RIGHT_MARGIN"]); + $arAvailGroups[$ar_res["ID"]] = array( + "ID" => intval($ar_res["ID"]), + "IBLOCK_SECTION_ID" => intval($ar_res["IBLOCK_SECTION_ID"]), + "NAME" => $ar_res["NAME"] + ); + if ($intMaxSectionID < $ar_res["ID"]) + $intMaxSectionID = $ar_res["ID"]; + } + + $filter = Array("IBLOCK_ID"=>$IBLOCK_ID, ">LEFT_MARGIN"=>$curLEFT_MARGIN, "$curRIGHT_MARGIN, "ACTIVE"=>"Y", "IBLOCK_ACTIVE"=>"Y", "GLOBAL_ACTIVE"=>"Y"); + $db_res = CIBlockSection::GetList(array("left_margin"=>"asc"), $filter); + while ($ar_res = $db_res->Fetch()) + { + $arAvailGroups[$ar_res["ID"]] = array( + "ID" => intval($ar_res["ID"]), + "IBLOCK_SECTION_ID" => intval($ar_res["IBLOCK_SECTION_ID"]), + "NAME" => $ar_res["NAME"] + ); + if ($intMaxSectionID < $ar_res["ID"]) + $intMaxSectionID = $ar_res["ID"]; + } + } + } + else + { + $filter = Array("IBLOCK_ID"=>$IBLOCK_ID, "ACTIVE"=>"Y", "IBLOCK_ACTIVE"=>"Y", "GLOBAL_ACTIVE"=>"Y"); + $db_res = CIBlockSection::GetList(array("left_margin"=>"asc"), $filter); + while ($ar_res = $db_res->Fetch()) + { + $arAvailGroups[$ar_res["ID"]] = array( + "ID" => intval($ar_res["ID"]), + "IBLOCK_SECTION_ID" => intval($ar_res["IBLOCK_SECTION_ID"]), + "NAME" => $ar_res["NAME"] + ); + if ($intMaxSectionID < $ar_res["ID"]) + $intMaxSectionID = $ar_res["ID"]; + } + } + + $arSectionIDs = array(); + foreach ($arAvailGroups as &$value) + { + $strTmpCat.= "0?" parentId=\"".$value["IBLOCK_SECTION_ID"]."\"":"").">".yandex_text2xml($value["NAME"], true)."\n"; + } + if (isset($value)) + unset($value); + + if (!empty($arAvailGroups)) + $arSectionIDs = array_keys($arAvailGroups); + + $intMaxSectionID += 100000000; + + //*****************************************// + $boolNeedRootSection = false; + + if ('D' == $arCatalog['CATALOG_TYPE'] || 'O' == $arCatalog['CATALOG_TYPE']) + { + $arSelect = array("ID", "LID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "ACTIVE", "ACTIVE_FROM", "ACTIVE_TO", "NAME", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE", "DETAIL_PICTURE", "LANG_DIR", "DETAIL_PAGE_URL"); + + $filter = Array("IBLOCK_ID"=>$IBLOCK_ID, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y"); + if (!$bAllSections) + { + $filter["INCLUDE_SUBSECTIONS"] = "Y"; + $filter["SECTION_ID"] = $arSectionIDs; + } + $res = CIBlockElement::GetList(array(), $filter, false, false, $arSelect); + + $total_sum = 0; + $is_exists = false; + $cnt = 0; + + while ($obElement = $res->GetNextElement()) + { + $arAcc = $obElement->GetFields(); + if (is_array($XML_DATA['XML_DATA'])) + { + $arAcc["PROPERTIES"] = $obElement->GetProperties(); + } + $arAcc['CATALOG_QUANTITY'] = ''; + $arAcc['CATALOG_QUANTITY_TRACE'] = 'N'; + $arProduct = CCatalogProduct::GetByID($arAcc['ID']); + if (!empty($arProduct)) + { + $arAcc['CATALOG_QUANTITY'] = $arProduct['QUANTITY']; + $arAcc['CATALOG_QUANTITY_TRACE'] = $arProduct['QUANTITY_TRACE']; + } + $str_QUANTITY = DoubleVal($arAcc["CATALOG_QUANTITY"]); + $str_QUANTITY_TRACE = $arAcc["CATALOG_QUANTITY_TRACE"]; + if (($str_QUANTITY <= 0) && ($str_QUANTITY_TRACE == "Y")) + $str_AVAILABLE = ' available="false"'; + else + $str_AVAILABLE = ' available="true"'; + + $minPrice = 0; + $minPriceRUR = 0; + $minPriceGroup = 0; + $minPriceCurrency = ""; + + if ($XML_DATA['PRICE'] > 0) + { + $rsPrices = CPrice::GetListEx(array(),array( + 'PRODUCT_ID' => $arAcc['ID'], + 'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], + 'CAN_BUY' => 'Y', + 'GROUP_GROUP_ID' => array(2), + '+<=QUANTITY_FROM' => 1, + '+>=QUANTITY_TO' => 1, + ) + ); + if ($arPrice = $rsPrices->Fetch()) + { +/* $dbVAT = CCatalogProduct::GetVATInfo($arAcc['ID']); + if ($arVat = $dbVAT->Fetch()) + { + $arVat['RATE'] = floatval($arVat['RATE'] * 0.01); + } + else + { + $arVat = array('RATE' => 0, 'VAT_INCLUDED' => 'N'); + } + $arPrice['VAT_RATE'] = $arVat['RATE']; + $arPrice['VAT_INCLUDED'] = $arVat['VAT_INCLUDED']; + if ($arPrice['VAT_INCLUDED'] == 'N') + { + $arPrice['PRICE'] *= (1 + $arPrice['VAT_RATE']); + $arPrice['VAT_INCLUDED'] = 'Y'; + } + $arPrice['PRICE'] = roundEx($arPrice['PRICE'], CATALOG_VALUE_PRECISION); + $arDiscounts = CCatalogDiscount::GetDiscount( + $arAcc['ID'], + $IBLOCK_ID, + array($XML_DATA['PRICE']), + array(2), + 'N', + $ar_iblock['LID'], + false + ); + $minPrice = CCatalogProduct::CountPriceWithDiscount($arPrice['PRICE'], $arPrice["CURRENCY"], $arDiscounts); + $minPriceGroup = $arPrice['CATALOG_GROUP_ID']; + $minPriceCurrency = $arPrice["CURRENCY"]; + $minPriceRUR = CCurrencyRates::ConvertCurrency($arPrice['PRICE'], $arPrice["CURRENCY"], $RUR); + */ + if ($arOptimalPrice = CCatalogProduct::GetOptimalPrice( + $arAcc['ID'], + 1, + array(2), // anonymous + 'N', + array($arPrice), + $ar_iblock['LID'] + )) + { + $minPrice = $arOptimalPrice['DISCOUNT_PRICE']; + $minPriceCurrency = $BASE_CURRENCY; + $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); + $minPriceGroup = $arOptimalPrice['PRICE']['CATALOG_GROUP_ID']; + } + } + } + else + { + if ($arPrice = CCatalogProduct::GetOptimalPrice( + $arAcc['ID'], + 1, + array(2), // anonymous + 'N', + array(), + $ar_iblock['LID'] + )) + { + $minPrice = $arPrice['DISCOUNT_PRICE']; + $minPriceCurrency = $BASE_CURRENCY; + $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); + $minPriceGroup = $arPrice['PRICE']['CATALOG_GROUP_ID']; + } + } + + if ($minPrice <= 0) continue; + + $boolCurrentSections = false; + $bNoActiveGroup = True; + $strTmpOff_tmp = ""; + $db_res1 = CIBlockElement::GetElementGroups($arAcc["ID"], true); + while ($ar_res1 = $db_res1->Fetch()) + { + $boolCurrentSections = true; + if (in_array(intval($ar_res1["ID"]), $arSectionIDs)) + { + $strTmpOff_tmp.= "".$ar_res1["ID"]."\n"; + $bNoActiveGroup = False; + + } + } + if (false == $boolCurrentSections) + { + $boolNeedRootSection = true; + $strTmpOff_tmp.= "".$intMaxSectionID."\n"; + } + else + { + if ($bNoActiveGroup) + continue; + } + + if (strlen($arAcc['DETAIL_PAGE_URL']) <= 0) + $arAcc['DETAIL_PAGE_URL'] = '/'; + 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']).'"'; + else + $str_TYPE = ''; + + if (!isset($arProduct["ID"])) + continue; + + $strTmpOff.= "\n"; + $strTmpOff.= "http://".$ar_iblock['SERVER_NAME'].htmlspecialcharsbx($arAcc["~DETAIL_PAGE_URL"]).(strstr($arAcc['DETAIL_PAGE_URL'], '?') === false ? '?' : '&')."r1=&r2=\n"; + + $strTmpOff.= "".$minPrice."\n"; + $strTmpOff.= "".$minPriceCurrency."\n"; + + $strTmpOff.= $strTmpOff_tmp; + + if (intval($arAcc["DETAIL_PICTURE"])>0 || intval($arAcc["PREVIEW_PICTURE"])>0) + { + $pictNo = intval($arAcc["DETAIL_PICTURE"]); + if ($pictNo<=0) $pictNo = intval($arAcc["PREVIEW_PICTURE"]); + + if ($ar_file = CFile::GetFileArray($pictNo)) + { + if(substr($ar_file["SRC"], 0, 1) == "/") + $strFile = "http://".$ar_iblock['SERVER_NAME'].implode("/", array_map("rawurlencode", explode("/", $ar_file["SRC"]))); + elseif(preg_match("/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $ar_file["SRC"], $match)) + $strFile = "http://".$match[2].'/'.implode("/", array_map("rawurlencode", explode("/", $match[3]))); + else + $strFile = $ar_file["SRC"]; + $strTmpOff.="".$strFile."\n"; + } + } + + $y = 0; + foreach ($arYandexFields as $key) + { + switch ($key) + { + case 'name': + if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) + continue; + + $strTmpOff .= "".yandex_text2xml($arAcc["NAME"], true)."\n"; + break; + case 'description': + $strTmpOff .= + "". + yandex_text2xml(TruncateText( + ($arAcc["PREVIEW_TEXT_TYPE"]=="html"? + strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arAcc["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arAcc["~PREVIEW_TEXT"])), + 255), true). + "\n"; + break; + case 'param': + if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) + { + foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) + { + $strParamValue = ''; + if ($prop_id) + { + $strParamValue = yandex_get_value($arAcc, 'PARAM_'.$key, $prop_id); + } + if ('' != $strParamValue) + $strTmpOff .= $strParamValue."\n"; + } + } + break; + case 'xml_id': + $strTmpOff .= "".yandex_text2xml($arProduct["EXTERNAL_ID"], true)."\n"; + break; + case 'product_name': + $strTmpOff .= "".yandex_text2xml($arProduct["NAME"], true)."\n"; + break; + case 'model': + case 'title': + if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) + { + if ( + $key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' + || + $key == 'title' && $XML_DATA['TYPE'] == 'artist.title' + ) + + $strTmpOff.= "<".$key.">".yandex_text2xml($arAcc["NAME"], true)."\n"; + } + else + { + $strValue = ''; + $strValue = yandex_get_value($arAcc, $key, $XML_DATA['XML_DATA'][$key]); + if ('' != $strValue) + $strTmpOff .= $strValue."\n"; + } + break; + case 'year': + $y++; + if ($XML_DATA['TYPE'] == 'artist.title') + { + if ($y == 1) continue; + } + else + { + if ($y > 1) continue; + } + + // no break here + + default: + if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) + { + $strValue = ''; + $strValue = yandex_get_value($arAcc, $key, $XML_DATA['XML_DATA'][$key]); + if ('' != $strValue) + $strTmpOff .= $strValue."\n"; + } + } + } + + $strTmpOff.= "\n"; + } + } + elseif ('P' == $arCatalog['CATALOG_TYPE'] || 'X' == $arCatalog['CATALOG_TYPE']) + { + $arOfferSelect = array("ID", "LID", "IBLOCK_ID", "ACTIVE", "NAME", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE", "DETAIL_PICTURE", "DETAIL_PAGE_URL"); + $arOfferFilter = array('IBLOCK_ID' => $intOfferIBlockID, 'PROPERTY_'.$arOffers['SKU_PROPERTY_ID'] => 0, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y"); + if (YANDEX_SKU_EXPORT_PROP == $arSKUExport['SKU_EXPORT_COND']) + { + $strExportKey = ''; + $mxValues = false; + if ($arSKUExport['SKU_PROP_COND']['COND'] == 'NONZERO' || $arSKUExport['SKU_PROP_COND']['COND'] == 'NONEQUAL') + $strExportKey = '!'; + $strExportKey .= 'PROPERTY_'.$arSKUExport['SKU_PROP_COND']['PROP_ID']; + if ($arSKUExport['SKU_PROP_COND']['COND'] == 'EQUAL' || $arSKUExport['SKU_PROP_COND']['COND'] == 'NONEQUAL') + $mxValues = $arSKUExport['SKU_PROP_COND']['VALUES']; + $arOfferFilter[$strExportKey] = $mxValues; + } + + $arSelect = array("ID", "LID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "ACTIVE", "ACTIVE_FROM", "ACTIVE_TO", "NAME", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE", "DETAIL_PICTURE", "DETAIL_PAGE_URL"); + $arFilter = Array("IBLOCK_ID"=>$IBLOCK_ID, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y"); + if (!$bAllSections) + { + $arFilter["INCLUDE_SUBSECTIONS"] = "Y"; + $arFilter["SECTION_ID"] = $arSectionIDs; + } + + $strOfferTemplateURL = ''; + if (!empty($arSKUExport['SKU_URL_TEMPLATE_TYPE'])) + { + switch($arSKUExport['SKU_URL_TEMPLATE_TYPE']) + { + case YANDEX_SKU_TEMPLATE_PRODUCT: + $strOfferTemplateURL = '#PRODUCT_URL#'; + break; + case YANDEX_SKU_TEMPLATE_CUSTOM: + if (!empty($arSKUExport['SKU_URL_TEMPLATE'])) + $strOfferTemplateURL = $arSKUExport['SKU_URL_TEMPLATE']; + break; + case YANDEX_SKU_TEMPLATE_OFFERS: + default: + $strOfferTemplateURL = ''; + break; + } + } + + $rsItems = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelect); + + while ($obItem = $rsItems->GetNextElement()) + { + $arItem = $obItem->GetFields(); + + $arItem['PROPERTIES'] = $obItem->GetProperties(); + if (!empty($arItem['PROPERTIES'])) + { + $arCross = array(); + foreach ($arItem['PROPERTIES'] as &$arProp) + { + $arCross[$arProp['ID']] = $arProp; + } + if (isset($arProp)) + unset($arProp); + $arItem['PROPERTIES'] = $arCross; + } + $boolItemExport = false; + $boolItemOffers = false; + $arItem['OFFERS'] = array(); + + $boolCurrentSections = false; + $boolNoActiveSections = true; + $strSections = ''; + $rsSections = CIBlockElement::GetElementGroups($arItem["ID"]); + while ($arSection = $rsSections->Fetch()) + { + $boolCurrentSections = true; + if (in_array(intval($arSection["ID"]), $arSectionIDs)) + { + $strSections .= "".$arSection["ID"]."\n"; + $boolNoActiveSections = false; + } + } + if (false == $boolCurrentSections) + { + $boolNeedRootSection = true; + $strSections .= "".$intMaxSectionID."\n"; + } + else + { + if ($boolNoActiveSections) + continue; + } + + $arItem['YANDEX_CATEGORY'] = $strSections; + + $strFile = ''; + if (intval($arItem["DETAIL_PICTURE"])>0 || intval($arItem["PREVIEW_PICTURE"])>0) + { + $pictNo = intval($arItem["DETAIL_PICTURE"]); + if ($pictNo <= 0) + $pictNo = intval($arItem["PREVIEW_PICTURE"]); + + if ($ar_file = CFile::GetFileArray($pictNo)) + { + if(substr($ar_file["SRC"], 0, 1) == "/") + $strFile = "http://".$ar_iblock['SERVER_NAME'].implode("/", array_map("rawurlencode", explode("/", $ar_file["SRC"]))); + elseif(preg_match("/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $ar_file["SRC"], $match)) + $strFile = "http://".$match[2].'/'.implode("/", array_map("rawurlencode", explode("/", $match[3]))); + else + $strFile = $ar_file["SRC"]; + } + } + $arItem['YANDEX_PICT'] = $strFile; + + $arItem['YANDEX_DESCR'] = yandex_text2xml(TruncateText( + ($arItem["PREVIEW_TEXT_TYPE"]=="html"? + strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arItem["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arItem["~PREVIEW_TEXT"])), + 255), true); + + $arOfferFilter['PROPERTY_'.$arOffers['SKU_PROPERTY_ID']] = $arItem['ID']; + $rsOfferItems = CIBlockElement::GetList(array(),$arOfferFilter,false,false,$arOfferSelect); + + if (!empty($strOfferTemplateURL)) + $rsOfferItems->SetUrlTemplates($strOfferTemplateURL); + if (YANDEX_SKU_EXPORT_MIN_PRICE == $arSKUExport['SKU_EXPORT_COND']) + { + $arCurrentOffer = false; + $arCurrentPrice = false; + $dblAllMinPrice = 0; + $boolFirst = true; + + while ($obOfferItem = $rsOfferItems->GetNextElement()) + { + $arOfferItem = $obOfferItem->GetFields(); + $minPrice = -1; + if ($XML_DATA['PRICE'] > 0) + { + $rsPrices = CPrice::GetListEx(array(),array( + 'PRODUCT_ID' => $arOfferItem['ID'], + 'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], + 'CAN_BUY' => 'Y', + 'GROUP_GROUP_ID' => array(2), + '+<=QUANTITY_FROM' => 1, + '+>=QUANTITY_TO' => 1, + ) + ); + if ($arPrice = $rsPrices->Fetch()) + { +/* $dbVAT = CCatalogProduct::GetVATInfo($arOfferItem['ID']); + if ($arVat = $dbVAT->Fetch()) + { + $arVat['RATE'] = floatval($arVat['RATE'] * 0.01); + } + else + { + $arVat = array('RATE' => 0, 'VAT_INCLUDED' => 'N'); + } + $arPrice['VAT_RATE'] = $arVat['RATE']; + $arPrice['VAT_INCLUDED'] = $arVat['VAT_INCLUDED']; + if ($arPrice['VAT_INCLUDED'] == 'N') + { + $arPrice['PRICE'] *= (1 + $arPrice['VAT_RATE']); + $arPrice['VAT_INCLUDED'] = 'Y'; + } + $arPrice['PRICE'] = roundEx($arPrice['PRICE'], CATALOG_VALUE_PRECISION); + $arDiscounts = CCatalogDiscount::GetDiscount( + $arOfferItem['ID'], + $intOfferIBlockID, + array($XML_DATA['PRICE']), + array(2), + 'N', + $arOfferIBlock['LID'], + false + ); + $minPrice = CCatalogProduct::CountPriceWithDiscount($arPrice['PRICE'], $arPrice["CURRENCY"], $arDiscounts); + $minPriceGroup = $arPrice['CATALOG_GROUP_ID']; + $minPriceCurrency = $arPrice["CURRENCY"]; + $minPriceRUR = CCurrencyRates::ConvertCurrency($arPrice['PRICE'], $arPrice["CURRENCY"], $RUR); */ + if ($arOptimalPrice = CCatalogProduct::GetOptimalPrice( + $arOfferItem['ID'], + 1, + array(2), + 'N', + array($arPrice), + $arOfferIBlock['LID'] + )) + { + $minPrice = $arOptimalPrice['DISCOUNT_PRICE']; + $minPriceCurrency = $BASE_CURRENCY; + $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); + $minPriceGroup = $arOptimalPrice['PRICE']['CATALOG_GROUP_ID']; + } + } + } + else + { + if ($arPrice = CCatalogProduct::GetOptimalPrice( + $arOfferItem['ID'], + 1, + array(2), // anonymous + 'N', + array(), + $arOfferIBlock['LID'] + )) + { + $minPrice = $arPrice['DISCOUNT_PRICE']; + $minPriceCurrency = $BASE_CURRENCY; + $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); + $minPriceGroup = $arPrice['PRICE']['CATALOG_GROUP_ID']; + } + } + if ($minPrice <= 0) + continue; + if ($boolFirst) + { + $dblAllMinPrice = $minPriceRUR; + $arOfferItem['PROPERTIES'] = $obOfferItem->GetProperties(); + $arCross = array(); + foreach ($arOfferItem['PROPERTIES'] as $arProp) + { + $arCross[$arProp['ID']] = $arProp; + } + if (!empty($arItem['PROPERTIES'])) + { + $arOfferItem['PROPERTIES'] = $arCross + $arItem['PROPERTIES']; + } + else + { + $arOfferItem['PROPERTIES'] = $arCross; + } + + $arCurrentOffer = $arOfferItem; + $arCurrentPrice = array( + 'MIN_PRICE' => $minPrice, + 'MIN_PRICE_CURRENCY' => $minPriceCurrency, + 'MIN_PRICE_RUR' => $minPriceRUR, + 'MIN_PRICE_GROUP' => $minPriceGroup, + ); + $boolFirst = false; + } + else + { + if ($dblAllMinPrice > $minPriceRUR) + { + $dblAllMinPrice > $minPriceRUR; + $arOfferItem['PROPERTIES'] = $obOfferItem->GetProperties(); + $arCross = array(); + foreach ($arOfferItem['PROPERTIES'] as $arProp) + { + $arCross[$arProp['ID']] = $arProp; + } + if (!empty($arItem['PROPERTIES'])) + { + $arOfferItem['PROPERTIES'] = $arCross + $arItem['PROPERTIES']; + } + else + { + $arOfferItem['PROPERTIES'] = $arCross; + } + + $arCurrentOffer = $arOfferItem; + $arCurrentPrice = array( + 'MIN_PRICE' => $minPrice, + 'MIN_PRICE_CURRENCY' => $minPriceCurrency, + 'MIN_PRICE_RUR' => $minPriceRUR, + 'MIN_PRICE_GROUP' => $minPriceGroup, + ); + } + } + } + if (!empty($arCurrentOffer) && !empty($arCurrentPrice)) + { + $arOfferItem = $arCurrentOffer; + $minPrice = $arCurrentPrice['MIN_PRICE']; + $minPriceCurrency = $arCurrentPrice['MIN_PRICE_CURRENCY']; + $minPriceRUR = $arCurrentPrice['MIN_PRICE_RUR']; + $minPriceGroup = $arCurrentPrice['MIN_PRICE_GROUP']; + + $arOfferItem['CATALOG_QUANTITY'] = ''; + $arOfferItem['CATALOG_QUANTITY_TRACE'] = 'N'; + $arProduct = CCatalogProduct::GetByID($arOfferItem['ID']); + if (!empty($arProduct)) + { + $arOfferItem['CATALOG_QUANTITY'] = $arProduct['QUANTITY']; + $arOfferItem['CATALOG_QUANTITY_TRACE'] = $arProduct['QUANTITY_TRACE']; + } + $arOfferItem['YANDEX_AVAILABLE'] = 'true'; + $str_QUANTITY = DoubleVal($arOfferItem["CATALOG_QUANTITY"]); + $str_QUANTITY_TRACE = $arOfferItem["CATALOG_QUANTITY_TRACE"]; + if (($str_QUANTITY <= 0) && ($str_QUANTITY_TRACE == "Y")) + $arOfferItem['YANDEX_AVAILABLE'] = 'false'; + + if (strlen($arOfferItem['DETAIL_PAGE_URL']) <= 0) + $arOfferItem['DETAIL_PAGE_URL'] = '/'; + 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']).'"'; + else + $str_TYPE = ''; + + $arOfferItem['YANDEX_TYPE'] = $str_TYPE; + + if(!isset($arItem["ID"])) + continue; + + $strOfferYandex = ''; + $strOfferYandex .= "\n"; + $strOfferYandex .= "http://".$ar_iblock['SERVER_NAME'].htmlspecialcharsbx($arOfferItem["~DETAIL_PAGE_URL"]).(strstr($arOfferItem['DETAIL_PAGE_URL'], '?') === false ? '?' : '&')."r1=&r2=\n"; + + $strOfferYandex .= "".$minPrice."\n"; + $strOfferYandex .= "".$minPriceCurrency."\n"; + + $strOfferYandex .= $arItem['YANDEX_CATEGORY']; + + $strFile = ''; + if (intval($arOfferItem["DETAIL_PICTURE"])>0 || intval($arOfferItem["PREVIEW_PICTURE"])>0) + { + $pictNo = intval($arOfferItem["DETAIL_PICTURE"]); + if ($pictNo<=0) + $pictNo = intval($arOfferItem["PREVIEW_PICTURE"]); + + if ($ar_file = CFile::GetFileArray($pictNo)) + { + if(substr($ar_file["SRC"], 0, 1) == "/") + $strFile = "http://".$ar_iblock['SERVER_NAME'].implode("/", array_map("rawurlencode", explode("/", $ar_file["SRC"]))); + elseif(preg_match("/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $ar_file["SRC"], $match)) + $strFile = "http://".$match[2].'/'.implode("/", array_map("rawurlencode", explode("/", $match[3]))); + else + $strFile = $ar_file["SRC"]; + } + } + if (!empty($strFile) || !empty($arItem['YANDEX_PICT'])) + { + $strOfferYandex .= "".(!empty($strFile) ? $strFile : $arItem['YANDEX_PICT'])."\n"; + } + + $y = 0; + foreach ($arYandexFields as $key) + { + switch ($key) + { + case 'name': + if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) + continue; + + $strOfferYandex .= "".yandex_text2xml($arOfferItem["NAME"], true)."\n"; + break; + case 'description': + $strOfferYandex .= ""; + if (strlen($arOfferItem['~PREVIEW_TEXT']) <= 0) + { + $strOfferYandex .= $arItem['YANDEX_DESCR']; + } + else + { + $strOfferYandex .= yandex_text2xml(TruncateText( + ($arOfferItem["PREVIEW_TEXT_TYPE"]=="html"? + strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferItem["~PREVIEW_TEXT"])) : $arOfferItem["~PREVIEW_TEXT"]), + 255), + true); + } + $strOfferYandex .= "\n"; + break; + case 'param': + if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) + { + foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) + { + $strParamValue = ''; + if ($prop_id) + { + $strParamValue = yandex_get_value($arOfferItem, 'PARAM_'.$key, $prop_id); + } + if ('' != $strParamValue) + $strOfferYandex .= $strParamValue."\n"; + } + } + break; + case 'xml_id': + $strOfferYandex .= "".yandex_text2xml($arItem["EXTERNAL_ID"], true)."\n"; + break; + case 'product_name': + $strOfferYandex .= "".yandex_text2xml($arItem["NAME"], true)."\n"; + break; + case 'model': + case 'title': + if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) + { + if ( + $key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' + || + $key == 'title' && $XML_DATA['TYPE'] == 'artist.title' + ) + $strOfferYandex .= "<".$key.">".yandex_text2xml($arOfferItem["NAME"], true)."\n"; + } + else + { + $strValue = ''; + $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key]); + if ('' != $strValue) + $strOfferYandex .= $strValue."\n"; + } + break; + case 'year': + $y++; + if ($XML_DATA['TYPE'] == 'artist.title') + { + if ($y == 1) continue; + } + else + { + if ($y > 1) continue; + } + // no break here + default: + if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) + { + $strValue = ''; + $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key]); + if ('' != $strValue) + $strOfferYandex .= $strValue."\n"; + } + } + } + + $strOfferYandex .= "\n"; + $arItem['OFFERS'][] = $strOfferYandex; + $boolItemOffers = true; + $boolItemExport = true; + } + } + else + { + while ($obOfferItem = $rsOfferItems->GetNextElement()) + { + $arOfferItem = $obOfferItem->GetFields(); + $arOfferItem['PROPERTIES'] = $obOfferItem->GetProperties(); + $arCross = array(); + foreach ($arOfferItem['PROPERTIES'] as $arProp) + { + $arCross[$arProp['ID']] = $arProp; + } + if (!empty($arItem['PROPERTIES'])) + { + $arOfferItem['PROPERTIES'] = $arCross + $arItem['PROPERTIES']; + } + else + { + $arOfferItem['PROPERTIES'] = $arCross; + } + + $arOfferItem['CATALOG_QUANTITY'] = ''; + $arOfferItem['CATALOG_QUANTITY_TRACE'] = 'N'; + $arProduct = CCatalogProduct::GetByID($arOfferItem['ID']); + if (!empty($arProduct)) + { + $arOfferItem['CATALOG_QUANTITY'] = $arProduct['QUANTITY']; + $arOfferItem['CATALOG_QUANTITY_TRACE'] = $arProduct['QUANTITY_TRACE']; + } + $arOfferItem['YANDEX_AVAILABLE'] = 'true'; + $str_QUANTITY = DoubleVal($arOfferItem["CATALOG_QUANTITY"]); + $str_QUANTITY_TRACE = $arOfferItem["CATALOG_QUANTITY_TRACE"]; + if (($str_QUANTITY <= 0) && ($str_QUANTITY_TRACE == "Y")) + $arOfferItem['YANDEX_AVAILABLE'] = 'false'; + + $minPrice = -1; + if ($XML_DATA['PRICE'] > 0) + { + $rsPrices = CPrice::GetListEx(array(),array( + 'PRODUCT_ID' => $arOfferItem['ID'], + 'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], + 'CAN_BUY' => 'Y', + 'GROUP_GROUP_ID' => array(2), + '+<=QUANTITY_FROM' => 1, + '+>=QUANTITY_TO' => 1, + ) + ); + if ($arPrice = $rsPrices->Fetch()) + { +/* $dbVAT = CCatalogProduct::GetVATInfo($arOfferItem['ID']); + if ($arVat = $dbVAT->Fetch()) + { + $arVat['RATE'] = floatval($arVat['RATE'] * 0.01); + } + else + { + $arVat = array('RATE' => 0, 'VAT_INCLUDED' => 'N'); + } + $arPrice['VAT_RATE'] = $arVat['RATE']; + $arPrice['VAT_INCLUDED'] = $arVat['VAT_INCLUDED']; + if ($arPrice['VAT_INCLUDED'] == 'N') + { + $arPrice['PRICE'] *= (1 + $arPrice['VAT_RATE']); + $arPrice['VAT_INCLUDED'] = 'Y'; + } + $arPrice['PRICE'] = roundEx($arPrice['PRICE'], CATALOG_VALUE_PRECISION); + $arDiscounts = CCatalogDiscount::GetDiscount( + $arOfferItem['ID'], + $intOfferIBlockID, + array($XML_DATA['PRICE']), + array(2), + 'N', + $arOfferIBlock['LID'], + false + ); + $minPrice = CCatalogProduct::CountPriceWithDiscount($arPrice['PRICE'], $arPrice["CURRENCY"], $arDiscounts); + $minPriceGroup = $arPrice['CATALOG_GROUP_ID']; + $minPriceCurrency = $arPrice["CURRENCY"]; + $minPriceRUR = CCurrencyRates::ConvertCurrency($arPrice['PRICE'], $arPrice["CURRENCY"], $RUR); */ + if ($arOptimalPrice = CCatalogProduct::GetOptimalPrice( + $arOfferItem['ID'], + 1, + array(2), + 'N', + array($arPrice), + $arOfferIBlock['LID'] + )) + { + $minPrice = $arOptimalPrice['DISCOUNT_PRICE']; + $minPriceCurrency = $BASE_CURRENCY; + $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); + $minPriceGroup = $arOptimalPrice['PRICE']['CATALOG_GROUP_ID']; + } + + } + } + else + { + if ($arPrice = CCatalogProduct::GetOptimalPrice( + $arOfferItem['ID'], + 1, + array(2), // anonymous + 'N', + array(), + $arOfferIBlock['LID'] + )) + { + $minPrice = $arPrice['DISCOUNT_PRICE']; + $minPriceCurrency = $BASE_CURRENCY; + $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); + $minPriceGroup = $arPrice['PRICE']['CATALOG_GROUP_ID']; + } + } + if ($minPrice <= 0) + continue; + + if (strlen($arOfferItem['DETAIL_PAGE_URL']) <= 0) + $arOfferItem['DETAIL_PAGE_URL'] = '/'; + 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']).'"'; + else + $str_TYPE = ''; + + $arOfferItem['YANDEX_TYPE'] = $str_TYPE; + + if(!isset($arItem["ID"])) + continue; + + $strOfferYandex = ''; + $strOfferYandex .= "\n"; + $strOfferYandex .= "http://".$ar_iblock['SERVER_NAME'].htmlspecialcharsbx($arOfferItem["~DETAIL_PAGE_URL"]).(strstr($arOfferItem['DETAIL_PAGE_URL'], '?') === false ? '?' : '&')."r1=&r2=\n"; + + $strOfferYandex .= "".$minPrice."\n"; + $strOfferYandex .= "".$minPriceCurrency."\n"; + + $strOfferYandex .= $arItem['YANDEX_CATEGORY']; + + $strFile = ''; + if (intval($arOfferItem["DETAIL_PICTURE"])>0 || intval($arOfferItem["PREVIEW_PICTURE"])>0) + { + $pictNo = intval($arOfferItem["DETAIL_PICTURE"]); + if ($pictNo<=0) + $pictNo = intval($arOfferItem["PREVIEW_PICTURE"]); + + if ($ar_file = CFile::GetFileArray($pictNo)) + { + if(substr($ar_file["SRC"], 0, 1) == "/") + $strFile = "http://".$ar_iblock['SERVER_NAME'].implode("/", array_map("rawurlencode", explode("/", $ar_file["SRC"]))); + elseif(preg_match("/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $ar_file["SRC"], $match)) + $strFile = "http://".$match[2].'/'.implode("/", array_map("rawurlencode", explode("/", $match[3]))); + else + $strFile = $ar_file["SRC"]; + } + } + if (!empty($strFile) || !empty($arItem['YANDEX_PICT'])) + { + $strOfferYandex .= "".(!empty($strFile) ? $strFile : $arItem['YANDEX_PICT'])."\n"; + } + + $y = 0; + foreach ($arYandexFields as $key) + { + switch ($key) + { + case 'name': + if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) + continue; + + $strOfferYandex .= "".yandex_text2xml($arOfferItem["NAME"], true)."\n"; + break; + case 'description': + $strOfferYandex .= ""; + if (strlen($arOfferItem['~PREVIEW_TEXT']) <= 0) + { + $strOfferYandex .= $arItem['YANDEX_DESCR']; + } + else + { + $strOfferYandex .= yandex_text2xml(TruncateText( + ($arOfferItem["PREVIEW_TEXT_TYPE"]=="html"? + strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferItem["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferItem["~PREVIEW_TEXT"])), + 255), + true); + } + $strOfferYandex .= "\n"; + break; + case 'param': + if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) + { + foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) + { + $strParamValue = ''; + if ($prop_id) + { + $strParamValue = yandex_get_value($arOfferItem, 'PARAM_'.$key, $prop_id); + } + if ('' != $strParamValue) + $strOfferYandex .= $strParamValue."\n"; + } + } + break; + case 'xml_id': + $strOfferYandex .= "".yandex_text2xml($arItem["EXTERNAL_ID"], true)."\n"; + break; + case 'product_name': + $strOfferYandex .= "".yandex_text2xml($arItem["NAME"], true)."\n"; + break; + case 'model': + case 'title': + if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) + { + if ( + $key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' + || + $key == 'title' && $XML_DATA['TYPE'] == 'artist.title' + ) + $strOfferYandex .= "<".$key.">".yandex_text2xml($arOfferItem["NAME"], true)."\n"; + } + else + { + $strValue = ''; + $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key]); + if ('' != $strValue) + $strOfferYandex .= $strValue."\n"; + } + break; + case 'year': + $y++; + if ($XML_DATA['TYPE'] == 'artist.title') + { + if ($y == 1) continue; + } + else + { + if ($y > 1) continue; + } + // no break here + default: + if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) + { + $strValue = ''; + $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key]); + if ('' != $strValue) + $strOfferYandex .= $strValue."\n"; + } + } + } + + $strOfferYandex .= "\n"; + $arItem['OFFERS'][] = $strOfferYandex; + $boolItemOffers = true; + $boolItemExport = true; + } + } + if ('X' == $arCatalog['CATALOG_TYPE'] && !$boolItemOffers) + { + $arItem['CATALOG_QUANTITY'] = ''; + $arItem['CATALOG_QUANTITY_TRACE'] = 'N'; + $arProduct = CCatalogProduct::GetByID($arItem['ID']); + if (!empty($arProduct)) + { + $arItem['CATALOG_QUANTITY'] = $arProduct['QUANTITY']; + $arItem['CATALOG_QUANTITY_TRACE'] = $arProduct['QUANTITY_TRACE']; + } + $str_QUANTITY = DoubleVal($arItem["CATALOG_QUANTITY"]); + $str_QUANTITY_TRACE = $arItem["CATALOG_QUANTITY_TRACE"]; + if (($str_QUANTITY <= 0) && ($str_QUANTITY_TRACE == "Y")) + $str_AVAILABLE = ' available="false"'; + else + $str_AVAILABLE = ' available="true"'; + + $minPrice = 0; + $minPriceRUR = 0; + $minPriceGroup = 0; + $minPriceCurrency = ""; + + if ($XML_DATA['PRICE'] > 0) + { + $rsPrices = CPrice::GetListEx(array(),array( + 'PRODUCT_ID' => $arItem['ID'], + 'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], + 'CAN_BUY' => 'Y', + 'GROUP_GROUP_ID' => array(2), + '+<=QUANTITY_FROM' => 1, + '+>=QUANTITY_TO' => 1, + ) + ); + if ($arPrice = $rsPrices->Fetch()) + { +/* $dbVAT = CCatalogProduct::GetVATInfo($arItem['ID']); + if ($arVat = $dbVAT->Fetch()) + { + $arVat['RATE'] = floatval($arVat['RATE'] * 0.01); + } + else + { + $arVat = array('RATE' => 0, 'VAT_INCLUDED' => 'N'); + } + $arPrice['VAT_RATE'] = $arVat['RATE']; + $arPrice['VAT_INCLUDED'] = $arVat['VAT_INCLUDED']; + if ($arPrice['VAT_INCLUDED'] == 'N') + { + $arPrice['PRICE'] *= (1 + $arPrice['VAT_RATE']); + $arPrice['VAT_INCLUDED'] = 'Y'; + } + $arPrice['PRICE'] = roundEx($arPrice['PRICE'], CATALOG_VALUE_PRECISION); + $arDiscounts = CCatalogDiscount::GetDiscount( + $arItem['ID'], + $IBLOCK_ID, + array($XML_DATA['PRICE']), + array(2), + 'N', + $ar_iblock['LID'], + false + ); + $minPrice = CCatalogProduct::CountPriceWithDiscount($arPrice['PRICE'], $arPrice["CURRENCY"], $arDiscounts); + $minPriceGroup = $arPrice['CATALOG_GROUP_ID']; + $minPriceCurrency = $arPrice["CURRENCY"]; + $minPriceRUR = CCurrencyRates::ConvertCurrency($arPrice['PRICE'], $arPrice["CURRENCY"], $RUR); */ + if ($arOptimalPrice = CCatalogProduct::GetOptimalPrice( + $arItem['ID'], + 1, + array(2), + 'N', + array($arPrice), + $ar_iblock['LID'] + )) + { + $minPrice = $arOptimalPrice['DISCOUNT_PRICE']; + $minPriceCurrency = $BASE_CURRENCY; + $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); + $minPriceGroup = $arOptimalPrice['PRICE']['CATALOG_GROUP_ID']; + } + } + } + else + { + if ($arPrice = CCatalogProduct::GetOptimalPrice( + $arItem['ID'], + 1, + array(2), // anonymous + 'N', + array(), + $ar_iblock['LID'] + )) + { + $minPrice = $arPrice['DISCOUNT_PRICE']; + $minPriceCurrency = $BASE_CURRENCY; + $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); + $minPriceGroup = $arPrice['PRICE']['CATALOG_GROUP_ID']; + } + } + + if ($minPrice <= 0) continue; + + if ('' == $arItem['DETAIL_PAGE_URL']) + { + $arItem['DETAIL_PAGE_URL'] = '/'; + } + else + { + $arItem['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arItem['DETAIL_PAGE_URL']); + } + if ('' == $arItem['~DETAIL_PAGE_URL']) + { + $arItem['~DETAIL_PAGE_URL'] = '/'; + } + else + { + $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']).'"'; + else + $str_TYPE = ''; + if (!isset($arItem["ID"])) + continue; + + $strOfferYandex = ''; + $strOfferYandex.= "\n"; + $strOfferYandex.= "http://".$ar_iblock['SERVER_NAME'].htmlspecialcharsbx($arItem["~DETAIL_PAGE_URL"]).(strstr($arItem['DETAIL_PAGE_URL'], '?') === false ? '?' : '&')."r1=&r2=\n"; + + $strOfferYandex.= "".$minPrice."\n"; + $strOfferYandex.= "".$minPriceCurrency."\n"; + + $strOfferYandex.= $arItem['YANDEX_CATEGORY']; + + if (!empty($arItem['YANDEX_PICT'])) + { + $strOfferYandex .= "".$arItem['YANDEX_PICT']."\n"; + } + + $y = 0; + foreach ($arYandexFields as $key) + { + $strValue = ''; + switch ($key) + { + case 'name': + if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) + continue; + + $strValue = "".yandex_text2xml($arItem["NAME"], true)."\n"; + break; + case 'description': + $strValue = + "". + yandex_text2xml(TruncateText( + ($arItem["PREVIEW_TEXT_TYPE"]=="html"? + strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arItem["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arItem["~PREVIEW_TEXT"])), + 255), true). + "\n"; + break; + case 'param': + if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) + { + foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) + { + $strParamValue = ''; + if ($prop_id) + { + $strParamValue = yandex_get_value($arItem, 'PARAM_'.$key, $prop_id); + } + if ('' != $strParamValue) + $strValue .= $strParamValue."\n"; + } + } + break; + case 'xml_id': + $strValue .= "".yandex_text2xml($arItem["EXTERNAL_ID"], true)."\n"; + break; + case 'product_name': + $strValue .= "".yandex_text2xml($arItem["NAME"], true)."\n"; + break; + case 'model': + case 'title': + if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) + { + if ( + $key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' + || + $key == 'title' && $XML_DATA['TYPE'] == 'artist.title' + ) + + $strValue = "<".$key.">".yandex_text2xml($arItem["NAME"], true)."\n"; + } + else + { + $strValue = yandex_get_value($arItem, $key, $XML_DATA['XML_DATA'][$key]); + if ('' != $strValue) + $strValue .= "\n"; + } + break; + case 'year': + $y++; + if ($XML_DATA['TYPE'] == 'artist.title') + { + if ($y == 1) continue; + } + else + { + if ($y > 1) continue; + } + + // no break here + + default: + if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) + { + $strValue = yandex_get_value($arItem, $key, $XML_DATA['XML_DATA'][$key]); + if ('' != $strValue) + $strValue .= "\n"; + } + } + if ('' != $strValue) + $strOfferYandex .= $strValue; + } + + $strOfferYandex .= "\n"; + + if ('' != $strOfferYandex) + { + $arItem['OFFERS'][] = $strOfferYandex; + $boolItemOffers = true; + $boolItemExport = true; + } + } + if (!$boolItemExport) + continue; + foreach ($arItem['OFFERS'] as $strOfferItem) + { + $strTmpOff .= $strOfferItem; + } + } + } + + @fwrite($fp, "\n"); + if (true == $boolNeedRootSection) + { + $strTmpCat .= "".yandex_text2xml(GetMessage('YANDEX_ROOT_DIRECTORY'), true)."\n"; + } + @fwrite($fp, $strTmpCat); + @fwrite($fp, "\n"); + + @fwrite($fp, "\n"); + @fwrite($fp, $strTmpOff); + @fwrite($fp, "\n"); + + @fwrite($fp, "\n"); + @fwrite($fp, "\n"); + + @fclose($fp); +} + +CCatalogDiscountSave::Enable(); + +if (!empty($arRunErrors)) + $strExportErrorMessage = implode('
',$arRunErrors); + +if ($bTmpUserCreated) +{ + unset($USER); + if (isset($USER_TMP)) + { + $USER = $USER_TMP; + unset($USER_TMP); + } +} \ No newline at end of file diff --git a/intaro.intarocrm/install/export/crm_setup.php b/intaro.intarocrm/install/export/crm_setup.php new file mode 100755 index 00000000..f3fc992c --- /dev/null +++ b/intaro.intarocrm/install/export/crm_setup.php @@ -0,0 +1,414 @@ +CRM +__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/export_setup_templ.php")); + +global $APPLICATION, $USER; + +ClearVars(); + +$strYandexError = ""; + +if (($ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && $STEP == 1) +{ + if (isset($arOldSetupVars['IBLOCK_ID'])) + $IBLOCK_ID = $arOldSetupVars['IBLOCK_ID']; + if (isset($arOldSetupVars['SETUP_FILE_NAME'])) + $SETUP_FILE_NAME = str_replace(COption::GetOptionString("catalog", "export_default_path", "/bitrix/catalog_export/"),'',$arOldSetupVars['SETUP_FILE_NAME']); + if (isset($arOldSetupVars['SETUP_PROFILE_NAME'])) + $SETUP_PROFILE_NAME = $arOldSetupVars['SETUP_PROFILE_NAME']; + if (isset($arOldSetupVars['V'])) + $V = $arOldSetupVars['V']; + if (isset($arOldSetupVars['XML_DATA'])) + { + if (get_magic_quotes_gpc()) + { + $XML_DATA = base64_encode(stripslashes($arOldSetupVars['XML_DATA'])); + } + else + { + $XML_DATA = base64_encode($arOldSetupVars['XML_DATA']); + } + } + if (isset($arOldSetupVars['SETUP_SERVER_NAME'])) + $SETUP_SERVER_NAME = $arOldSetupVars['SETUP_SERVER_NAME']; +} + +if ($STEP>1) +{ + $IBLOCK_ID = intval($IBLOCK_ID); + $rsIBlocks = CIBlock::GetByID($IBLOCK_ID); + if ($IBLOCK_ID<=0 || !($arIBlock = $rsIBlocks->Fetch())) + { + $strYandexError .= GetMessage("CET_ERROR_NO_IBLOCK1")." #".$IBLOCK_ID." ".GetMessage("CET_ERROR_NO_IBLOCK2")."
"; + } + else + { + $bRightBlock = !CIBlockRights::UserHasRightTo($IBLOCK_ID, $IBLOCK_ID, "iblock_admin_display"); + if ($bRightBlock) + { + $strYandexError .= str_replace('#IBLOCK_ID#',$IBLOCK_ID,GetMessage("CET_ERROR_IBLOCK_PERM"))."
"; + } + } + + if (strlen($SETUP_FILE_NAME)<=0) + { + $strYandexError .= GetMessage("CET_ERROR_NO_FILENAME")."
"; + } + elseif (preg_match(BX_CATALOG_FILENAME_REG,$SETUP_FILE_NAME)) + { + $strYandexError .= GetMessage("CES_ERROR_BAD_EXPORT_FILENAME")."
"; + } + elseif ($APPLICATION->GetFileAccessPermission($SETUP_FILE_NAME) < "W") + { + $strYandexError .= str_replace("#FILE#", $SETUP_FILE_NAME, GetMessage('CET_YAND_RUN_ERR_SETUP_FILE_ACCESS_DENIED'))."
"; + } + + $SETUP_SERVER_NAME = trim($SETUP_SERVER_NAME); + + if (strlen($strYandexError)<=0) + { + $bAllSections = false; + $arSections = array(); + if (is_array($V) && !empty($V)) + { + foreach ($V as $key => $value) + { + if (trim($value)=="0") + { + $bAllSections = true; + break; + } + $value = intval($value); + if ($value>0) + { + $arSections[] = $value; + } + } + } + + if (!$bAllSections && !empty($arSections)) + { + $arCheckSections = array(); + $rsSections = CIBlockSection::GetList(array(), array('IBLOCK_ID' => $IBLOCK_ID, 'ID' => $arSections), false, array('ID')); + while ($arOneSection = $rsSections->Fetch()) + { + $arCheckSections[] = $arOneSection['ID']; + } + $arSections = $arCheckSections; + } + + if (!$bAllSections && empty($arSections)) + { + $strYandexError .= GetMessage("CET_ERROR_NO_GROUPS")."
"; + $V = array(); + } + } + + if (is_array($V)) + { + $V = array_unique(array_values($V)); + $_REQUEST['V'] = $V; + } + + $arCatalog = CCatalog::GetByIDExt($IBLOCK_ID); + if ('P' == $arCatalog['CATALOG_TYPE'] || 'X' == $arCatalog['CATALOG_TYPE']) + { + if (strlen($XML_DATA) <= 0) + { + $strYandexError .= GetMessage('YANDEX_ERR_SKU_SETTINGS_ABSENT').'
'; + } + } + + if (($ACTION=="EXPORT_SETUP" || $ACTION=="EXPORT_EDIT" || $ACTION=="EXPORT_COPY") && strlen($SETUP_PROFILE_NAME)<=0) + $strYandexError .= GetMessage("CET_ERROR_NO_PROFILE_NAME")."
"; + + if (strlen($strYandexError)>0) + { + $STEP = 1; + } +} + +echo ShowError($strYandexError); + +if ($STEP==1) +{ + if (CModule::IncludeModule("iblock")) + { + ?> +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ 'Y','MIN_PERMISSION' => 'W'), + "ClearSelected(); document.getElementById('id_ifr').src='/bitrix/tools/catalog_export/yandex_util.php?IBLOCK_ID=0&'+'".bitrix_sessid_get()."';", + "ClearSelected(); document.getElementById('id_ifr').src='/bitrix/tools/catalog_export/yandex_util.php?IBLOCK_ID='+this[this.selectedIndex].value+'&'+'".bitrix_sessid_get()."';", + 'class="adm-detail-iblock-types"', + 'class="adm-detail-iblock-list"' + ); ?> +

+
+
+ + + + +
+ + + + +

+
+ + : + + +
+ + + +

+
+ + " size="50" /> + +

+
+ + + +

+
+ + "> + + + + "> +
+
+ 0) + { + $XML_DATA = base64_decode($XML_DATA); + } + $SETUP_SERVER_NAME = htmlspecialcharsbx($SETUP_SERVER_NAME); + $_POST['SETUP_SERVER_NAME'] = htmlspecialcharsbx($_POST['SETUP_SERVER_NAME']); + $_REQUEST['SETUP_SERVER_NAME'] = htmlspecialcharsbx($_REQUEST['SETUP_SERVER_NAME']); + + $FINITE = true; +} \ No newline at end of file diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 76b802ca..0d6f2639 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -141,6 +141,7 @@ class intaro_intarocrm extends CModule $arResult['paymentTypesList'] = $this->INTARO_CRM_API->paymentTypesList(); $arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); // --statuses $arResult['paymentList'] = $this->INTARO_CRM_API->orderStatusesList(); + $arResult['paymentGroupList'] = $this->INTARO_CRM_API->orderStatusGroupsList(); // -- statuses groups //bitrix orderTypesList -- personTypes $dbOrderTypesList = CSalePersonType::GetList( @@ -359,25 +360,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); - /*RegisterModule($this->MODULE_ID); - - //agent - $dateAgent = new DateTime(); - $intAgent = new DateInterval('PT600S'); // PT60S - 60 sec; 600 - 600 sec - $dateAgent->add($intAgent); - - CAgent::AddAgent( - "ICrmOrderActions::uploadOrdersAgent();", - $this->MODULE_ID, - "N", - 600, // interval - 10 mins - $dateAgent->format('d.m.Y H:i:s'), // date of first check - "Y", // агент активен - $dateAgent->format('d.m.Y H:i:s'), // date of first start - 30 - ); - - $this->CopyFiles(); */ $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), diff --git a/intaro.intarocrm/install/step2.php b/intaro.intarocrm/install/step2.php index 9fc1efd6..3bd0d338 100755 --- a/intaro.intarocrm/install/step2.php +++ b/intaro.intarocrm/install/step2.php @@ -106,12 +106,16 @@ $defaultPayment = array( diff --git a/intaro.intarocrm/install/step3.php b/intaro.intarocrm/install/step3.php index d4b7ac47..b58fb1fc 100755 --- a/intaro.intarocrm/install/step3.php +++ b/intaro.intarocrm/install/step3.php @@ -73,6 +73,10 @@ IncludeModuleLangFile(__FILE__); $(document).ready(function() { var globStop = false; + $(window).resize(function(){ // strechin progress bar + $('#percent').width($('.instal-progress-bar-outer').width()); + }); + // orderUpload function function orderUpload(finish) { if(globStop) diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index f1760bb4..8ca8a131 100755 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ '0.3.5', - 'VERSION_DATE' => '2013-07-24 18:27:00', + 'VERSION' => '0.3.6', + 'VERSION_DATE' => '2013-07-25 15:29:00', ); diff --git a/intaro.intarocrm/lang/ru/install/step2.php b/intaro.intarocrm/lang/ru/install/step2.php index 691c1f45..cad51a52 100755 --- a/intaro.intarocrm/lang/ru/install/step2.php +++ b/intaro.intarocrm/lang/ru/install/step2.php @@ -7,7 +7,7 @@ $MESS ['PAYMENT_TYPES_LIST'] = 'Способы оплаты'; $MESS ['PAYMENT_STATUS_LIST'] = 'Статусы'; $MESS ['ORDER_TYPES_LIST'] = 'Типы заказа'; $MESS ['PAYMENT_LIST'] = 'Оплата'; -$MESS ['PAYMENT_Y'] = 'Флаг «Отменен»'; +$MESS ['PAYMENT_Y'] = 'Оплачен'; $MESS ['PAYMENT_N'] = 'Не оплачен'; -$MESS ['CANCELED'] = 'Отменен'; +$MESS ['CANCELED'] = 'Флаг «Отменен»'; $MESS ['INFO_1'] = ' Задайте соответствие между справочниками 1C-Битрикс и справочниками IntaroCRM.'; \ No newline at end of file diff --git a/intaro.intarocrm/lang/ru/install/step3.php b/intaro.intarocrm/lang/ru/install/step3.php index 624acc2c..a4762583 100755 --- a/intaro.intarocrm/lang/ru/install/step3.php +++ b/intaro.intarocrm/lang/ru/install/step3.php @@ -8,4 +8,4 @@ $MESS ['STOP'] = 'Приостановить выгрузку'; $MESS ['START_1'] = 'Начать выгрузку'; $MESS ['START_2'] = 'Приостановить выгрузку'; $MESS ['START_3'] = 'Вообновить выгрузку'; -$MESS ['MOD_NEXT_STEP'] = 'Следующий шаг'; \ No newline at end of file +$MESS ['MOD_NEXT_STEP'] = 'Завершить установку'; \ No newline at end of file diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 148e6782..473cf341 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -21,4 +21,4 @@ $MESS ['ERR_404'] = 'Возможно не верно введен адрес CR $MESS ['ERR_403'] = 'Неверный apiKey.'; $MESS ['ERR_0'] = 'Превышено время ожидания ответа от сервера.'; $MESS ['ICRM_OPTIONS_OK'] = 'Изменения успешно сохранены.'; -$MESS ['CANCELED'] = 'Отменен'; \ No newline at end of file +$MESS ['CANCELED'] = 'Флаг «Отменен»'; \ No newline at end of file diff --git a/intaro.intarocrm/options.php b/intaro.intarocrm/options.php index 82d8c66e..9c8043f8 100755 --- a/intaro.intarocrm/options.php +++ b/intaro.intarocrm/options.php @@ -152,6 +152,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $arResult['paymentTypesList'] = $api->paymentTypesList(); $arResult['paymentStatusesList'] = $api->paymentStatusesList(); // --statuses $arResult['paymentList'] = $api->orderStatusesList(); + $arResult['paymentGroupList'] = $api->orderStatusGroupsList(); // -- statuses groups //check connection & apiKey valid if ((int) $api->getStatusCode() != 200) @@ -336,11 +337,15 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { From 7bf2c2b8dc3fd9685d03b4391754e278a4993310 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 25 Jul 2013 15:33:13 +0400 Subject: [PATCH 02/11] deleted inc files --- intaro.intarocrm/install/export/crm_run.php | 1829 ----------------- intaro.intarocrm/install/export/crm_setup.php | 414 ---- 2 files changed, 2243 deletions(-) delete mode 100755 intaro.intarocrm/install/export/crm_run.php delete mode 100755 intaro.intarocrm/install/export/crm_setup.php diff --git a/intaro.intarocrm/install/export/crm_run.php b/intaro.intarocrm/install/export/crm_run.php deleted file mode 100755 index ce91fb42..00000000 --- a/intaro.intarocrm/install/export/crm_run.php +++ /dev/null @@ -1,1829 +0,0 @@ -CRM -__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/export_crm.php")); -set_time_limit(0); - -global $USER, $APPLICATION; -$bTmpUserCreated = false; -if (!isset($USER) || !(($USER instanceof CUser) && ('CUser' == get_class($USER)))) -{ - $bTmpUserCreated = true; - if (isset($USER)) - { - $USER_TMP = $USER; - unset($USER); - } - - $USER = new CUser(); -} - -CCatalogDiscountSave::Disable(); - -$arYandexFields = array('vendor', 'vendorCode', 'model', 'author', 'name','product_name','xml_id', - 'publisher', 'series', 'year', 'ISBN', 'volume', 'part', - 'language', 'binding', 'page_extent', 'table_of_contents', - 'performed_by', 'performance_type', 'storage', 'format', - 'recording_length', 'artist', 'title', 'year', 'media', - 'starring', 'director', 'originalName', 'country', 'aliases', - 'description', 'sales_notes', 'promo', 'provider', 'tarifplan', - 'xCategory', 'additional', 'worldRegion', 'region', 'days', 'dataTour', - 'hotel_stars', 'room', 'meal', 'included', 'transport', 'price_min', - 'price_max', 'options', 'manufacturer_warranty', 'country_of_origin', - 'downloadable', 'param', 'place', 'hall', 'hall_part', 'is_premiere', - 'is_kids', 'date'); - -if (!function_exists("yandex_replace_special")) -{ - function yandex_replace_special($arg) - { - if (in_array($arg[0], array(""", "&", "<", ">"))) - return $arg[0]; - else - return " "; - } -} - -if (!function_exists("yandex_text2xml")) -{ - function yandex_text2xml($text, $bHSC = false, $bDblQuote = false) - { - global $APPLICATION; - - $bHSC = (true == $bHSC ? true : false); - $bDblQuote = (true == $bDblQuote ? true: false); - - if ($bHSC) - { - $text = htmlspecialcharsbx($text); - if ($bDblQuote) - $text = str_replace('"', '"', $text); - } - $text = preg_replace("/[\x1-\x8\xB-\xC\xE-\x1F]/", "", $text); - $text = str_replace("'", "'", $text); - $text = $APPLICATION->ConvertCharset($text, LANG_CHARSET, 'windows-1251'); - return $text; - } -} - -if (!function_exists('yandex_get_value')) -{ - function yandex_get_value($arOffer, $param, $PROPERTY) - { - global $IBLOCK_ID; - static $arProperties = null, $arUserTypes = null; - - if (!is_array($arProperties)) - { - $dbRes = CIBlockProperty::GetList( - array('ID' => 'ASC'), - array('IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N') - ); - - while ($arRes = $dbRes->Fetch()) - { - $arProperties[$arRes['ID']] = $arRes; - } - - if (!empty($arOffer['IBLOCK_ID']) && $arOffer['IBLOCK_ID'] != $IBLOCK_ID) - { - $dbRes = CIBlockProperty::GetList( - array('ID' => 'ASC'), - array('IBLOCK_ID' => $arOffer['IBLOCK_ID'], 'CHECK_PERMISSIONS' => 'N') - ); - - while ($arRes = $dbRes->Fetch()) - { - $arProperties[$arRes['ID']] = $arRes; - } - } - } - - $strProperty = ''; - $bParam = substr($param, 0, 6) == 'PARAM_'; - if (is_array($arProperties[$PROPERTY])) - { - $PROPERTY_CODE = $arProperties[$PROPERTY]['CODE']; - - $arProperty = $arOffer['PROPERTIES'][$PROPERTY_CODE] ? $arOffer['PROPERTIES'][$PROPERTY_CODE] : $arOffer['PROPERTIES'][$PROPERTY]; - - $value = ''; - $description = ''; - switch ($arProperties[$PROPERTY]['PROPERTY_TYPE']) - { - case 'E': - if (!empty($arProperty['VALUE'])) - { - $arCheckValue = array(); - if (!is_array($arProperty['VALUE'])) - { - $arProperty['VALUE'] = intval($arProperty['VALUE']); - if (0 < $arProperty['VALUE']) - $arCheckValue[] = $arProperty['VALUE']; - } - else - { - foreach ($arProperty['VALUE'] as &$intValue) - { - $intValue = intval($intValue); - if (0 < $intValue) - $arCheckValue[] = $intValue; - } - if (isset($intValue)) - unset($intValue); - } - if (!empty($arCheckValue)) - { - $dbRes = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $arProperties[$PROPERTY]['LINK_IBLOCK_ID'], 'ID' => $arCheckValue), false, false, array('NAME')); - while ($arRes = $dbRes->Fetch()) - { - $value .= ($value ? ', ' : '').$arRes['NAME']; - } - } - } - break; - case 'G': - if (!empty($arProperty['VALUE'])) - { - $arCheckValue = array(); - if (!is_array($arProperty['VALUE'])) - { - $arProperty['VALUE'] = intval($arProperty['VALUE']); - if (0 < $arProperty['VALUE']) - $arCheckValue[] = $arProperty['VALUE']; - } - else - { - foreach ($arProperty['VALUE'] as &$intValue) - { - $intValue = intval($intValue); - if (0 < $intValue) - $arCheckValue[] = $intValue; - } - if (isset($intValue)) - unset($intValue); - } - if (!empty($arCheckValue)) - { - $dbRes = CIBlockSection::GetList(array(), array('IBLOCK_ID' => $arProperty['LINK_IBLOCK_ID'], 'ID' => $arCheckValue), false, array('NAME')); - while ($arRes = $dbRes->Fetch()) - { - $value .= ($value ? ', ' : '').$arRes['NAME']; - } - } - } - break; - case 'L': - if ($arProperty['VALUE']) - { - if (is_array($arProperty['VALUE'])) - $value .= implode(', ', $arProperty['VALUE']); - else - $value .= $arProperty['VALUE']; - } - break; - default: - if ($bParam && $arProperty['WITH_DESCRIPTION'] == 'Y') - { - $description = $arProperty['DESCRIPTION']; - $value = $arProperty['VALUE']; - } - else - { - $value = is_array($arProperty['VALUE']) ? implode(', ', $arProperty['VALUE']) : $arProperty['VALUE']; - } - } - - // !!!! check multiple properties and properties like CML2_ATTRIBUTES - - if ($bParam) - { - if (is_array($description)) - { - foreach ($value as $key => $val) - { - $strProperty .= $strProperty ? "\n" : ""; - $strProperty .= ''.yandex_text2xml($val, true).''; - } - } - else - { - $strProperty .= ''.yandex_text2xml($value, true).''; - } - } - else - { - $param_h = yandex_text2xml($param, true); - $strProperty .= '<'.$param_h.'>'.yandex_text2xml($value, true).''; - } - } - - return $strProperty; - //if (is_callable(array($arParams["arUserField"]["USER_TYPE"]['CLASS_NAME'], 'getlist'))) - } -} - -$arRunErrors = array(); - -if ($XML_DATA && CheckSerializedData($XML_DATA)) -{ - $XML_DATA = unserialize(stripslashes($XML_DATA)); - if (!is_array($XML_DATA)) $XML_DATA = array(); -} - -$IBLOCK_ID = intval($IBLOCK_ID); -$db_iblock = CIBlock::GetByID($IBLOCK_ID); -if (!($ar_iblock = $db_iblock->Fetch())) -{ - $arRunErrors[] = str_replace('#ID#', $IBLOCK_ID, GetMessage('YANDEX_ERR_NO_IBLOCK_FOUND_EXT')); -} -/*elseif (!CIBlockRights::UserHasRightTo($IBLOCK_ID, $IBLOCK_ID, 'iblock_admin_display')) -{ - $arRunErrors[] = str_replace('#IBLOCK_ID#',$IBLOCK_ID,GetMessage('CET_ERROR_IBLOCK_PERM')); -} */ -else -{ - $SETUP_SERVER_NAME = trim($SETUP_SERVER_NAME); - - if (strlen($SETUP_SERVER_NAME) <= 0) - { - if (strlen($ar_iblock['SERVER_NAME']) <= 0) - { - $rsSite = CSite::GetList(($b="sort"), ($o="asc"), array("LID" => $ar_iblock["LID"])); - if($arSite = $rsSite->Fetch()) - $ar_iblock["SERVER_NAME"] = $arSite["SERVER_NAME"]; - if(strlen($ar_iblock["SERVER_NAME"])<=0 && defined("SITE_SERVER_NAME")) - $ar_iblock["SERVER_NAME"] = SITE_SERVER_NAME; - if(strlen($ar_iblock["SERVER_NAME"])<=0) - $ar_iblock["SERVER_NAME"] = COption::GetOptionString("main", "server_name", ""); - } - } - else - { - $ar_iblock['SERVER_NAME'] = $SETUP_SERVER_NAME; - } - $ar_iblock['PROPERTY'] = array(); - $rsProps = CIBlockProperty::GetList(array(),array('IBLOCK_ID' => $IBLOCK_ID, 'ACTIVE' => 'Y')); - while ($arProp = $rsProps->Fetch()) - { - $ar_iblock['PROPERTY'][$arProp['ID']] = $arProp; - } -} - -$boolOffers = false; -$arOffers = false; -$arOfferIBlock = false; -$intOfferIBlockID = 0; -$arSelectOfferProps = array(); -$arSelectedPropTypes = array('S','N','L','E','G'); -$arOffersSelectKeys = array( - YANDEX_SKU_EXPORT_ALL, - YANDEX_SKU_EXPORT_MIN_PRICE, - YANDEX_SKU_EXPORT_PROP, -); -$arCondSelectProp = array( - 'ZERO', - 'NONZERO', - 'EQUAL', - 'NONEQUAL', -); -$arPropertyMap = array(); -$arSKUExport = array(); - -$arCatalog = CCatalog::GetByIDExt($IBLOCK_ID); -if (empty($arCatalog)) -{ - $arRunErrors[] = str_replace('#ID#', $IBLOCK_ID, GetMessage('YANDEX_ERR_NO_IBLOCK_IS_CATALOG')); -} -else -{ - $arOffers = CCatalogSKU::GetInfoByProductIBlock($IBLOCK_ID); - if (!empty($arOffers['IBLOCK_ID'])) - { - $intOfferIBlockID = $arOffers['IBLOCK_ID']; - $rsOfferIBlocks = CIBlock::GetByID($intOfferIBlockID); - if (($arOfferIBlock = $rsOfferIBlocks->Fetch())) - { - $boolOffers = true; - $rsProps = CIBlockProperty::GetList(array('SORT' => 'ASC'),array('IBLOCK_ID' => $intOfferIBlockID,'ACTIVE' => 'Y')); - while ($arProp = $rsProps->Fetch()) - { - if ($arOffers['SKU_PROPERTY_ID'] != $arProp['ID']) - { - $ar_iblock['OFFERS_PROPERTY'][$arProp['ID']] = $arProp; - if (in_array($arProp['PROPERTY_TYPE'],$arSelectedPropTypes)) - $arSelectOfferProps[] = $arProp['ID']; - if (strlen($arProp['CODE']) > 0) - { - foreach ($ar_iblock['PROPERTY'] as &$arMainProp) - { - if ($arMainProp['CODE'] == $arProp['CODE']) - { - $arPropertyMap[$arProp['ID']] = $arMainProp['CODE']; - break; - } - } - if (isset($arMainProp)) - unset($arMainProp); - } - } - } - $arOfferIBlock['LID'] = $ar_iblock['LID']; - } - else - { - $arRunErrors[] = GetMessage('YANDEX_ERR_BAD_OFFERS_IBLOCK_ID'); - } - } - if (true == $boolOffers) - { - if (empty($XML_DATA['SKU_EXPORT'])) - { - $arRunErrors[] = GetMessage('YANDEX_ERR_SKU_SETTINGS_ABSENT'); - } - else - { - $arSKUExport = $XML_DATA['SKU_EXPORT'];; - if (empty($arSKUExport['SKU_EXPORT_COND']) || !in_array($arSKUExport['SKU_EXPORT_COND'],$arOffersSelectKeys)) - { - $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_CONDITION_ABSENT'); - } - if (YANDEX_SKU_EXPORT_PROP == $arSKUExport['SKU_EXPORT_COND']) - { - if (empty($arSKUExport['SKU_PROP_COND']) || !is_array($arSKUExport['SKU_PROP_COND'])) - { - $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_PROPERTY_ABSENT'); - } - else - { - if (empty($arSKUExport['SKU_PROP_COND']['PROP_ID']) || !in_array($arSKUExport['SKU_PROP_COND']['PROP_ID'],$arSelectOfferProps)) - { - $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_PROPERTY_ABSENT'); - } - if (empty($arSKUExport['SKU_PROP_COND']['COND']) || !in_array($arSKUExport['SKU_PROP_COND']['COND'],$arCondSelectProp)) - { - $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_PROPERTY_COND_ABSENT'); - } - else - { - if ($arSKUExport['SKU_PROP_COND']['COND'] == 'EQUAL' || $arSKUExport['SKU_PROP_COND']['COND'] == 'NONEQUAL') - { - if (empty($arSKUExport['SKU_PROP_COND']['VALUES'])) - { - $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_PROPERTY_VALUES_ABSENT'); - } - } - } - } - } - } - } -} - -if (empty($arRunErrors)) -{ - $bAllSections = False; - $arSections = array(); - if (is_array($V)) - { - foreach ($V as $key => $value) - { - if (trim($value)=="0") - { - $bAllSections = True; - break; - } - - if (intval($value)>0) - { - $arSections[] = intval($value); - } - } - } - - if (!$bAllSections && count($arSections)<=0) - { - $arRunErrors[] = GetMessage('YANDEX_ERR_NO_SECTION_LIST'); - } -} - -if (!empty($XML_DATA['PRICE'])) -{ - if (intval($XML_DATA['PRICE']) > 0) - { - $rsCatalogGroups = CCatalogGroup::GetGroupsList(array('CATALOG_GROUP_ID' => $XML_DATA['PRICE'],'GROUP_ID' => 2)); - if (!($arCatalogGroup = $rsCatalogGroups->Fetch())) - { - $arRunErrors[] = GetMessage('YANDEX_ERR_BAD_PRICE_TYPE'); - } - } - else - { - $arRunErrors[] = GetMessage('YANDEX_ERR_BAD_PRICE_TYPE'); - } -} - -if (strlen($SETUP_FILE_NAME) <= 0) -{ - $arRunErrors[] = GetMessage("CATI_NO_SAVE_FILE"); -} -elseif (preg_match(BX_CATALOG_FILENAME_REG,$SETUP_FILE_NAME)) -{ - $arRunErrors[] = GetMessage("CES_ERROR_BAD_EXPORT_FILENAME"); -} -else -{ - $SETUP_FILE_NAME = Rel2Abs("/", $SETUP_FILE_NAME); -} -if (empty($arRunErrors)) -{ -/* if ($GLOBALS["APPLICATION"]->GetFileAccessPermission($SETUP_FILE_NAME) < "W") - { - $arRunErrors[] = str_replace('#FILE#', $SETUP_FILE_NAME,GetMessage('YANDEX_ERR_FILE_ACCESS_DENIED')); - } */ -} - -if (empty($arRunErrors)) -{ - CheckDirPath($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME); - - if (!$fp = @fopen($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME, "wb")) - { - $arRunErrors[] = str_replace('#FILE#', $_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME, GetMessage('YANDEX_ERR_FILE_OPEN_WRITING')); - } - else - { - - if (!@fwrite($fp, '')) - { - $arRunErrors[] = str_replace('#FILE#', $_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME, GetMessage('YANDEX_ERR_SETUP_FILE_WRITE')); - @fclose($fp); - } - else - { - fwrite($fp, ''); - fwrite($fp, ''); - fwrite($fp, ''); - } - } -} - -if (empty($arRunErrors)) -{ - @fwrite($fp, ''); - @fwrite($fp, '"?>'); - @fwrite($fp, "\n\n"); - @fwrite($fp, "\n"); - @fwrite($fp, "\n"); - - @fwrite($fp, "".$APPLICATION->ConvertCharset(htmlspecialcharsbx(COption::GetOptionString("main", "site_name", "")), LANG_CHARSET, 'windows-1251')."\n"); - - @fwrite($fp, "".$APPLICATION->ConvertCharset(htmlspecialcharsbx(COption::GetOptionString("main", "site_name", "")), LANG_CHARSET, 'windows-1251')."\n"); - @fwrite($fp, "http://".htmlspecialcharsbx($ar_iblock['SERVER_NAME'])."\n"); - - $strTmp = "\n"; - - if ($arCurrency = CCurrency::GetByID('RUR')) - $RUR = 'RUR'; - else - $RUR = 'RUB'; - - $arCurrencyAllowed = array($RUR, 'USD', 'EUR', 'UAH', 'BYR', 'KZT'); - - $BASE_CURRENCY = CCurrency::GetBaseCurrency(); - if (is_array($XML_DATA['CURRENCY'])) - { - foreach ($XML_DATA['CURRENCY'] as $CURRENCY => $arCurData) - { - if (in_array($CURRENCY, $arCurrencyAllowed)) - { - $strTmp.= " 0 ? ' plus="'.intval($arCurData['plus']).'"' : '') - ." />\n"; - } - } - } - else - { - $db_acc = CCurrency::GetList(($by="sort"), ($order="asc")); - while ($arAcc = $db_acc->Fetch()) - { - if (in_array($arAcc['CURRENCY'], $arCurrencyAllowed)) - $strTmp.= "\n"; - } - } - $strTmp.= "\n"; - - @fwrite($fp, $strTmp); - - //*****************************************// - - - //*****************************************// - $intMaxSectionID = 0; - - $strTmpCat = ""; - $strTmpOff = ""; - - $arAvailGroups = array(); - if (!$bAllSections) - { - for ($i = 0, $intSectionsCount = count($arSections); $i < $intSectionsCount; $i++) - { - $filter_tmp = $filter; - $db_res = CIBlockSection::GetNavChain($IBLOCK_ID, $arSections[$i]); - $curLEFT_MARGIN = 0; - $curRIGHT_MARGIN = 0; - while ($ar_res = $db_res->Fetch()) - { - $curLEFT_MARGIN = intval($ar_res["LEFT_MARGIN"]); - $curRIGHT_MARGIN = intval($ar_res["RIGHT_MARGIN"]); - $arAvailGroups[$ar_res["ID"]] = array( - "ID" => intval($ar_res["ID"]), - "IBLOCK_SECTION_ID" => intval($ar_res["IBLOCK_SECTION_ID"]), - "NAME" => $ar_res["NAME"] - ); - if ($intMaxSectionID < $ar_res["ID"]) - $intMaxSectionID = $ar_res["ID"]; - } - - $filter = Array("IBLOCK_ID"=>$IBLOCK_ID, ">LEFT_MARGIN"=>$curLEFT_MARGIN, "$curRIGHT_MARGIN, "ACTIVE"=>"Y", "IBLOCK_ACTIVE"=>"Y", "GLOBAL_ACTIVE"=>"Y"); - $db_res = CIBlockSection::GetList(array("left_margin"=>"asc"), $filter); - while ($ar_res = $db_res->Fetch()) - { - $arAvailGroups[$ar_res["ID"]] = array( - "ID" => intval($ar_res["ID"]), - "IBLOCK_SECTION_ID" => intval($ar_res["IBLOCK_SECTION_ID"]), - "NAME" => $ar_res["NAME"] - ); - if ($intMaxSectionID < $ar_res["ID"]) - $intMaxSectionID = $ar_res["ID"]; - } - } - } - else - { - $filter = Array("IBLOCK_ID"=>$IBLOCK_ID, "ACTIVE"=>"Y", "IBLOCK_ACTIVE"=>"Y", "GLOBAL_ACTIVE"=>"Y"); - $db_res = CIBlockSection::GetList(array("left_margin"=>"asc"), $filter); - while ($ar_res = $db_res->Fetch()) - { - $arAvailGroups[$ar_res["ID"]] = array( - "ID" => intval($ar_res["ID"]), - "IBLOCK_SECTION_ID" => intval($ar_res["IBLOCK_SECTION_ID"]), - "NAME" => $ar_res["NAME"] - ); - if ($intMaxSectionID < $ar_res["ID"]) - $intMaxSectionID = $ar_res["ID"]; - } - } - - $arSectionIDs = array(); - foreach ($arAvailGroups as &$value) - { - $strTmpCat.= "0?" parentId=\"".$value["IBLOCK_SECTION_ID"]."\"":"").">".yandex_text2xml($value["NAME"], true)."\n"; - } - if (isset($value)) - unset($value); - - if (!empty($arAvailGroups)) - $arSectionIDs = array_keys($arAvailGroups); - - $intMaxSectionID += 100000000; - - //*****************************************// - $boolNeedRootSection = false; - - if ('D' == $arCatalog['CATALOG_TYPE'] || 'O' == $arCatalog['CATALOG_TYPE']) - { - $arSelect = array("ID", "LID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "ACTIVE", "ACTIVE_FROM", "ACTIVE_TO", "NAME", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE", "DETAIL_PICTURE", "LANG_DIR", "DETAIL_PAGE_URL"); - - $filter = Array("IBLOCK_ID"=>$IBLOCK_ID, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y"); - if (!$bAllSections) - { - $filter["INCLUDE_SUBSECTIONS"] = "Y"; - $filter["SECTION_ID"] = $arSectionIDs; - } - $res = CIBlockElement::GetList(array(), $filter, false, false, $arSelect); - - $total_sum = 0; - $is_exists = false; - $cnt = 0; - - while ($obElement = $res->GetNextElement()) - { - $arAcc = $obElement->GetFields(); - if (is_array($XML_DATA['XML_DATA'])) - { - $arAcc["PROPERTIES"] = $obElement->GetProperties(); - } - $arAcc['CATALOG_QUANTITY'] = ''; - $arAcc['CATALOG_QUANTITY_TRACE'] = 'N'; - $arProduct = CCatalogProduct::GetByID($arAcc['ID']); - if (!empty($arProduct)) - { - $arAcc['CATALOG_QUANTITY'] = $arProduct['QUANTITY']; - $arAcc['CATALOG_QUANTITY_TRACE'] = $arProduct['QUANTITY_TRACE']; - } - $str_QUANTITY = DoubleVal($arAcc["CATALOG_QUANTITY"]); - $str_QUANTITY_TRACE = $arAcc["CATALOG_QUANTITY_TRACE"]; - if (($str_QUANTITY <= 0) && ($str_QUANTITY_TRACE == "Y")) - $str_AVAILABLE = ' available="false"'; - else - $str_AVAILABLE = ' available="true"'; - - $minPrice = 0; - $minPriceRUR = 0; - $minPriceGroup = 0; - $minPriceCurrency = ""; - - if ($XML_DATA['PRICE'] > 0) - { - $rsPrices = CPrice::GetListEx(array(),array( - 'PRODUCT_ID' => $arAcc['ID'], - 'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], - 'CAN_BUY' => 'Y', - 'GROUP_GROUP_ID' => array(2), - '+<=QUANTITY_FROM' => 1, - '+>=QUANTITY_TO' => 1, - ) - ); - if ($arPrice = $rsPrices->Fetch()) - { -/* $dbVAT = CCatalogProduct::GetVATInfo($arAcc['ID']); - if ($arVat = $dbVAT->Fetch()) - { - $arVat['RATE'] = floatval($arVat['RATE'] * 0.01); - } - else - { - $arVat = array('RATE' => 0, 'VAT_INCLUDED' => 'N'); - } - $arPrice['VAT_RATE'] = $arVat['RATE']; - $arPrice['VAT_INCLUDED'] = $arVat['VAT_INCLUDED']; - if ($arPrice['VAT_INCLUDED'] == 'N') - { - $arPrice['PRICE'] *= (1 + $arPrice['VAT_RATE']); - $arPrice['VAT_INCLUDED'] = 'Y'; - } - $arPrice['PRICE'] = roundEx($arPrice['PRICE'], CATALOG_VALUE_PRECISION); - $arDiscounts = CCatalogDiscount::GetDiscount( - $arAcc['ID'], - $IBLOCK_ID, - array($XML_DATA['PRICE']), - array(2), - 'N', - $ar_iblock['LID'], - false - ); - $minPrice = CCatalogProduct::CountPriceWithDiscount($arPrice['PRICE'], $arPrice["CURRENCY"], $arDiscounts); - $minPriceGroup = $arPrice['CATALOG_GROUP_ID']; - $minPriceCurrency = $arPrice["CURRENCY"]; - $minPriceRUR = CCurrencyRates::ConvertCurrency($arPrice['PRICE'], $arPrice["CURRENCY"], $RUR); - */ - if ($arOptimalPrice = CCatalogProduct::GetOptimalPrice( - $arAcc['ID'], - 1, - array(2), // anonymous - 'N', - array($arPrice), - $ar_iblock['LID'] - )) - { - $minPrice = $arOptimalPrice['DISCOUNT_PRICE']; - $minPriceCurrency = $BASE_CURRENCY; - $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); - $minPriceGroup = $arOptimalPrice['PRICE']['CATALOG_GROUP_ID']; - } - } - } - else - { - if ($arPrice = CCatalogProduct::GetOptimalPrice( - $arAcc['ID'], - 1, - array(2), // anonymous - 'N', - array(), - $ar_iblock['LID'] - )) - { - $minPrice = $arPrice['DISCOUNT_PRICE']; - $minPriceCurrency = $BASE_CURRENCY; - $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); - $minPriceGroup = $arPrice['PRICE']['CATALOG_GROUP_ID']; - } - } - - if ($minPrice <= 0) continue; - - $boolCurrentSections = false; - $bNoActiveGroup = True; - $strTmpOff_tmp = ""; - $db_res1 = CIBlockElement::GetElementGroups($arAcc["ID"], true); - while ($ar_res1 = $db_res1->Fetch()) - { - $boolCurrentSections = true; - if (in_array(intval($ar_res1["ID"]), $arSectionIDs)) - { - $strTmpOff_tmp.= "".$ar_res1["ID"]."\n"; - $bNoActiveGroup = False; - - } - } - if (false == $boolCurrentSections) - { - $boolNeedRootSection = true; - $strTmpOff_tmp.= "".$intMaxSectionID."\n"; - } - else - { - if ($bNoActiveGroup) - continue; - } - - if (strlen($arAcc['DETAIL_PAGE_URL']) <= 0) - $arAcc['DETAIL_PAGE_URL'] = '/'; - 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']).'"'; - else - $str_TYPE = ''; - - if (!isset($arProduct["ID"])) - continue; - - $strTmpOff.= "\n"; - $strTmpOff.= "http://".$ar_iblock['SERVER_NAME'].htmlspecialcharsbx($arAcc["~DETAIL_PAGE_URL"]).(strstr($arAcc['DETAIL_PAGE_URL'], '?') === false ? '?' : '&')."r1=&r2=\n"; - - $strTmpOff.= "".$minPrice."\n"; - $strTmpOff.= "".$minPriceCurrency."\n"; - - $strTmpOff.= $strTmpOff_tmp; - - if (intval($arAcc["DETAIL_PICTURE"])>0 || intval($arAcc["PREVIEW_PICTURE"])>0) - { - $pictNo = intval($arAcc["DETAIL_PICTURE"]); - if ($pictNo<=0) $pictNo = intval($arAcc["PREVIEW_PICTURE"]); - - if ($ar_file = CFile::GetFileArray($pictNo)) - { - if(substr($ar_file["SRC"], 0, 1) == "/") - $strFile = "http://".$ar_iblock['SERVER_NAME'].implode("/", array_map("rawurlencode", explode("/", $ar_file["SRC"]))); - elseif(preg_match("/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $ar_file["SRC"], $match)) - $strFile = "http://".$match[2].'/'.implode("/", array_map("rawurlencode", explode("/", $match[3]))); - else - $strFile = $ar_file["SRC"]; - $strTmpOff.="".$strFile."\n"; - } - } - - $y = 0; - foreach ($arYandexFields as $key) - { - switch ($key) - { - case 'name': - if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) - continue; - - $strTmpOff .= "".yandex_text2xml($arAcc["NAME"], true)."\n"; - break; - case 'description': - $strTmpOff .= - "". - yandex_text2xml(TruncateText( - ($arAcc["PREVIEW_TEXT_TYPE"]=="html"? - strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arAcc["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arAcc["~PREVIEW_TEXT"])), - 255), true). - "\n"; - break; - case 'param': - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) - { - foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) - { - $strParamValue = ''; - if ($prop_id) - { - $strParamValue = yandex_get_value($arAcc, 'PARAM_'.$key, $prop_id); - } - if ('' != $strParamValue) - $strTmpOff .= $strParamValue."\n"; - } - } - break; - case 'xml_id': - $strTmpOff .= "".yandex_text2xml($arProduct["EXTERNAL_ID"], true)."\n"; - break; - case 'product_name': - $strTmpOff .= "".yandex_text2xml($arProduct["NAME"], true)."\n"; - break; - case 'model': - case 'title': - if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) - { - if ( - $key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' - || - $key == 'title' && $XML_DATA['TYPE'] == 'artist.title' - ) - - $strTmpOff.= "<".$key.">".yandex_text2xml($arAcc["NAME"], true)."\n"; - } - else - { - $strValue = ''; - $strValue = yandex_get_value($arAcc, $key, $XML_DATA['XML_DATA'][$key]); - if ('' != $strValue) - $strTmpOff .= $strValue."\n"; - } - break; - case 'year': - $y++; - if ($XML_DATA['TYPE'] == 'artist.title') - { - if ($y == 1) continue; - } - else - { - if ($y > 1) continue; - } - - // no break here - - default: - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) - { - $strValue = ''; - $strValue = yandex_get_value($arAcc, $key, $XML_DATA['XML_DATA'][$key]); - if ('' != $strValue) - $strTmpOff .= $strValue."\n"; - } - } - } - - $strTmpOff.= "\n"; - } - } - elseif ('P' == $arCatalog['CATALOG_TYPE'] || 'X' == $arCatalog['CATALOG_TYPE']) - { - $arOfferSelect = array("ID", "LID", "IBLOCK_ID", "ACTIVE", "NAME", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE", "DETAIL_PICTURE", "DETAIL_PAGE_URL"); - $arOfferFilter = array('IBLOCK_ID' => $intOfferIBlockID, 'PROPERTY_'.$arOffers['SKU_PROPERTY_ID'] => 0, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y"); - if (YANDEX_SKU_EXPORT_PROP == $arSKUExport['SKU_EXPORT_COND']) - { - $strExportKey = ''; - $mxValues = false; - if ($arSKUExport['SKU_PROP_COND']['COND'] == 'NONZERO' || $arSKUExport['SKU_PROP_COND']['COND'] == 'NONEQUAL') - $strExportKey = '!'; - $strExportKey .= 'PROPERTY_'.$arSKUExport['SKU_PROP_COND']['PROP_ID']; - if ($arSKUExport['SKU_PROP_COND']['COND'] == 'EQUAL' || $arSKUExport['SKU_PROP_COND']['COND'] == 'NONEQUAL') - $mxValues = $arSKUExport['SKU_PROP_COND']['VALUES']; - $arOfferFilter[$strExportKey] = $mxValues; - } - - $arSelect = array("ID", "LID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "ACTIVE", "ACTIVE_FROM", "ACTIVE_TO", "NAME", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE", "DETAIL_PICTURE", "DETAIL_PAGE_URL"); - $arFilter = Array("IBLOCK_ID"=>$IBLOCK_ID, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y"); - if (!$bAllSections) - { - $arFilter["INCLUDE_SUBSECTIONS"] = "Y"; - $arFilter["SECTION_ID"] = $arSectionIDs; - } - - $strOfferTemplateURL = ''; - if (!empty($arSKUExport['SKU_URL_TEMPLATE_TYPE'])) - { - switch($arSKUExport['SKU_URL_TEMPLATE_TYPE']) - { - case YANDEX_SKU_TEMPLATE_PRODUCT: - $strOfferTemplateURL = '#PRODUCT_URL#'; - break; - case YANDEX_SKU_TEMPLATE_CUSTOM: - if (!empty($arSKUExport['SKU_URL_TEMPLATE'])) - $strOfferTemplateURL = $arSKUExport['SKU_URL_TEMPLATE']; - break; - case YANDEX_SKU_TEMPLATE_OFFERS: - default: - $strOfferTemplateURL = ''; - break; - } - } - - $rsItems = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelect); - - while ($obItem = $rsItems->GetNextElement()) - { - $arItem = $obItem->GetFields(); - - $arItem['PROPERTIES'] = $obItem->GetProperties(); - if (!empty($arItem['PROPERTIES'])) - { - $arCross = array(); - foreach ($arItem['PROPERTIES'] as &$arProp) - { - $arCross[$arProp['ID']] = $arProp; - } - if (isset($arProp)) - unset($arProp); - $arItem['PROPERTIES'] = $arCross; - } - $boolItemExport = false; - $boolItemOffers = false; - $arItem['OFFERS'] = array(); - - $boolCurrentSections = false; - $boolNoActiveSections = true; - $strSections = ''; - $rsSections = CIBlockElement::GetElementGroups($arItem["ID"]); - while ($arSection = $rsSections->Fetch()) - { - $boolCurrentSections = true; - if (in_array(intval($arSection["ID"]), $arSectionIDs)) - { - $strSections .= "".$arSection["ID"]."\n"; - $boolNoActiveSections = false; - } - } - if (false == $boolCurrentSections) - { - $boolNeedRootSection = true; - $strSections .= "".$intMaxSectionID."\n"; - } - else - { - if ($boolNoActiveSections) - continue; - } - - $arItem['YANDEX_CATEGORY'] = $strSections; - - $strFile = ''; - if (intval($arItem["DETAIL_PICTURE"])>0 || intval($arItem["PREVIEW_PICTURE"])>0) - { - $pictNo = intval($arItem["DETAIL_PICTURE"]); - if ($pictNo <= 0) - $pictNo = intval($arItem["PREVIEW_PICTURE"]); - - if ($ar_file = CFile::GetFileArray($pictNo)) - { - if(substr($ar_file["SRC"], 0, 1) == "/") - $strFile = "http://".$ar_iblock['SERVER_NAME'].implode("/", array_map("rawurlencode", explode("/", $ar_file["SRC"]))); - elseif(preg_match("/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $ar_file["SRC"], $match)) - $strFile = "http://".$match[2].'/'.implode("/", array_map("rawurlencode", explode("/", $match[3]))); - else - $strFile = $ar_file["SRC"]; - } - } - $arItem['YANDEX_PICT'] = $strFile; - - $arItem['YANDEX_DESCR'] = yandex_text2xml(TruncateText( - ($arItem["PREVIEW_TEXT_TYPE"]=="html"? - strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arItem["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arItem["~PREVIEW_TEXT"])), - 255), true); - - $arOfferFilter['PROPERTY_'.$arOffers['SKU_PROPERTY_ID']] = $arItem['ID']; - $rsOfferItems = CIBlockElement::GetList(array(),$arOfferFilter,false,false,$arOfferSelect); - - if (!empty($strOfferTemplateURL)) - $rsOfferItems->SetUrlTemplates($strOfferTemplateURL); - if (YANDEX_SKU_EXPORT_MIN_PRICE == $arSKUExport['SKU_EXPORT_COND']) - { - $arCurrentOffer = false; - $arCurrentPrice = false; - $dblAllMinPrice = 0; - $boolFirst = true; - - while ($obOfferItem = $rsOfferItems->GetNextElement()) - { - $arOfferItem = $obOfferItem->GetFields(); - $minPrice = -1; - if ($XML_DATA['PRICE'] > 0) - { - $rsPrices = CPrice::GetListEx(array(),array( - 'PRODUCT_ID' => $arOfferItem['ID'], - 'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], - 'CAN_BUY' => 'Y', - 'GROUP_GROUP_ID' => array(2), - '+<=QUANTITY_FROM' => 1, - '+>=QUANTITY_TO' => 1, - ) - ); - if ($arPrice = $rsPrices->Fetch()) - { -/* $dbVAT = CCatalogProduct::GetVATInfo($arOfferItem['ID']); - if ($arVat = $dbVAT->Fetch()) - { - $arVat['RATE'] = floatval($arVat['RATE'] * 0.01); - } - else - { - $arVat = array('RATE' => 0, 'VAT_INCLUDED' => 'N'); - } - $arPrice['VAT_RATE'] = $arVat['RATE']; - $arPrice['VAT_INCLUDED'] = $arVat['VAT_INCLUDED']; - if ($arPrice['VAT_INCLUDED'] == 'N') - { - $arPrice['PRICE'] *= (1 + $arPrice['VAT_RATE']); - $arPrice['VAT_INCLUDED'] = 'Y'; - } - $arPrice['PRICE'] = roundEx($arPrice['PRICE'], CATALOG_VALUE_PRECISION); - $arDiscounts = CCatalogDiscount::GetDiscount( - $arOfferItem['ID'], - $intOfferIBlockID, - array($XML_DATA['PRICE']), - array(2), - 'N', - $arOfferIBlock['LID'], - false - ); - $minPrice = CCatalogProduct::CountPriceWithDiscount($arPrice['PRICE'], $arPrice["CURRENCY"], $arDiscounts); - $minPriceGroup = $arPrice['CATALOG_GROUP_ID']; - $minPriceCurrency = $arPrice["CURRENCY"]; - $minPriceRUR = CCurrencyRates::ConvertCurrency($arPrice['PRICE'], $arPrice["CURRENCY"], $RUR); */ - if ($arOptimalPrice = CCatalogProduct::GetOptimalPrice( - $arOfferItem['ID'], - 1, - array(2), - 'N', - array($arPrice), - $arOfferIBlock['LID'] - )) - { - $minPrice = $arOptimalPrice['DISCOUNT_PRICE']; - $minPriceCurrency = $BASE_CURRENCY; - $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); - $minPriceGroup = $arOptimalPrice['PRICE']['CATALOG_GROUP_ID']; - } - } - } - else - { - if ($arPrice = CCatalogProduct::GetOptimalPrice( - $arOfferItem['ID'], - 1, - array(2), // anonymous - 'N', - array(), - $arOfferIBlock['LID'] - )) - { - $minPrice = $arPrice['DISCOUNT_PRICE']; - $minPriceCurrency = $BASE_CURRENCY; - $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); - $minPriceGroup = $arPrice['PRICE']['CATALOG_GROUP_ID']; - } - } - if ($minPrice <= 0) - continue; - if ($boolFirst) - { - $dblAllMinPrice = $minPriceRUR; - $arOfferItem['PROPERTIES'] = $obOfferItem->GetProperties(); - $arCross = array(); - foreach ($arOfferItem['PROPERTIES'] as $arProp) - { - $arCross[$arProp['ID']] = $arProp; - } - if (!empty($arItem['PROPERTIES'])) - { - $arOfferItem['PROPERTIES'] = $arCross + $arItem['PROPERTIES']; - } - else - { - $arOfferItem['PROPERTIES'] = $arCross; - } - - $arCurrentOffer = $arOfferItem; - $arCurrentPrice = array( - 'MIN_PRICE' => $minPrice, - 'MIN_PRICE_CURRENCY' => $minPriceCurrency, - 'MIN_PRICE_RUR' => $minPriceRUR, - 'MIN_PRICE_GROUP' => $minPriceGroup, - ); - $boolFirst = false; - } - else - { - if ($dblAllMinPrice > $minPriceRUR) - { - $dblAllMinPrice > $minPriceRUR; - $arOfferItem['PROPERTIES'] = $obOfferItem->GetProperties(); - $arCross = array(); - foreach ($arOfferItem['PROPERTIES'] as $arProp) - { - $arCross[$arProp['ID']] = $arProp; - } - if (!empty($arItem['PROPERTIES'])) - { - $arOfferItem['PROPERTIES'] = $arCross + $arItem['PROPERTIES']; - } - else - { - $arOfferItem['PROPERTIES'] = $arCross; - } - - $arCurrentOffer = $arOfferItem; - $arCurrentPrice = array( - 'MIN_PRICE' => $minPrice, - 'MIN_PRICE_CURRENCY' => $minPriceCurrency, - 'MIN_PRICE_RUR' => $minPriceRUR, - 'MIN_PRICE_GROUP' => $minPriceGroup, - ); - } - } - } - if (!empty($arCurrentOffer) && !empty($arCurrentPrice)) - { - $arOfferItem = $arCurrentOffer; - $minPrice = $arCurrentPrice['MIN_PRICE']; - $minPriceCurrency = $arCurrentPrice['MIN_PRICE_CURRENCY']; - $minPriceRUR = $arCurrentPrice['MIN_PRICE_RUR']; - $minPriceGroup = $arCurrentPrice['MIN_PRICE_GROUP']; - - $arOfferItem['CATALOG_QUANTITY'] = ''; - $arOfferItem['CATALOG_QUANTITY_TRACE'] = 'N'; - $arProduct = CCatalogProduct::GetByID($arOfferItem['ID']); - if (!empty($arProduct)) - { - $arOfferItem['CATALOG_QUANTITY'] = $arProduct['QUANTITY']; - $arOfferItem['CATALOG_QUANTITY_TRACE'] = $arProduct['QUANTITY_TRACE']; - } - $arOfferItem['YANDEX_AVAILABLE'] = 'true'; - $str_QUANTITY = DoubleVal($arOfferItem["CATALOG_QUANTITY"]); - $str_QUANTITY_TRACE = $arOfferItem["CATALOG_QUANTITY_TRACE"]; - if (($str_QUANTITY <= 0) && ($str_QUANTITY_TRACE == "Y")) - $arOfferItem['YANDEX_AVAILABLE'] = 'false'; - - if (strlen($arOfferItem['DETAIL_PAGE_URL']) <= 0) - $arOfferItem['DETAIL_PAGE_URL'] = '/'; - 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']).'"'; - else - $str_TYPE = ''; - - $arOfferItem['YANDEX_TYPE'] = $str_TYPE; - - if(!isset($arItem["ID"])) - continue; - - $strOfferYandex = ''; - $strOfferYandex .= "\n"; - $strOfferYandex .= "http://".$ar_iblock['SERVER_NAME'].htmlspecialcharsbx($arOfferItem["~DETAIL_PAGE_URL"]).(strstr($arOfferItem['DETAIL_PAGE_URL'], '?') === false ? '?' : '&')."r1=&r2=\n"; - - $strOfferYandex .= "".$minPrice."\n"; - $strOfferYandex .= "".$minPriceCurrency."\n"; - - $strOfferYandex .= $arItem['YANDEX_CATEGORY']; - - $strFile = ''; - if (intval($arOfferItem["DETAIL_PICTURE"])>0 || intval($arOfferItem["PREVIEW_PICTURE"])>0) - { - $pictNo = intval($arOfferItem["DETAIL_PICTURE"]); - if ($pictNo<=0) - $pictNo = intval($arOfferItem["PREVIEW_PICTURE"]); - - if ($ar_file = CFile::GetFileArray($pictNo)) - { - if(substr($ar_file["SRC"], 0, 1) == "/") - $strFile = "http://".$ar_iblock['SERVER_NAME'].implode("/", array_map("rawurlencode", explode("/", $ar_file["SRC"]))); - elseif(preg_match("/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $ar_file["SRC"], $match)) - $strFile = "http://".$match[2].'/'.implode("/", array_map("rawurlencode", explode("/", $match[3]))); - else - $strFile = $ar_file["SRC"]; - } - } - if (!empty($strFile) || !empty($arItem['YANDEX_PICT'])) - { - $strOfferYandex .= "".(!empty($strFile) ? $strFile : $arItem['YANDEX_PICT'])."\n"; - } - - $y = 0; - foreach ($arYandexFields as $key) - { - switch ($key) - { - case 'name': - if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) - continue; - - $strOfferYandex .= "".yandex_text2xml($arOfferItem["NAME"], true)."\n"; - break; - case 'description': - $strOfferYandex .= ""; - if (strlen($arOfferItem['~PREVIEW_TEXT']) <= 0) - { - $strOfferYandex .= $arItem['YANDEX_DESCR']; - } - else - { - $strOfferYandex .= yandex_text2xml(TruncateText( - ($arOfferItem["PREVIEW_TEXT_TYPE"]=="html"? - strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferItem["~PREVIEW_TEXT"])) : $arOfferItem["~PREVIEW_TEXT"]), - 255), - true); - } - $strOfferYandex .= "\n"; - break; - case 'param': - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) - { - foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) - { - $strParamValue = ''; - if ($prop_id) - { - $strParamValue = yandex_get_value($arOfferItem, 'PARAM_'.$key, $prop_id); - } - if ('' != $strParamValue) - $strOfferYandex .= $strParamValue."\n"; - } - } - break; - case 'xml_id': - $strOfferYandex .= "".yandex_text2xml($arItem["EXTERNAL_ID"], true)."\n"; - break; - case 'product_name': - $strOfferYandex .= "".yandex_text2xml($arItem["NAME"], true)."\n"; - break; - case 'model': - case 'title': - if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) - { - if ( - $key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' - || - $key == 'title' && $XML_DATA['TYPE'] == 'artist.title' - ) - $strOfferYandex .= "<".$key.">".yandex_text2xml($arOfferItem["NAME"], true)."\n"; - } - else - { - $strValue = ''; - $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key]); - if ('' != $strValue) - $strOfferYandex .= $strValue."\n"; - } - break; - case 'year': - $y++; - if ($XML_DATA['TYPE'] == 'artist.title') - { - if ($y == 1) continue; - } - else - { - if ($y > 1) continue; - } - // no break here - default: - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) - { - $strValue = ''; - $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key]); - if ('' != $strValue) - $strOfferYandex .= $strValue."\n"; - } - } - } - - $strOfferYandex .= "\n"; - $arItem['OFFERS'][] = $strOfferYandex; - $boolItemOffers = true; - $boolItemExport = true; - } - } - else - { - while ($obOfferItem = $rsOfferItems->GetNextElement()) - { - $arOfferItem = $obOfferItem->GetFields(); - $arOfferItem['PROPERTIES'] = $obOfferItem->GetProperties(); - $arCross = array(); - foreach ($arOfferItem['PROPERTIES'] as $arProp) - { - $arCross[$arProp['ID']] = $arProp; - } - if (!empty($arItem['PROPERTIES'])) - { - $arOfferItem['PROPERTIES'] = $arCross + $arItem['PROPERTIES']; - } - else - { - $arOfferItem['PROPERTIES'] = $arCross; - } - - $arOfferItem['CATALOG_QUANTITY'] = ''; - $arOfferItem['CATALOG_QUANTITY_TRACE'] = 'N'; - $arProduct = CCatalogProduct::GetByID($arOfferItem['ID']); - if (!empty($arProduct)) - { - $arOfferItem['CATALOG_QUANTITY'] = $arProduct['QUANTITY']; - $arOfferItem['CATALOG_QUANTITY_TRACE'] = $arProduct['QUANTITY_TRACE']; - } - $arOfferItem['YANDEX_AVAILABLE'] = 'true'; - $str_QUANTITY = DoubleVal($arOfferItem["CATALOG_QUANTITY"]); - $str_QUANTITY_TRACE = $arOfferItem["CATALOG_QUANTITY_TRACE"]; - if (($str_QUANTITY <= 0) && ($str_QUANTITY_TRACE == "Y")) - $arOfferItem['YANDEX_AVAILABLE'] = 'false'; - - $minPrice = -1; - if ($XML_DATA['PRICE'] > 0) - { - $rsPrices = CPrice::GetListEx(array(),array( - 'PRODUCT_ID' => $arOfferItem['ID'], - 'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], - 'CAN_BUY' => 'Y', - 'GROUP_GROUP_ID' => array(2), - '+<=QUANTITY_FROM' => 1, - '+>=QUANTITY_TO' => 1, - ) - ); - if ($arPrice = $rsPrices->Fetch()) - { -/* $dbVAT = CCatalogProduct::GetVATInfo($arOfferItem['ID']); - if ($arVat = $dbVAT->Fetch()) - { - $arVat['RATE'] = floatval($arVat['RATE'] * 0.01); - } - else - { - $arVat = array('RATE' => 0, 'VAT_INCLUDED' => 'N'); - } - $arPrice['VAT_RATE'] = $arVat['RATE']; - $arPrice['VAT_INCLUDED'] = $arVat['VAT_INCLUDED']; - if ($arPrice['VAT_INCLUDED'] == 'N') - { - $arPrice['PRICE'] *= (1 + $arPrice['VAT_RATE']); - $arPrice['VAT_INCLUDED'] = 'Y'; - } - $arPrice['PRICE'] = roundEx($arPrice['PRICE'], CATALOG_VALUE_PRECISION); - $arDiscounts = CCatalogDiscount::GetDiscount( - $arOfferItem['ID'], - $intOfferIBlockID, - array($XML_DATA['PRICE']), - array(2), - 'N', - $arOfferIBlock['LID'], - false - ); - $minPrice = CCatalogProduct::CountPriceWithDiscount($arPrice['PRICE'], $arPrice["CURRENCY"], $arDiscounts); - $minPriceGroup = $arPrice['CATALOG_GROUP_ID']; - $minPriceCurrency = $arPrice["CURRENCY"]; - $minPriceRUR = CCurrencyRates::ConvertCurrency($arPrice['PRICE'], $arPrice["CURRENCY"], $RUR); */ - if ($arOptimalPrice = CCatalogProduct::GetOptimalPrice( - $arOfferItem['ID'], - 1, - array(2), - 'N', - array($arPrice), - $arOfferIBlock['LID'] - )) - { - $minPrice = $arOptimalPrice['DISCOUNT_PRICE']; - $minPriceCurrency = $BASE_CURRENCY; - $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); - $minPriceGroup = $arOptimalPrice['PRICE']['CATALOG_GROUP_ID']; - } - - } - } - else - { - if ($arPrice = CCatalogProduct::GetOptimalPrice( - $arOfferItem['ID'], - 1, - array(2), // anonymous - 'N', - array(), - $arOfferIBlock['LID'] - )) - { - $minPrice = $arPrice['DISCOUNT_PRICE']; - $minPriceCurrency = $BASE_CURRENCY; - $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); - $minPriceGroup = $arPrice['PRICE']['CATALOG_GROUP_ID']; - } - } - if ($minPrice <= 0) - continue; - - if (strlen($arOfferItem['DETAIL_PAGE_URL']) <= 0) - $arOfferItem['DETAIL_PAGE_URL'] = '/'; - 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']).'"'; - else - $str_TYPE = ''; - - $arOfferItem['YANDEX_TYPE'] = $str_TYPE; - - if(!isset($arItem["ID"])) - continue; - - $strOfferYandex = ''; - $strOfferYandex .= "\n"; - $strOfferYandex .= "http://".$ar_iblock['SERVER_NAME'].htmlspecialcharsbx($arOfferItem["~DETAIL_PAGE_URL"]).(strstr($arOfferItem['DETAIL_PAGE_URL'], '?') === false ? '?' : '&')."r1=&r2=\n"; - - $strOfferYandex .= "".$minPrice."\n"; - $strOfferYandex .= "".$minPriceCurrency."\n"; - - $strOfferYandex .= $arItem['YANDEX_CATEGORY']; - - $strFile = ''; - if (intval($arOfferItem["DETAIL_PICTURE"])>0 || intval($arOfferItem["PREVIEW_PICTURE"])>0) - { - $pictNo = intval($arOfferItem["DETAIL_PICTURE"]); - if ($pictNo<=0) - $pictNo = intval($arOfferItem["PREVIEW_PICTURE"]); - - if ($ar_file = CFile::GetFileArray($pictNo)) - { - if(substr($ar_file["SRC"], 0, 1) == "/") - $strFile = "http://".$ar_iblock['SERVER_NAME'].implode("/", array_map("rawurlencode", explode("/", $ar_file["SRC"]))); - elseif(preg_match("/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $ar_file["SRC"], $match)) - $strFile = "http://".$match[2].'/'.implode("/", array_map("rawurlencode", explode("/", $match[3]))); - else - $strFile = $ar_file["SRC"]; - } - } - if (!empty($strFile) || !empty($arItem['YANDEX_PICT'])) - { - $strOfferYandex .= "".(!empty($strFile) ? $strFile : $arItem['YANDEX_PICT'])."\n"; - } - - $y = 0; - foreach ($arYandexFields as $key) - { - switch ($key) - { - case 'name': - if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) - continue; - - $strOfferYandex .= "".yandex_text2xml($arOfferItem["NAME"], true)."\n"; - break; - case 'description': - $strOfferYandex .= ""; - if (strlen($arOfferItem['~PREVIEW_TEXT']) <= 0) - { - $strOfferYandex .= $arItem['YANDEX_DESCR']; - } - else - { - $strOfferYandex .= yandex_text2xml(TruncateText( - ($arOfferItem["PREVIEW_TEXT_TYPE"]=="html"? - strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferItem["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferItem["~PREVIEW_TEXT"])), - 255), - true); - } - $strOfferYandex .= "\n"; - break; - case 'param': - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) - { - foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) - { - $strParamValue = ''; - if ($prop_id) - { - $strParamValue = yandex_get_value($arOfferItem, 'PARAM_'.$key, $prop_id); - } - if ('' != $strParamValue) - $strOfferYandex .= $strParamValue."\n"; - } - } - break; - case 'xml_id': - $strOfferYandex .= "".yandex_text2xml($arItem["EXTERNAL_ID"], true)."\n"; - break; - case 'product_name': - $strOfferYandex .= "".yandex_text2xml($arItem["NAME"], true)."\n"; - break; - case 'model': - case 'title': - if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) - { - if ( - $key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' - || - $key == 'title' && $XML_DATA['TYPE'] == 'artist.title' - ) - $strOfferYandex .= "<".$key.">".yandex_text2xml($arOfferItem["NAME"], true)."\n"; - } - else - { - $strValue = ''; - $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key]); - if ('' != $strValue) - $strOfferYandex .= $strValue."\n"; - } - break; - case 'year': - $y++; - if ($XML_DATA['TYPE'] == 'artist.title') - { - if ($y == 1) continue; - } - else - { - if ($y > 1) continue; - } - // no break here - default: - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) - { - $strValue = ''; - $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key]); - if ('' != $strValue) - $strOfferYandex .= $strValue."\n"; - } - } - } - - $strOfferYandex .= "\n"; - $arItem['OFFERS'][] = $strOfferYandex; - $boolItemOffers = true; - $boolItemExport = true; - } - } - if ('X' == $arCatalog['CATALOG_TYPE'] && !$boolItemOffers) - { - $arItem['CATALOG_QUANTITY'] = ''; - $arItem['CATALOG_QUANTITY_TRACE'] = 'N'; - $arProduct = CCatalogProduct::GetByID($arItem['ID']); - if (!empty($arProduct)) - { - $arItem['CATALOG_QUANTITY'] = $arProduct['QUANTITY']; - $arItem['CATALOG_QUANTITY_TRACE'] = $arProduct['QUANTITY_TRACE']; - } - $str_QUANTITY = DoubleVal($arItem["CATALOG_QUANTITY"]); - $str_QUANTITY_TRACE = $arItem["CATALOG_QUANTITY_TRACE"]; - if (($str_QUANTITY <= 0) && ($str_QUANTITY_TRACE == "Y")) - $str_AVAILABLE = ' available="false"'; - else - $str_AVAILABLE = ' available="true"'; - - $minPrice = 0; - $minPriceRUR = 0; - $minPriceGroup = 0; - $minPriceCurrency = ""; - - if ($XML_DATA['PRICE'] > 0) - { - $rsPrices = CPrice::GetListEx(array(),array( - 'PRODUCT_ID' => $arItem['ID'], - 'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], - 'CAN_BUY' => 'Y', - 'GROUP_GROUP_ID' => array(2), - '+<=QUANTITY_FROM' => 1, - '+>=QUANTITY_TO' => 1, - ) - ); - if ($arPrice = $rsPrices->Fetch()) - { -/* $dbVAT = CCatalogProduct::GetVATInfo($arItem['ID']); - if ($arVat = $dbVAT->Fetch()) - { - $arVat['RATE'] = floatval($arVat['RATE'] * 0.01); - } - else - { - $arVat = array('RATE' => 0, 'VAT_INCLUDED' => 'N'); - } - $arPrice['VAT_RATE'] = $arVat['RATE']; - $arPrice['VAT_INCLUDED'] = $arVat['VAT_INCLUDED']; - if ($arPrice['VAT_INCLUDED'] == 'N') - { - $arPrice['PRICE'] *= (1 + $arPrice['VAT_RATE']); - $arPrice['VAT_INCLUDED'] = 'Y'; - } - $arPrice['PRICE'] = roundEx($arPrice['PRICE'], CATALOG_VALUE_PRECISION); - $arDiscounts = CCatalogDiscount::GetDiscount( - $arItem['ID'], - $IBLOCK_ID, - array($XML_DATA['PRICE']), - array(2), - 'N', - $ar_iblock['LID'], - false - ); - $minPrice = CCatalogProduct::CountPriceWithDiscount($arPrice['PRICE'], $arPrice["CURRENCY"], $arDiscounts); - $minPriceGroup = $arPrice['CATALOG_GROUP_ID']; - $minPriceCurrency = $arPrice["CURRENCY"]; - $minPriceRUR = CCurrencyRates::ConvertCurrency($arPrice['PRICE'], $arPrice["CURRENCY"], $RUR); */ - if ($arOptimalPrice = CCatalogProduct::GetOptimalPrice( - $arItem['ID'], - 1, - array(2), - 'N', - array($arPrice), - $ar_iblock['LID'] - )) - { - $minPrice = $arOptimalPrice['DISCOUNT_PRICE']; - $minPriceCurrency = $BASE_CURRENCY; - $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); - $minPriceGroup = $arOptimalPrice['PRICE']['CATALOG_GROUP_ID']; - } - } - } - else - { - if ($arPrice = CCatalogProduct::GetOptimalPrice( - $arItem['ID'], - 1, - array(2), // anonymous - 'N', - array(), - $ar_iblock['LID'] - )) - { - $minPrice = $arPrice['DISCOUNT_PRICE']; - $minPriceCurrency = $BASE_CURRENCY; - $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR); - $minPriceGroup = $arPrice['PRICE']['CATALOG_GROUP_ID']; - } - } - - if ($minPrice <= 0) continue; - - if ('' == $arItem['DETAIL_PAGE_URL']) - { - $arItem['DETAIL_PAGE_URL'] = '/'; - } - else - { - $arItem['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arItem['DETAIL_PAGE_URL']); - } - if ('' == $arItem['~DETAIL_PAGE_URL']) - { - $arItem['~DETAIL_PAGE_URL'] = '/'; - } - else - { - $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']).'"'; - else - $str_TYPE = ''; - if (!isset($arItem["ID"])) - continue; - - $strOfferYandex = ''; - $strOfferYandex.= "\n"; - $strOfferYandex.= "http://".$ar_iblock['SERVER_NAME'].htmlspecialcharsbx($arItem["~DETAIL_PAGE_URL"]).(strstr($arItem['DETAIL_PAGE_URL'], '?') === false ? '?' : '&')."r1=&r2=\n"; - - $strOfferYandex.= "".$minPrice."\n"; - $strOfferYandex.= "".$minPriceCurrency."\n"; - - $strOfferYandex.= $arItem['YANDEX_CATEGORY']; - - if (!empty($arItem['YANDEX_PICT'])) - { - $strOfferYandex .= "".$arItem['YANDEX_PICT']."\n"; - } - - $y = 0; - foreach ($arYandexFields as $key) - { - $strValue = ''; - switch ($key) - { - case 'name': - if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) - continue; - - $strValue = "".yandex_text2xml($arItem["NAME"], true)."\n"; - break; - case 'description': - $strValue = - "". - yandex_text2xml(TruncateText( - ($arItem["PREVIEW_TEXT_TYPE"]=="html"? - strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arItem["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arItem["~PREVIEW_TEXT"])), - 255), true). - "\n"; - break; - case 'param': - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) - { - foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) - { - $strParamValue = ''; - if ($prop_id) - { - $strParamValue = yandex_get_value($arItem, 'PARAM_'.$key, $prop_id); - } - if ('' != $strParamValue) - $strValue .= $strParamValue."\n"; - } - } - break; - case 'xml_id': - $strValue .= "".yandex_text2xml($arItem["EXTERNAL_ID"], true)."\n"; - break; - case 'product_name': - $strValue .= "".yandex_text2xml($arItem["NAME"], true)."\n"; - break; - case 'model': - case 'title': - if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) - { - if ( - $key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' - || - $key == 'title' && $XML_DATA['TYPE'] == 'artist.title' - ) - - $strValue = "<".$key.">".yandex_text2xml($arItem["NAME"], true)."\n"; - } - else - { - $strValue = yandex_get_value($arItem, $key, $XML_DATA['XML_DATA'][$key]); - if ('' != $strValue) - $strValue .= "\n"; - } - break; - case 'year': - $y++; - if ($XML_DATA['TYPE'] == 'artist.title') - { - if ($y == 1) continue; - } - else - { - if ($y > 1) continue; - } - - // no break here - - default: - if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) - { - $strValue = yandex_get_value($arItem, $key, $XML_DATA['XML_DATA'][$key]); - if ('' != $strValue) - $strValue .= "\n"; - } - } - if ('' != $strValue) - $strOfferYandex .= $strValue; - } - - $strOfferYandex .= "\n"; - - if ('' != $strOfferYandex) - { - $arItem['OFFERS'][] = $strOfferYandex; - $boolItemOffers = true; - $boolItemExport = true; - } - } - if (!$boolItemExport) - continue; - foreach ($arItem['OFFERS'] as $strOfferItem) - { - $strTmpOff .= $strOfferItem; - } - } - } - - @fwrite($fp, "\n"); - if (true == $boolNeedRootSection) - { - $strTmpCat .= "".yandex_text2xml(GetMessage('YANDEX_ROOT_DIRECTORY'), true)."\n"; - } - @fwrite($fp, $strTmpCat); - @fwrite($fp, "\n"); - - @fwrite($fp, "\n"); - @fwrite($fp, $strTmpOff); - @fwrite($fp, "\n"); - - @fwrite($fp, "\n"); - @fwrite($fp, "\n"); - - @fclose($fp); -} - -CCatalogDiscountSave::Enable(); - -if (!empty($arRunErrors)) - $strExportErrorMessage = implode('
',$arRunErrors); - -if ($bTmpUserCreated) -{ - unset($USER); - if (isset($USER_TMP)) - { - $USER = $USER_TMP; - unset($USER_TMP); - } -} \ No newline at end of file diff --git a/intaro.intarocrm/install/export/crm_setup.php b/intaro.intarocrm/install/export/crm_setup.php deleted file mode 100755 index f3fc992c..00000000 --- a/intaro.intarocrm/install/export/crm_setup.php +++ /dev/null @@ -1,414 +0,0 @@ -CRM -__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/export_setup_templ.php")); - -global $APPLICATION, $USER; - -ClearVars(); - -$strYandexError = ""; - -if (($ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && $STEP == 1) -{ - if (isset($arOldSetupVars['IBLOCK_ID'])) - $IBLOCK_ID = $arOldSetupVars['IBLOCK_ID']; - if (isset($arOldSetupVars['SETUP_FILE_NAME'])) - $SETUP_FILE_NAME = str_replace(COption::GetOptionString("catalog", "export_default_path", "/bitrix/catalog_export/"),'',$arOldSetupVars['SETUP_FILE_NAME']); - if (isset($arOldSetupVars['SETUP_PROFILE_NAME'])) - $SETUP_PROFILE_NAME = $arOldSetupVars['SETUP_PROFILE_NAME']; - if (isset($arOldSetupVars['V'])) - $V = $arOldSetupVars['V']; - if (isset($arOldSetupVars['XML_DATA'])) - { - if (get_magic_quotes_gpc()) - { - $XML_DATA = base64_encode(stripslashes($arOldSetupVars['XML_DATA'])); - } - else - { - $XML_DATA = base64_encode($arOldSetupVars['XML_DATA']); - } - } - if (isset($arOldSetupVars['SETUP_SERVER_NAME'])) - $SETUP_SERVER_NAME = $arOldSetupVars['SETUP_SERVER_NAME']; -} - -if ($STEP>1) -{ - $IBLOCK_ID = intval($IBLOCK_ID); - $rsIBlocks = CIBlock::GetByID($IBLOCK_ID); - if ($IBLOCK_ID<=0 || !($arIBlock = $rsIBlocks->Fetch())) - { - $strYandexError .= GetMessage("CET_ERROR_NO_IBLOCK1")." #".$IBLOCK_ID." ".GetMessage("CET_ERROR_NO_IBLOCK2")."
"; - } - else - { - $bRightBlock = !CIBlockRights::UserHasRightTo($IBLOCK_ID, $IBLOCK_ID, "iblock_admin_display"); - if ($bRightBlock) - { - $strYandexError .= str_replace('#IBLOCK_ID#',$IBLOCK_ID,GetMessage("CET_ERROR_IBLOCK_PERM"))."
"; - } - } - - if (strlen($SETUP_FILE_NAME)<=0) - { - $strYandexError .= GetMessage("CET_ERROR_NO_FILENAME")."
"; - } - elseif (preg_match(BX_CATALOG_FILENAME_REG,$SETUP_FILE_NAME)) - { - $strYandexError .= GetMessage("CES_ERROR_BAD_EXPORT_FILENAME")."
"; - } - elseif ($APPLICATION->GetFileAccessPermission($SETUP_FILE_NAME) < "W") - { - $strYandexError .= str_replace("#FILE#", $SETUP_FILE_NAME, GetMessage('CET_YAND_RUN_ERR_SETUP_FILE_ACCESS_DENIED'))."
"; - } - - $SETUP_SERVER_NAME = trim($SETUP_SERVER_NAME); - - if (strlen($strYandexError)<=0) - { - $bAllSections = false; - $arSections = array(); - if (is_array($V) && !empty($V)) - { - foreach ($V as $key => $value) - { - if (trim($value)=="0") - { - $bAllSections = true; - break; - } - $value = intval($value); - if ($value>0) - { - $arSections[] = $value; - } - } - } - - if (!$bAllSections && !empty($arSections)) - { - $arCheckSections = array(); - $rsSections = CIBlockSection::GetList(array(), array('IBLOCK_ID' => $IBLOCK_ID, 'ID' => $arSections), false, array('ID')); - while ($arOneSection = $rsSections->Fetch()) - { - $arCheckSections[] = $arOneSection['ID']; - } - $arSections = $arCheckSections; - } - - if (!$bAllSections && empty($arSections)) - { - $strYandexError .= GetMessage("CET_ERROR_NO_GROUPS")."
"; - $V = array(); - } - } - - if (is_array($V)) - { - $V = array_unique(array_values($V)); - $_REQUEST['V'] = $V; - } - - $arCatalog = CCatalog::GetByIDExt($IBLOCK_ID); - if ('P' == $arCatalog['CATALOG_TYPE'] || 'X' == $arCatalog['CATALOG_TYPE']) - { - if (strlen($XML_DATA) <= 0) - { - $strYandexError .= GetMessage('YANDEX_ERR_SKU_SETTINGS_ABSENT').'
'; - } - } - - if (($ACTION=="EXPORT_SETUP" || $ACTION=="EXPORT_EDIT" || $ACTION=="EXPORT_COPY") && strlen($SETUP_PROFILE_NAME)<=0) - $strYandexError .= GetMessage("CET_ERROR_NO_PROFILE_NAME")."
"; - - if (strlen($strYandexError)>0) - { - $STEP = 1; - } -} - -echo ShowError($strYandexError); - -if ($STEP==1) -{ - if (CModule::IncludeModule("iblock")) - { - ?> -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- 'Y','MIN_PERMISSION' => 'W'), - "ClearSelected(); document.getElementById('id_ifr').src='/bitrix/tools/catalog_export/yandex_util.php?IBLOCK_ID=0&'+'".bitrix_sessid_get()."';", - "ClearSelected(); document.getElementById('id_ifr').src='/bitrix/tools/catalog_export/yandex_util.php?IBLOCK_ID='+this[this.selectedIndex].value+'&'+'".bitrix_sessid_get()."';", - 'class="adm-detail-iblock-types"', - 'class="adm-detail-iblock-list"' - ); ?> -

-
-
- - - - -
- - - - -

-
- - : - - -
- - - -

-
- - " size="50" /> - -

-
- - - -

-
- - "> - - - - "> -
-
- 0) - { - $XML_DATA = base64_decode($XML_DATA); - } - $SETUP_SERVER_NAME = htmlspecialcharsbx($SETUP_SERVER_NAME); - $_POST['SETUP_SERVER_NAME'] = htmlspecialcharsbx($_POST['SETUP_SERVER_NAME']); - $_REQUEST['SETUP_SERVER_NAME'] = htmlspecialcharsbx($_REQUEST['SETUP_SERVER_NAME']); - - $FINITE = true; -} \ No newline at end of file From abb2cdf7ea95821a4c354e550850f04744ee73ce Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 25 Jul 2013 16:56:36 +0400 Subject: [PATCH 03/11] istallation fixes; diiscountPercent fix; --- intaro.intarocrm/classes/general/ICrmOrderActions.php | 7 +++++-- intaro.intarocrm/install/index.php | 4 ++-- intaro.intarocrm/install/version.php | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 6c201637..cf6f12a2 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -146,7 +146,7 @@ class ICrmOrderActions COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $lastOrderId); return true; //all ok! - } + } /** * @@ -269,7 +269,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, diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 0d6f2639..9c824cda 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -427,7 +427,7 @@ class intaro_intarocrm extends CModule } function DeleteFiles() { - unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/crm_run.php'); - unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/crm_setup.php'); + 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 8ca8a131..a7dcb4fb 100755 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ '0.3.6', - 'VERSION_DATE' => '2013-07-25 15:29:00', + 'VERSION_DATE' => '2013-07-25 16:55:00', ); From 88d22602f1f3a46ac896b32a8a9547bf33036fd7 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 25 Jul 2013 18:15:15 +0400 Subject: [PATCH 04/11] change path to export file --- intaro.intarocrm/install/export/intarocrm_setup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intaro.intarocrm/install/export/intarocrm_setup.php b/intaro.intarocrm/install/export/intarocrm_setup.php index 003e9293..10919622 100755 --- a/intaro.intarocrm/install/export/intarocrm_setup.php +++ b/intaro.intarocrm/install/export/intarocrm_setup.php @@ -124,7 +124,7 @@ if ($STEP==1) - " size="50"> + " size="50">

From 62f92b5dde152855638dd0de8d89e2ef19a61a7a Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Thu, 25 Jul 2013 18:15:24 +0400 Subject: [PATCH 05/11] general fixes; +handle server error on step3 installation; --- intaro.intarocrm/install/step3.php | 9 +++++++++ intaro.intarocrm/install/version.php | 2 +- intaro.intarocrm/lang/ru/install/step3.php | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/intaro.intarocrm/install/step3.php b/intaro.intarocrm/install/step3.php index b58fb1fc..956ff73c 100755 --- a/intaro.intarocrm/install/step3.php +++ b/intaro.intarocrm/install/step3.php @@ -73,6 +73,8 @@ IncludeModuleLangFile(__FILE__); $(document).ready(function() { var globStop = false; + $('#percent').width($('.instal-progress-bar-outer').width()); + $(window).resize(function(){ // strechin progress bar $('#percent').width($('.instal-progress-bar-outer').width()); }); @@ -111,6 +113,13 @@ IncludeModuleLangFile(__FILE__); orderUpload(response.finish); // wait until next response + }, + error: function () { + $('input[name="inst"]').css('opacity', '1').removeAttr('disabled'); + $('input[name="stop"]').attr('name', 'start'); + $('input[name="stop"]').attr('value', ''); + $('#status').text(''); + globStop = true; } }); } diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index a7dcb4fb..47b89181 100755 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ '0.3.6', - 'VERSION_DATE' => '2013-07-25 16:55:00', + 'VERSION_DATE' => '2013-07-25 18:14:00', ); diff --git a/intaro.intarocrm/lang/ru/install/step3.php b/intaro.intarocrm/lang/ru/install/step3.php index a4762583..7a867a9a 100755 --- a/intaro.intarocrm/lang/ru/install/step3.php +++ b/intaro.intarocrm/lang/ru/install/step3.php @@ -4,8 +4,9 @@ $MESS ['MESS_1'] = 'Нажмите кнопку для экспорта офор $MESS ['MESS_2'] = 'Экспорт...'; $MESS ['MESS_3'] = 'Экспорт заказов успешно завершён.'; $MESS ['MESS_4'] = 'Экспорт заказов приостановлен.'; +$MESS ['MESS_5'] = 'Произошла ошибка сервера, обратитесь в Интаро Софт.'; $MESS ['STOP'] = 'Приостановить выгрузку'; $MESS ['START_1'] = 'Начать выгрузку'; $MESS ['START_2'] = 'Приостановить выгрузку'; -$MESS ['START_3'] = 'Вообновить выгрузку'; +$MESS ['START_3'] = 'Возобновить выгрузку'; $MESS ['MOD_NEXT_STEP'] = 'Завершить установку'; \ No newline at end of file From e220e8eabce21d9f1dcb87b4b254161865ee883a Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Fri, 26 Jul 2013 17:19:02 +0800 Subject: [PATCH 06/11] Update README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c49f316a..6550f2bb 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,13 @@ Bitrix module ============= -Bitrix module for interaction with IntaroCRM through REST API. +Bitrix module for interaction with [IntaroCRM](http://www.intarocrm.com) through [REST API](http://docs.intarocrm.ru/rest-api/). Module allows: -* Send to IntaroCRM new orders and changes for old orders from Bitrix -* Load from IntaroCRM changes for old orders to Bitrix +* Send to IntaroCRM new orders * Configure relations between dictionaries of IntaroCRM and Bitrix (statuses, payments, delivery types and etc) -* Generate extended YML (YandexML) for catalog loading by IntaroCRM +* Generate [ICML](http://docs.intarocrm.ru/index.php?n=Пользователи.ФорматICML) (IntaroCRM Markup Language) for catalog loading by IntaroCRM Installation ------------- From c6d11680f388e1931c6911a1a0ecb0c349bc14d1 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Fri, 26 Jul 2013 15:56:00 +0400 Subject: [PATCH 07/11] change date format --- intaro.intarocrm/classes/general/ICrmOrderActions.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index cf6f12a2..4bd3f8de 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -217,6 +217,7 @@ class ICrmOrderActions 'firstName' => $firstName, 'patronymic' => $patronymic, 'phones' => $phones + 'createdAt' => $arUser['DATE_REGISTER'], )); $customer = $api->customerEdit($result); @@ -287,10 +288,6 @@ class ICrmOrderActions if($arFields['CANCELED'] == 'Y') $arFields['STATUS_ID'] = $arFields['CANCELED']; - $createdAt = \datetime::createfromformat('Y-m-d H:i:s', $arFields['DATE_INSERT']); - if($createdAt) - $createdAt = $createdAt->format('d-m-Y H:i:s'); - $resOrder = self::clearArr(array( 'contactName' => $resOrder['contactName'], 'phone' => $resOrder['phone'], @@ -306,7 +303,7 @@ class ICrmOrderActions 'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId], 'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']], 'statusComment' => $arFields['REASON_CANCELED'], - 'createdAt' => $createdAt, + 'createdAt' => $arFields['DATE_INSERT'], 'deliveryAddress' => $resOrderDeliveryAddress, 'items' => $items )); From 5b39c7349fc0e2ebed3168df89df316d9dd1da4f Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Fri, 26 Jul 2013 16:17:34 +0400 Subject: [PATCH 08/11] change date format --- intaro.intarocrm/classes/general/ICrmOrderActions.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 4bd3f8de..2f499d19 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -211,13 +211,16 @@ class ICrmOrderActions ); $phones[] = $phoneWork; + $createdAt = new \DateTime($arUser['DATE_REGISTER']); + $createdAt = $createdAt->format('Y-m-d H:i:s'); + $result = self::clearArr(array( 'externalId' => $arFields['USER_ID'], 'lastName' => $lastName, 'firstName' => $firstName, 'patronymic' => $patronymic, - 'phones' => $phones - 'createdAt' => $arUser['DATE_REGISTER'], + 'phones' => $phones, + 'createdAt' => $createdAt, )); $customer = $api->customerEdit($result); From a4eeec4031117ed95920d1ae41269f35c955a91f Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Fri, 26 Jul 2013 16:32:07 +0400 Subject: [PATCH 09/11] fix status association --- 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 3bd0d338..4be9c242 100755 --- a/intaro.intarocrm/install/step2.php +++ b/intaro.intarocrm/install/step2.php @@ -24,7 +24,7 @@ $defaultPayTypes = array ( ); $defaultPayStatuses = array ( - 'N' => 'in-processing', + 'N' => 'new', 'P' => 'approval', 'F' => 'complete', 'Y' => 'cancel-other' From d293f532de7acdd73c0d2c1fb15e0ac3e8113c28 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 29 Jul 2013 12:29:41 +0400 Subject: [PATCH 10/11] fio parse; small fixes; --- .../classes/general/ICrmOrderActions.php | 26 ++++--- intaro.intarocrm/classes/general/RestApi.php | 74 ++++++++++++++----- .../install/export/intarocrm_setup.php | 4 +- intaro.intarocrm/install/index.php | 13 +++- intaro.intarocrm/install/step3.php | 15 ++-- intaro.intarocrm/install/version.php | 2 +- intaro.intarocrm/lang/ru/install/step3.php | 2 +- 7 files changed, 94 insertions(+), 42 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 2f499d19..5d0a9294 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -120,9 +120,10 @@ class ICrmOrderActions if($api->getStatusCode() != 460) // some orders were sent return false; // in pack mode return errors - } - 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 } @@ -147,7 +148,7 @@ class ICrmOrderActions return true; //all ok! } - + /** * * w+ event in bitrix log @@ -193,6 +194,9 @@ 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'); // push customer (for crm) $firstName = self::toJSON($arUser['NAME']); @@ -211,16 +215,13 @@ class ICrmOrderActions ); $phones[] = $phoneWork; - $createdAt = new \DateTime($arUser['DATE_REGISTER']); - $createdAt = $createdAt->format('Y-m-d H:i:s'); - $result = self::clearArr(array( 'externalId' => $arFields['USER_ID'], 'lastName' => $lastName, 'firstName' => $firstName, 'patronymic' => $patronymic, 'phones' => $phones, - 'createdAt' => $createdAt, + 'createdAt' => $createdAt )); $customer = $api->customerEdit($result); @@ -255,7 +256,7 @@ class ICrmOrderActions break; case 'ADDRESS': $resOrderDeliveryAddress['text'] = self::toJSON($ar['VALUE']); break; - case 'FIO': $resOrder['contactName'] = self::toJSON($ar['VALUE']); + case 'FIO': $resOrder['contactName'] = explode(" ", self::toJSON($ar['VALUE'])); break; case 'PHONE': $resOrder['phone'] = $ar['VALUE']; break; @@ -291,8 +292,13 @@ class ICrmOrderActions 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( - 'contactName' => $resOrder['contactName'], + 'firstName' => $resOrder['contactName'][0], + 'lastName' => $resOrder['contactName'][1], + 'patronymic' => $resOrder['contactName'][2], 'phone' => $resOrder['phone'], 'email' => $resOrder['email'], 'deliveryCost' => $arFields['PRICE_DELIVERY'], @@ -306,7 +312,7 @@ class ICrmOrderActions 'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId], 'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']], 'statusComment' => $arFields['REASON_CANCELED'], - 'createdAt' => $arFields['DATE_INSERT'], + 'createdAt' => $createdAt, 'deliveryAddress' => $resOrderDeliveryAddress, 'items' => $items )); diff --git a/intaro.intarocrm/classes/general/RestApi.php b/intaro.intarocrm/classes/general/RestApi.php index 7e2711cb..c8f85181 100644 --- a/intaro.intarocrm/classes/general/RestApi.php +++ b/intaro.intarocrm/classes/general/RestApi.php @@ -6,7 +6,8 @@ class RestApi protected $apiUrl; protected $apiKey; protected $apiVersion = '1'; - protected $lastError; + + protected $response; protected $statusCode; protected $parameters; @@ -30,16 +31,23 @@ class RestApi /* Получение кода статуса и сообщения об ошибке */ public function getLastError() { - if (!is_null($this->lastError)) - return $this->statusCode . ' ' . $this->lastError; + if (isset($this->response['errorMsg']) && isset($this->response['errors'])) + { + $result = $this->statusCode . ' ' . $this->response['errorMsg']; + foreach ($this->response['errors'] as $error) + $result .= ' ' . $error; + } + elseif (isset($this->response['errorMsg'])) + $result = $this->statusCode . ' ' . $this->response['errorMsg']; else - return null; + $result = null; + return $result; } /* Псообщения об ошибке */ public function getLastErrorMessage() { - return $this->lastError; + return $this->response['errorMsg']; } @@ -94,7 +102,7 @@ class RestApi } /** - * Загрузка нескольких заказов + * Пакетная загрузка заказов * * @param array $orders - массив заказов * @return array @@ -106,6 +114,8 @@ class RestApi $url = $this->apiUrl.'orders/upload'; $result = $this->curlRequest($url, 'POST'); + if (is_null($result) && isset($result['uploadedOrders'])) + return $result['uploadedOrders']; return $result; } @@ -154,10 +164,8 @@ class RestApi public function orderHistory($startDate = null, $endDate = null, $limit = 100, $offset = 0) { $url = $this->apiUrl.'orders/history'; - if($startDate) - $this->parameters['startDate'] = $startDate; - if($endDate) - $this->parameters['endDate'] = $endDate; + $this->parameters['startDate'] = $startDate; + $this->parameters['endDate'] = $endDate; $this->parameters['limit'] = $limit; $this->parameters['offset'] = $offset; @@ -215,6 +223,26 @@ class RestApi return $result; } + /** + * Пакетная загрузка клиентов + * + * @param array $customers - массив клиентов + * @return array + */ + public function customerUpload($customers) + { + $dataJson = json_encode($customers); + $dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget, + $dataJson); + $this->parameters['customers'] = $dataJson; + + $url = $this->apiUrl.'customers/upload'; + $result = $this->curlRequest($url, 'POST'); + if (is_null($result) && isset($result['uploaded'])) + return $result['uploaded']; + return $result; + } + /** * Удаление клиента * @@ -414,9 +442,18 @@ class RestApi $result = $this->curlRequest($url); return $result; } - - - + + /** + * Обновление статистики + * + * @return array - статус вып обновления + */ + public function statisticUpdate() + { + $url = $this->apiUrl.'statistic/update'; + $result = $this->curlRequest($url); + return $result; + } protected function curlRequest($url, $method = 'GET', $format = 'json') { @@ -444,22 +481,21 @@ class RestApi if (curl_errno($ch)) { - $this->lastError = 'Curl error: ' . curl_error($ch); + $this->response = array('errorMsg' => 'Curl error: ' . curl_error($ch)); return null; } curl_close($ch); $result = (array)json_decode($response, true); + $this->response = $result; if ($result['success'] == false) - { - $this->lastError = $result['errorMsg']; return null; - } - $this->lastError = null; unset($result['success']); if (count($result) == 0) return true; return reset($result); } -} \ No newline at end of file +} + +?> \ No newline at end of file diff --git a/intaro.intarocrm/install/export/intarocrm_setup.php b/intaro.intarocrm/install/export/intarocrm_setup.php index 10919622..6679189a 100755 --- a/intaro.intarocrm/install/export/intarocrm_setup.php +++ b/intaro.intarocrm/install/export/intarocrm_setup.php @@ -150,8 +150,8 @@ if ($STEP==1) - "> - + "> + "> diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 9c824cda..dc5166e0 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -59,6 +59,7 @@ class intaro_intarocrm extends CModule global $APPLICATION, $step, $arResult; include($this->INSTALL_PATH . '/../classes/general/RestApi.php'); + include($this->INSTALL_PATH . '/../classes/general/ICrmOrderActions.php'); $step = intval($_REQUEST['step']); @@ -234,9 +235,7 @@ class intaro_intarocrm extends CModule } if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') - && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) { - include($this->INSTALL_PATH . '/../classes/general/ICrmOrderActions.php'); - + && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) { ICrmOrderActions::uploadOrders(true); // each 50 $lastUpOrderId = COption::GetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0); @@ -250,8 +249,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); diff --git a/intaro.intarocrm/install/step3.php b/intaro.intarocrm/install/step3.php index 956ff73c..5a5658fb 100755 --- a/intaro.intarocrm/install/step3.php +++ b/intaro.intarocrm/install/step3.php @@ -85,17 +85,19 @@ IncludeModuleLangFile(__FILE__); return false; if(finish == 1) { - $('#status').text(''); + $('#status').text(''); BX.closeWait(); $('input[name="inst"]').css('opacity', '1').removeAttr('disabled'); + $('input[name="stop"]').css('opacity', '0.5').attr('disabled', 'disabled'); + $('input[name="stop"]').attr('value', ''); return true; // exit from function, end recursion } var handlerUrl = $(this).parents('form').attr('action'); - var step = $('input[name="continue"]').val(); - var id = $('input[name="id"]').val(); - var install = $('input[name="install"]').val(); - var sessid = BX.bitrix_sessid(); + var step = $('input[name="continue"]').val(); + var id = $('input[name="id"]').val(); + var install = $('input[name="install"]').val(); + var sessid = BX.bitrix_sessid(); var data = 'install=' + install +'&step=' + step + '&sessid=' + sessid + '&id=' + id + '&ajax=1&finish=' + finish; @@ -115,11 +117,14 @@ IncludeModuleLangFile(__FILE__); }, error: function () { + BX.closeWait(); $('input[name="inst"]').css('opacity', '1').removeAttr('disabled'); $('input[name="stop"]').attr('name', 'start'); $('input[name="stop"]').attr('value', ''); $('#status').text(''); globStop = true; + + alert(''); } }); } diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index 47b89181..14200c58 100755 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ '0.3.6', - 'VERSION_DATE' => '2013-07-25 18:14:00', + 'VERSION_DATE' => '2013-07-29 12:29:00', ); diff --git a/intaro.intarocrm/lang/ru/install/step3.php b/intaro.intarocrm/lang/ru/install/step3.php index 7a867a9a..ff5fc8fe 100755 --- a/intaro.intarocrm/lang/ru/install/step3.php +++ b/intaro.intarocrm/lang/ru/install/step3.php @@ -1,6 +1,6 @@ Date: Mon, 29 Jul 2013 12:48:16 +0400 Subject: [PATCH 11/11] agent bug 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 5d0a9294..7fde6192 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -90,7 +90,7 @@ class ICrmOrderActions self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError()); if ($api->getStatusCode() != 460) // some orders were sent - return false; // in pack mode return errors + return true; } }