1
0
mirror of synced 2024-11-22 13:26:10 +03:00
This commit is contained in:
Grisha Pomadchin 2013-07-29 18:43:45 +04:00
commit 2440aee3a3

View File

@ -3,6 +3,7 @@
__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/export_crm.php")); __IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/export_crm.php"));
set_time_limit(0); set_time_limit(0);
CModule::IncludeModule("iblock"); CModule::IncludeModule("iblock");
$db_res = CIBlock::GetList(Array("IBLOCK_TYPE"=>"ASC", "NAME"=>"ASC"),array('CHECK_PERMISSIONS' => 'Y','MIN_PERMISSION' => 'W')); $db_res = CIBlock::GetList(Array("IBLOCK_TYPE"=>"ASC", "NAME"=>"ASC"),array('CHECK_PERMISSIONS' => 'Y','MIN_PERMISSION' => 'W'));
$IBLOCK_ID = Array(); $IBLOCK_ID = Array();
@ -244,16 +245,23 @@ if ($XML_DATA && CheckSerializedData($XML_DATA))
$XML_DATA = unserialize(stripslashes($XML_DATA)); $XML_DATA = unserialize(stripslashes($XML_DATA));
if (!is_array($XML_DATA)) $XML_DATA = array(); if (!is_array($XML_DATA)) $XML_DATA = array();
} }
$XML_DATA = Array(); $XML_DATA = Array();
$XML_DATA["TYPE"] = null; foreach ($arIBlockId as $id)
$XML_DATA["CURRENCY"] = Array ( {
$IBLOCK_ID = $id;
$IBLOCK_ID = intval($IBLOCK_ID);
$XML_DATA[$IBLOCK_ID]["TYPE"] = null;
$XML_DATA[$IBLOCK_ID]["CURRENCY"] = Array (
"RUB" => Array ( "RUB" => Array (
"rate" => SITE, "rate" => SITE,
"plus" => null "plus" => null
) )
); );
$XML_DATA["XML_DATA"] = Array(); $XML_DATA[$IBLOCK_ID]["XML_DATA"] = Array();
$XML_DATA["SKU_EXPORT"] = Array ( $XML_DATA[$IBLOCK_ID]["SKU_EXPORT"] = Array (
"SKU_URL_TEMPLATE_TYPE" => 1, "SKU_URL_TEMPLATE_TYPE" => 1,
"SKU_URL_TEMPLATE" => null, "SKU_URL_TEMPLATE" => null,
"SKU_EXPORT_COND" => 1, "SKU_EXPORT_COND" => 1,
@ -264,10 +272,17 @@ $XML_DATA["SKU_EXPORT"] = Array (
) )
); );
foreach ($arIBlockId as $id) $properties = CIBlockProperty::GetList(
{ Array(),
$IBLOCK_ID = $id; Array(
$IBLOCK_ID = intval($IBLOCK_ID); "ACTIVE"=>"Y",
"IBLOCK_ID"=>$IBLOCK_ID,
"CODE" => "ARTICLE"
)
)->Fetch();
$XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'][] = $properties['ID'];
$db_iblock = CIBlock::GetByID($IBLOCK_ID); $db_iblock = CIBlock::GetByID($IBLOCK_ID);
$ar_iblock[$IBLOCK_ID] = $db_iblock->Fetch(); $ar_iblock[$IBLOCK_ID] = $db_iblock->Fetch();
if (!($ar_iblock[$IBLOCK_ID])) if (!($ar_iblock[$IBLOCK_ID]))
@ -378,13 +393,13 @@ foreach ($arIBlockId as $id)
} }
if (true == $boolOffers) if (true == $boolOffers)
{ {
if (empty($XML_DATA['SKU_EXPORT'])) if (empty($XML_DATA[$IBLOCK_ID]['SKU_EXPORT']))
{ {
$arRunErrors[] = GetMessage('YANDEX_ERR_SKU_SETTINGS_ABSENT'); $arRunErrors[] = GetMessage('YANDEX_ERR_SKU_SETTINGS_ABSENT');
} }
else else
{ {
$arSKUExport = $XML_DATA['SKU_EXPORT'];; $arSKUExport = $XML_DATA[$IBLOCK_ID]['SKU_EXPORT'];;
if (empty($arSKUExport['SKU_EXPORT_COND']) || !in_array($arSKUExport['SKU_EXPORT_COND'],$arOffersSelectKeys)) if (empty($arSKUExport['SKU_EXPORT_COND']) || !in_array($arSKUExport['SKU_EXPORT_COND'],$arOffersSelectKeys))
{ {
$arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_CONDITION_ABSENT'); $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_CONDITION_ABSENT');
@ -450,11 +465,11 @@ if (empty($arRunErrors))
} }
} }
if (!empty($XML_DATA['PRICE'])) if (!empty($XML_DATA[$IBLOCK_ID]['PRICE']))
{ {
if (intval($XML_DATA['PRICE']) > 0) if (intval($XML_DATA[$IBLOCK_ID]['PRICE']) > 0)
{ {
$rsCatalogGroups = CCatalogGroup::GetGroupsList(array('CATALOG_GROUP_ID' => $XML_DATA['PRICE'],'GROUP_ID' => 2)); $rsCatalogGroups = CCatalogGroup::GetGroupsList(array('CATALOG_GROUP_ID' => $XML_DATA[$IBLOCK_ID]['PRICE'],'GROUP_ID' => 2));
if (!($arCatalogGroup = $rsCatalogGroups->Fetch())) if (!($arCatalogGroup = $rsCatalogGroups->Fetch()))
{ {
$arRunErrors[] = GetMessage('YANDEX_ERR_BAD_PRICE_TYPE'); $arRunErrors[] = GetMessage('YANDEX_ERR_BAD_PRICE_TYPE');
@ -536,9 +551,9 @@ if (empty($arRunErrors))
$arCurrencyAllowed = array($RUR, 'USD', 'EUR', 'UAH', 'BYR', 'KZT'); $arCurrencyAllowed = array($RUR, 'USD', 'EUR', 'UAH', 'BYR', 'KZT');
$BASE_CURRENCY = CCurrency::GetBaseCurrency(); $BASE_CURRENCY = CCurrency::GetBaseCurrency();
if (is_array($XML_DATA['CURRENCY'])) if (is_array($XML_DATA[$IBLOCK_ID]['CURRENCY']))
{ {
foreach ($XML_DATA['CURRENCY'] as $CURRENCY => $arCurData) foreach ($XML_DATA[$IBLOCK_ID]['CURRENCY'] as $CURRENCY => $arCurData)
{ {
if (in_array($CURRENCY, $arCurrencyAllowed)) if (in_array($CURRENCY, $arCurrencyAllowed))
{ {
@ -663,7 +678,7 @@ if (empty($arRunErrors))
while ($obElement = $res->GetNextElement()) while ($obElement = $res->GetNextElement())
{ {
$arAcc = $obElement->GetFields(); $arAcc = $obElement->GetFields();
if (is_array($XML_DATA['XML_DATA'])) if (is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']))
{ {
$arAcc["PROPERTIES"] = $obElement->GetProperties(); $arAcc["PROPERTIES"] = $obElement->GetProperties();
} }
@ -688,11 +703,11 @@ if (empty($arRunErrors))
$minPriceGroup = 0; $minPriceGroup = 0;
$minPriceCurrency = ""; $minPriceCurrency = "";
if ($XML_DATA['PRICE'] > 0) if ($XML_DATA[$IBLOCK_ID]['PRICE'] > 0)
{ {
$rsPrices = CPrice::GetListEx(array(),array( $rsPrices = CPrice::GetListEx(array(),array(
'PRODUCT_ID' => $arAcc['ID'], 'PRODUCT_ID' => $arAcc['ID'],
'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], 'CATALOG_GROUP_ID' => $XML_DATA[$IBLOCK_ID]['PRICE'],
'CAN_BUY' => 'Y', 'CAN_BUY' => 'Y',
'GROUP_GROUP_ID' => array(2), 'GROUP_GROUP_ID' => array(2),
'+<=QUANTITY_FROM' => 1, '+<=QUANTITY_FROM' => 1,
@ -721,7 +736,7 @@ if (empty($arRunErrors))
$arDiscounts = CCatalogDiscount::GetDiscount( $arDiscounts = CCatalogDiscount::GetDiscount(
$arAcc['ID'], $arAcc['ID'],
$IBLOCK_ID, $IBLOCK_ID,
array($XML_DATA['PRICE']), array($XML_DATA[$IBLOCK_ID]['PRICE']),
array(2), array(2),
'N', 'N',
$ar_iblock['LID'], $ar_iblock['LID'],
@ -798,8 +813,8 @@ if (empty($arRunErrors))
else else
$arAcc['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arAcc['DETAIL_PAGE_URL']); $arAcc['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arAcc['DETAIL_PAGE_URL']);
if (is_array($XML_DATA) && $XML_DATA['TYPE'] && $XML_DATA['TYPE'] != 'none') if (is_array($XML_DATA[$IBLOCK_ID]) && $XML_DATA[$IBLOCK_ID]['TYPE'] && $XML_DATA[$IBLOCK_ID]['TYPE'] != 'none')
$str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA['TYPE']).'"'; $str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA[$IBLOCK_ID]['TYPE']).'"';
else else
$str_TYPE = ''; $str_TYPE = '';
@ -837,7 +852,7 @@ if (empty($arRunErrors))
switch ($key) switch ($key)
{ {
case 'name': case 'name':
if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) if (is_array($XML_DATA[$IBLOCK_ID]) && ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model' || $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title'))
continue; continue;
$strTmpOff .= "<name>".yandex_text2xml($arAcc["NAME"], true)."</name>\n"; $strTmpOff .= "<name>".yandex_text2xml($arAcc["NAME"], true)."</name>\n";
@ -852,10 +867,11 @@ if (empty($arRunErrors))
"</description>\n"; "</description>\n";
break; break;
case 'param': case 'param':
if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS']))
{ {
foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) foreach ($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'] as $key => $prop_id)
{ {
$strParamValue = ''; $strParamValue = '';
if ($prop_id) if ($prop_id)
{ {
@ -876,12 +892,12 @@ if (empty($arRunErrors))
break; break;
case 'model': case 'model':
case 'title': case 'title':
if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) if (!is_array($XML_DATA[$IBLOCK_ID]) || !is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) || !$XML_DATA[$IBLOCK_ID]['XML_DATA'][$key])
{ {
if ( if (
$key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' $key == 'model' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model'
|| ||
$key == 'title' && $XML_DATA['TYPE'] == 'artist.title' $key == 'title' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title'
) )
$strTmpOff.= "<".$key.">".yandex_text2xml($arAcc["NAME"], true)."</".$key.">\n"; $strTmpOff.= "<".$key.">".yandex_text2xml($arAcc["NAME"], true)."</".$key.">\n";
@ -889,14 +905,14 @@ if (empty($arRunErrors))
else else
{ {
$strValue = ''; $strValue = '';
$strValue = yandex_get_value($arAcc, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); $strValue = yandex_get_value($arAcc, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID);
if ('' != $strValue) if ('' != $strValue)
$strTmpOff .= $strValue."\n"; $strTmpOff .= $strValue."\n";
} }
break; break;
case 'year': case 'year':
$y++; $y++;
if ($XML_DATA['TYPE'] == 'artist.title') if ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title')
{ {
if ($y == 1) continue; if ($y == 1) continue;
} }
@ -908,10 +924,10 @@ if (empty($arRunErrors))
// no break here // no break here
default: default:
if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key])
{ {
$strValue = ''; $strValue = '';
$strValue = yandex_get_value($arAcc, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); $strValue = yandex_get_value($arAcc, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID);
if ('' != $strValue) if ('' != $strValue)
$strTmpOff .= $strValue."\n"; $strTmpOff .= $strValue."\n";
} }
@ -1053,11 +1069,11 @@ if (empty($arRunErrors))
{ {
$arOfferItem = $obOfferItem->GetFields(); $arOfferItem = $obOfferItem->GetFields();
$minPrice = -1; $minPrice = -1;
if ($XML_DATA['PRICE'] > 0) if ($XML_DATA[$IBLOCK_ID]['PRICE'] > 0)
{ {
$rsPrices = CPrice::GetListEx(array(),array( $rsPrices = CPrice::GetListEx(array(),array(
'PRODUCT_ID' => $arOfferItem['ID'], 'PRODUCT_ID' => $arOfferItem['ID'],
'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], 'CATALOG_GROUP_ID' => $XML_DATA[$IBLOCK_ID]['PRICE'],
'CAN_BUY' => 'Y', 'CAN_BUY' => 'Y',
'GROUP_GROUP_ID' => array(2), 'GROUP_GROUP_ID' => array(2),
'+<=QUANTITY_FROM' => 1, '+<=QUANTITY_FROM' => 1,
@ -1086,7 +1102,7 @@ if (empty($arRunErrors))
$arDiscounts = CCatalogDiscount::GetDiscount( $arDiscounts = CCatalogDiscount::GetDiscount(
$arOfferItem['ID'], $arOfferItem['ID'],
$intOfferIBlockID, $intOfferIBlockID,
array($XML_DATA['PRICE']), array($XML_DATA[$IBLOCK_ID]['PRICE']),
array(2), array(2),
'N', 'N',
$arOfferIBlock['LID'], $arOfferIBlock['LID'],
@ -1215,8 +1231,8 @@ if (empty($arRunErrors))
else else
$arOfferItem['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arOfferItem['DETAIL_PAGE_URL']); $arOfferItem['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arOfferItem['DETAIL_PAGE_URL']);
if (is_array($XML_DATA) && $XML_DATA['TYPE'] && $XML_DATA['TYPE'] != 'none') if (is_array($XML_DATA[$IBLOCK_ID]) && $XML_DATA[$IBLOCK_ID]['TYPE'] && $XML_DATA[$IBLOCK_ID]['TYPE'] != 'none')
$str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA['TYPE']).'"'; $str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA[$IBLOCK_ID]['TYPE']).'"';
else else
$str_TYPE = ''; $str_TYPE = '';
@ -1262,7 +1278,7 @@ if (empty($arRunErrors))
switch ($key) switch ($key)
{ {
case 'name': case 'name':
if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) if (is_array($XML_DATA[$IBLOCK_ID]) && ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model' || $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title'))
continue; continue;
$strOfferYandex .= "<name>".yandex_text2xml($arOfferItem["NAME"], true)."</name>\n"; $strOfferYandex .= "<name>".yandex_text2xml($arOfferItem["NAME"], true)."</name>\n";
@ -1284,10 +1300,11 @@ if (empty($arRunErrors))
$strOfferYandex .= "</description>\n"; $strOfferYandex .= "</description>\n";
break; break;
case 'param': case 'param':
if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS']))
{ {
foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) foreach ($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'] as $key => $prop_id)
{ {
$strParamValue = ''; $strParamValue = '';
if ($prop_id) if ($prop_id)
{ {
@ -1306,26 +1323,26 @@ if (empty($arRunErrors))
break; break;
case 'model': case 'model':
case 'title': case 'title':
if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) if (!is_array($XML_DATA[$IBLOCK_ID]) || !is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) || !$XML_DATA[$IBLOCK_ID]['XML_DATA'][$key])
{ {
if ( if (
$key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' $key == 'model' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model'
|| ||
$key == 'title' && $XML_DATA['TYPE'] == 'artist.title' $key == 'title' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title'
) )
$strOfferYandex .= "<".$key.">".yandex_text2xml($arOfferItem["NAME"], true)."</".$key.">\n"; $strOfferYandex .= "<".$key.">".yandex_text2xml($arOfferItem["NAME"], true)."</".$key.">\n";
} }
else else
{ {
$strValue = ''; $strValue = '';
$strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID);
if ('' != $strValue) if ('' != $strValue)
$strOfferYandex .= $strValue."\n"; $strOfferYandex .= $strValue."\n";
} }
break; break;
case 'year': case 'year':
$y++; $y++;
if ($XML_DATA['TYPE'] == 'artist.title') if ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title')
{ {
if ($y == 1) continue; if ($y == 1) continue;
} }
@ -1335,10 +1352,10 @@ if (empty($arRunErrors))
} }
// no break here // no break here
default: default:
if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key])
{ {
$strValue = ''; $strValue = '';
$strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID);
if ('' != $strValue) if ('' != $strValue)
$strOfferYandex .= $strValue."\n"; $strOfferYandex .= $strValue."\n";
} }
@ -1386,11 +1403,11 @@ if (empty($arRunErrors))
$arOfferItem['YANDEX_AVAILABLE'] = 'false'; $arOfferItem['YANDEX_AVAILABLE'] = 'false';
$minPrice = -1; $minPrice = -1;
if ($XML_DATA['PRICE'] > 0) if ($XML_DATA[$IBLOCK_ID]['PRICE'] > 0)
{ {
$rsPrices = CPrice::GetListEx(array(),array( $rsPrices = CPrice::GetListEx(array(),array(
'PRODUCT_ID' => $arOfferItem['ID'], 'PRODUCT_ID' => $arOfferItem['ID'],
'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], 'CATALOG_GROUP_ID' => $XML_DATA[$IBLOCK_ID]['PRICE'],
'CAN_BUY' => 'Y', 'CAN_BUY' => 'Y',
'GROUP_GROUP_ID' => array(2), 'GROUP_GROUP_ID' => array(2),
'+<=QUANTITY_FROM' => 1, '+<=QUANTITY_FROM' => 1,
@ -1419,7 +1436,7 @@ if (empty($arRunErrors))
$arDiscounts = CCatalogDiscount::GetDiscount( $arDiscounts = CCatalogDiscount::GetDiscount(
$arOfferItem['ID'], $arOfferItem['ID'],
$intOfferIBlockID, $intOfferIBlockID,
array($XML_DATA['PRICE']), array($XML_DATA[$IBLOCK_ID]['PRICE']),
array(2), array(2),
'N', 'N',
$arOfferIBlock['LID'], $arOfferIBlock['LID'],
@ -1471,8 +1488,8 @@ if (empty($arRunErrors))
else else
$arOfferItem['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arOfferItem['DETAIL_PAGE_URL']); $arOfferItem['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arOfferItem['DETAIL_PAGE_URL']);
if (is_array($XML_DATA) && $XML_DATA['TYPE'] && $XML_DATA['TYPE'] != 'none') if (is_array($XML_DATA[$IBLOCK_ID]) && $XML_DATA[$IBLOCK_ID]['TYPE'] && $XML_DATA[$IBLOCK_ID]['TYPE'] != 'none')
$str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA['TYPE']).'"'; $str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA[$IBLOCK_ID]['TYPE']).'"';
else else
$str_TYPE = ''; $str_TYPE = '';
@ -1518,7 +1535,7 @@ if (empty($arRunErrors))
switch ($key) switch ($key)
{ {
case 'name': case 'name':
if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) if (is_array($XML_DATA[$IBLOCK_ID]) && ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model' || $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title'))
continue; continue;
$strOfferYandex .= "<name>".yandex_text2xml($arOfferItem["NAME"], true)."</name>\n"; $strOfferYandex .= "<name>".yandex_text2xml($arOfferItem["NAME"], true)."</name>\n";
@ -1540,9 +1557,9 @@ if (empty($arRunErrors))
$strOfferYandex .= "</description>\n"; $strOfferYandex .= "</description>\n";
break; break;
case 'param': case 'param':
if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS']))
{ {
foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) foreach ($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'] as $key => $prop_id)
{ {
$strParamValue = ''; $strParamValue = '';
if ($prop_id) if ($prop_id)
@ -1562,26 +1579,26 @@ if (empty($arRunErrors))
break; break;
case 'model': case 'model':
case 'title': case 'title':
if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) if (!is_array($XML_DATA[$IBLOCK_ID]) || !is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) || !$XML_DATA[$IBLOCK_ID]['XML_DATA'][$key])
{ {
if ( if (
$key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' $key == 'model' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model'
|| ||
$key == 'title' && $XML_DATA['TYPE'] == 'artist.title' $key == 'title' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title'
) )
$strOfferYandex .= "<".$key.">".yandex_text2xml($arOfferItem["NAME"], true)."</".$key.">\n"; $strOfferYandex .= "<".$key.">".yandex_text2xml($arOfferItem["NAME"], true)."</".$key.">\n";
} }
else else
{ {
$strValue = ''; $strValue = '';
$strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID);
if ('' != $strValue) if ('' != $strValue)
$strOfferYandex .= $strValue."\n"; $strOfferYandex .= $strValue."\n";
} }
break; break;
case 'year': case 'year':
$y++; $y++;
if ($XML_DATA['TYPE'] == 'artist.title') if ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title')
{ {
if ($y == 1) continue; if ($y == 1) continue;
} }
@ -1591,10 +1608,10 @@ if (empty($arRunErrors))
} }
// no break here // no break here
default: default:
if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key])
{ {
$strValue = ''; $strValue = '';
$strValue = yandex_get_value($arOfferItem, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); $strValue = yandex_get_value($arOfferItem, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID);
if ('' != $strValue) if ('' != $strValue)
$strOfferYandex .= $strValue."\n"; $strOfferYandex .= $strValue."\n";
} }
@ -1630,11 +1647,11 @@ if (empty($arRunErrors))
$minPriceGroup = 0; $minPriceGroup = 0;
$minPriceCurrency = ""; $minPriceCurrency = "";
if ($XML_DATA['PRICE'] > 0) if ($XML_DATA[$IBLOCK_ID]['PRICE'] > 0)
{ {
$rsPrices = CPrice::GetListEx(array(),array( $rsPrices = CPrice::GetListEx(array(),array(
'PRODUCT_ID' => $arItem['ID'], 'PRODUCT_ID' => $arItem['ID'],
'CATALOG_GROUP_ID' => $XML_DATA['PRICE'], 'CATALOG_GROUP_ID' => $XML_DATA[$IBLOCK_ID]['PRICE'],
'CAN_BUY' => 'Y', 'CAN_BUY' => 'Y',
'GROUP_GROUP_ID' => array(2), 'GROUP_GROUP_ID' => array(2),
'+<=QUANTITY_FROM' => 1, '+<=QUANTITY_FROM' => 1,
@ -1663,7 +1680,7 @@ if (empty($arRunErrors))
$arDiscounts = CCatalogDiscount::GetDiscount( $arDiscounts = CCatalogDiscount::GetDiscount(
$arItem['ID'], $arItem['ID'],
$IBLOCK_ID, $IBLOCK_ID,
array($XML_DATA['PRICE']), array($XML_DATA[$IBLOCK_ID]['PRICE']),
array(2), array(2),
'N', 'N',
$ar_iblock['LID'], $ar_iblock['LID'],
@ -1726,8 +1743,8 @@ if (empty($arRunErrors))
$arItem['~DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arItem['~DETAIL_PAGE_URL']); $arItem['~DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arItem['~DETAIL_PAGE_URL']);
} }
if (is_array($XML_DATA) && $XML_DATA['TYPE'] && $XML_DATA['TYPE'] != 'none') if (is_array($XML_DATA[$IBLOCK_ID]) && $XML_DATA[$IBLOCK_ID]['TYPE'] && $XML_DATA[$IBLOCK_ID]['TYPE'] != 'none')
$str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA['TYPE']).'"'; $str_TYPE = ' type="'.htmlspecialcharsbx($XML_DATA[$IBLOCK_ID]['TYPE']).'"';
else else
$str_TYPE = ''; $str_TYPE = '';
if (!isset($arItem["ID"])) if (!isset($arItem["ID"]))
@ -1754,7 +1771,7 @@ if (empty($arRunErrors))
switch ($key) switch ($key)
{ {
case 'name': case 'name':
if (is_array($XML_DATA) && ($XML_DATA['TYPE'] == 'vendor.model' || $XML_DATA['TYPE'] == 'artist.title')) if (is_array($XML_DATA[$IBLOCK_ID]) && ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model' || $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title'))
continue; continue;
$strValue = "<name>".yandex_text2xml($arItem["NAME"], true)."</name>\n"; $strValue = "<name>".yandex_text2xml($arItem["NAME"], true)."</name>\n";
@ -1769,9 +1786,9 @@ if (empty($arRunErrors))
"</description>\n"; "</description>\n";
break; break;
case 'param': case 'param':
if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']['PARAMS'])) if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS']))
{ {
foreach ($XML_DATA['XML_DATA']['PARAMS'] as $key => $prop_id) foreach ($XML_DATA[$IBLOCK_ID]['XML_DATA']['PARAMS'] as $key => $prop_id)
{ {
$strParamValue = ''; $strParamValue = '';
if ($prop_id) if ($prop_id)
@ -1791,26 +1808,26 @@ if (empty($arRunErrors))
break; break;
case 'model': case 'model':
case 'title': case 'title':
if (!is_array($XML_DATA) || !is_array($XML_DATA['XML_DATA']) || !$XML_DATA['XML_DATA'][$key]) if (!is_array($XML_DATA[$IBLOCK_ID]) || !is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) || !$XML_DATA[$IBLOCK_ID]['XML_DATA'][$key])
{ {
if ( if (
$key == 'model' && $XML_DATA['TYPE'] == 'vendor.model' $key == 'model' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'vendor.model'
|| ||
$key == 'title' && $XML_DATA['TYPE'] == 'artist.title' $key == 'title' && $XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title'
) )
$strValue = "<".$key.">".yandex_text2xml($arItem["NAME"], true)."</".$key.">\n"; $strValue = "<".$key.">".yandex_text2xml($arItem["NAME"], true)."</".$key.">\n";
} }
else else
{ {
$strValue = yandex_get_value($arItem, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); $strValue = yandex_get_value($arItem, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID);
if ('' != $strValue) if ('' != $strValue)
$strValue .= "\n"; $strValue .= "\n";
} }
break; break;
case 'year': case 'year':
$y++; $y++;
if ($XML_DATA['TYPE'] == 'artist.title') if ($XML_DATA[$IBLOCK_ID]['TYPE'] == 'artist.title')
{ {
if ($y == 1) continue; if ($y == 1) continue;
} }
@ -1822,9 +1839,9 @@ if (empty($arRunErrors))
// no break here // no break here
default: default:
if (is_array($XML_DATA) && is_array($XML_DATA['XML_DATA']) && $XML_DATA['XML_DATA'][$key]) if (is_array($XML_DATA[$IBLOCK_ID]) && is_array($XML_DATA[$IBLOCK_ID]['XML_DATA']) && $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key])
{ {
$strValue = yandex_get_value($arItem, $key, $XML_DATA['XML_DATA'][$key], $IBLOCK_ID); $strValue = yandex_get_value($arItem, $key, $XML_DATA[$IBLOCK_ID]['XML_DATA'][$key], $IBLOCK_ID);
if ('' != $strValue) if ('' != $strValue)
$strValue .= "\n"; $strValue .= "\n";
} }
@ -1869,6 +1886,7 @@ if (empty($arRunErrors))
@fclose($fp); @fclose($fp);
} }
CCatalogDiscountSave::Enable(); CCatalogDiscountSave::Enable();