1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
yandex_run.php
См. документацию.
1<?
2//<title>Yandex</title>
14
15use Bitrix\Main,
21
22IncludeModuleLangFile($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/catalog/export_yandex.php');
23IncludeModuleLangFile(__FILE__);
24
26if ($MAX_EXECUTION_TIME <= 0)
28if (defined('BX_CAT_CRON') && BX_CAT_CRON == true)
29{
31 $firstStep = true;
32}
33if (defined("CATALOG_EXPORT_NO_STEP") && CATALOG_EXPORT_NO_STEP == true)
34{
36 $firstStep = true;
37}
38if ($MAX_EXECUTION_TIME == 0)
39 set_time_limit(0);
40
42if ($CHECK_PERMISSIONS == 'Y')
43 $permissionFilter = array('CHECK_PERMISSIONS' => 'Y', 'MIN_PERMISSION' => 'R', 'PERMISSIONS_BY' => 0);
44else
45 $permissionFilter = array('CHECK_PERMISSIONS' => 'N');
46
47if (!isset($firstStep))
48 $firstStep = true;
49
51$navParams = array('nTopCount' => $pageSize);
52
53$SETUP_VARS_LIST = 'IBLOCK_ID,SITE_ID,V,XML_DATA,SETUP_SERVER_NAME,COMPANY_NAME,SETUP_FILE_NAME,USE_HTTPS,FILTER_AVAILABLE,DISABLE_REFERERS,EXPORT_CHARSET,MAX_EXECUTION_TIME,CHECK_PERMISSIONS';
54$INTERNAL_VARS_LIST = 'intMaxSectionID,boolNeedRootSection,arSectionIDs,arAvailGroups';
55
56global $USER;
59{
60 $bTmpUserCreated = true;
61 if (isset($USER))
62 $USER_TMP = $USER;
63 $USER = new CUser();
64}
65
66$saleIncluded = Loader::includeModule('sale');
68 Sale\DiscountCouponsManager::freezeCouponStorage();
70
72 'typePrefix', 'vendor', 'vendorCode', 'model',
73 'author', 'name', 'publisher', 'series', 'year',
74 'ISBN', 'volume', 'part', 'language', 'binding',
75 'page_extent', 'table_of_contents', 'performed_by', 'performance_type',
76 'storage', 'format', 'recording_length', 'artist', 'title', 'year', 'media',
77 'starring', 'director', 'originalName', 'country', 'aliases',
78 'description', 'sales_notes', 'promo', 'provider', 'tarifplan',
79 'xCategory', 'additional', 'worldRegion', 'region', 'days', 'dataTour',
80 'hotel_stars', 'room', 'meal', 'included', 'transport', 'price_min', 'price_max',
81 'options', 'manufacturer_warranty', 'country_of_origin', 'downloadable', 'adult', 'param',
82 'place', 'hall', 'hall_part', 'is_premiere', 'is_kids', 'date'
83);
84
86 'none' => array(
87 'vendor', 'vendorCode', 'sales_notes', 'manufacturer_warranty', 'country_of_origin',
88 'adult'
89 ),
90 'vendor.model' => array(
91 'typePrefix', 'vendor', 'vendorCode', 'model', 'sales_notes', 'manufacturer_warranty', 'country_of_origin',
92 'adult'
93 ),
94 'book' => array(
95 'author', 'publisher', 'series', 'year', 'ISBN', 'volume', 'part', 'language', 'binding',
96 'page_extent', 'table_of_contents', 'sales_notes'
97 ),
98 'audiobook' => array(
99 'author', 'publisher', 'series', 'year', 'ISBN', 'performed_by', 'performance_type',
100 'language', 'volume', 'part', 'format', 'storage', 'recording_length', 'table_of_contents'
101 ),
102 'artist.title' => array(
103 'title', 'artist', 'director', 'starring', 'originalName', 'country', 'year', 'media', 'adult'
104 )
105);
106
107if (!function_exists("yandex_replace_special"))
108{
109 function yandex_replace_special($arg)
110 {
111 if (in_array($arg[0], array("&quot;", "&amp;", "&lt;", "&gt;")))
112 return $arg[0];
113 else
114 return " ";
115 }
116}
117
118if (!function_exists("yandex_text2xml"))
119{
120 function yandex_text2xml(string $text, array $options)
121 {
122 $text = htmlspecialcharsbx($text, ENT_QUOTES|ENT_XML1);
123
124 $text = preg_replace("/[\x1-\x8\xB-\xC\xE-\x1F]/", "", $text);
125
127 }
128}
129
130if (!function_exists('yandex_get_value'))
131{
132function yandex_get_value(
133 array $arOffer,
134 string $param,
135 $PROPERTY,
139)
140{
141 $strProperty = '';
142 $bParam = (strncmp($param, 'PARAM_', 6) == 0);
143 if (isset($arProperties[$PROPERTY]) && !empty($arProperties[$PROPERTY]))
144 {
145 $iblockProperty = $arProperties[$PROPERTY];
146 $PROPERTY_CODE = $iblockProperty['CODE'];
147 if (!isset($arOffer['PROPERTIES'][$PROPERTY_CODE]) && !isset($arOffer['PROPERTIES'][$PROPERTY]))
148 return $strProperty;
149 $arProperty = (
150 isset($arOffer['PROPERTIES'][$PROPERTY_CODE])
151 ? $arOffer['PROPERTIES'][$PROPERTY_CODE]
152 : $arOffer['PROPERTIES'][$PROPERTY]
153 );
154 if ($arProperty['ID'] != $PROPERTY)
155 return $strProperty;
156
157 $value = '';
158 $description = '';
159 switch ($iblockProperty['PROPERTY_TYPE'])
160 {
161 case 'USER_TYPE':
162 if ($iblockProperty['MULTIPLE'] == 'Y')
163 {
164 if (!empty($arProperty['~VALUE']))
165 {
166 $arValues = array();
167 foreach($arProperty["~VALUE"] as $oneValue)
168 {
169 $isArray = is_array($oneValue);
170 if (
171 ($isArray && !empty($oneValue))
172 || (!$isArray && $oneValue != '')
173 )
174 {
175 $arValues[] = call_user_func_array($arUserTypeFormat[$PROPERTY],
176 array(
177 $iblockProperty,
178 array("VALUE" => $oneValue),
179 array('MODE' => 'SIMPLE_TEXT'),
180 )
181 );
182 }
183 }
184 $value = implode(', ', $arValues);
185 }
186 }
187 else
188 {
189 $isArray = is_array($arProperty['~VALUE']);
190 if (
191 ($isArray && !empty($arProperty['~VALUE']))
192 || (!$isArray && $arProperty['~VALUE'] != '')
193 )
194 {
195 $value = call_user_func_array($arUserTypeFormat[$PROPERTY],
196 array(
197 $iblockProperty,
198 array("VALUE" => $arProperty["~VALUE"]),
199 array('MODE' => 'SIMPLE_TEXT'),
200 )
201 );
202 }
203 }
204 break;
206 if (!empty($arProperty['VALUE']))
207 {
208 $arCheckValue = array();
209 if (!is_array($arProperty['VALUE']))
210 {
211 $arProperty['VALUE'] = (int)$arProperty['VALUE'];
212 if ($arProperty['VALUE'] > 0)
213 $arCheckValue[] = $arProperty['VALUE'];
214 }
215 else
216 {
217 foreach ($arProperty['VALUE'] as $intValue)
218 {
219 $intValue = (int)$intValue;
220 if ($intValue > 0)
221 $arCheckValue[] = $intValue;
222 }
223 unset($intValue);
224 }
225 if (!empty($arCheckValue))
226 {
227 $filter = array(
228 '@ID' => $arCheckValue
229 );
230 if ($iblockProperty['LINK_IBLOCK_ID'] > 0)
231 $filter['=IBLOCK_ID'] = $iblockProperty['LINK_IBLOCK_ID'];
232
233 $iterator = Iblock\ElementTable::getList(array(
234 'select' => array('ID', 'NAME'),
235 'filter' => array($filter)
236 ));
237 while ($row = $iterator->fetch())
238 {
239 $value .= ($value ? ', ' : '').$row['NAME'];
240 }
241 unset($row, $iterator);
242 }
243 }
244 break;
246 if (!empty($arProperty['VALUE']))
247 {
248 $arCheckValue = array();
249 if (!is_array($arProperty['VALUE']))
250 {
251 $arProperty['VALUE'] = (int)$arProperty['VALUE'];
252 if ($arProperty['VALUE'] > 0)
253 $arCheckValue[] = $arProperty['VALUE'];
254 }
255 else
256 {
257 foreach ($arProperty['VALUE'] as $intValue)
258 {
259 $intValue = (int)$intValue;
260 if ($intValue > 0)
261 $arCheckValue[] = $intValue;
262 }
263 unset($intValue);
264 }
265 if (!empty($arCheckValue))
266 {
267 $filter = array(
268 '@ID' => $arCheckValue
269 );
270 if ($iblockProperty['LINK_IBLOCK_ID'] > 0)
271 $filter['=IBLOCK_ID'] = $iblockProperty['LINK_IBLOCK_ID'];
272
273 $iterator = Iblock\SectionTable::getList(array(
274 'select' => array('ID', 'NAME'),
275 'filter' => array($filter)
276 ));
277 while ($row = $iterator->fetch())
278 {
279 $value .= ($value ? ', ' : '').$row['NAME'];
280 }
281 unset($row, $iterator);
282 }
283 }
284 break;
286 if (!empty($arProperty['~VALUE']))
287 {
288 if (is_array($arProperty['~VALUE']))
289 $value .= implode(', ', $arProperty['~VALUE']);
290 else
291 $value .= $arProperty['~VALUE'];
292 }
293 break;
295 if (!empty($arProperty['VALUE']))
296 {
297 if (is_array($arProperty['VALUE']))
298 {
299 foreach ($arProperty['VALUE'] as $intValue)
300 {
301 $intValue = (int)$intValue;
302 if ($intValue > 0)
303 {
304 if ($ar_file = CFile::GetFileArray($intValue))
305 {
306 if(mb_substr($ar_file["SRC"], 0, 1) == "/")
307 $strFile = $options['PROTOCOL'].$options['SITE_NAME'].CHTTP::urnEncode($ar_file['SRC'], 'utf-8');
308 else
309 $strFile = $ar_file["SRC"];
310 $value .= ($value ? ', ' : '').$strFile;
311 }
312 }
313 }
314 unset($intValue);
315 }
316 else
317 {
318 $arProperty['VALUE'] = (int)$arProperty['VALUE'];
319 if ($arProperty['VALUE'] > 0)
320 {
321 if ($ar_file = CFile::GetFileArray($arProperty['VALUE']))
322 {
323 if(mb_substr($ar_file["SRC"], 0, 1) == "/")
324 $strFile = $options['PROTOCOL'].$options['SITE_NAME'].CHTTP::urnEncode($ar_file['SRC'], 'utf-8');
325 else
326 $strFile = $ar_file["SRC"];
328 }
329 }
330 }
331 }
332 break;
333 default:
334 if ($bParam && $iblockProperty['WITH_DESCRIPTION'] == 'Y')
335 {
336 $description = $arProperty['~DESCRIPTION'];
337 $value = $arProperty['~VALUE'];
338 }
339 else
340 {
341 $value = is_array($arProperty['~VALUE']) ? implode(', ', $arProperty['~VALUE']) : $arProperty['~VALUE'];
342 }
343 }
344
345 // !!!! check multiple properties and properties like CML2_ATTRIBUTES
346
347 if ($bParam)
348 {
349 if (is_array($description))
350 {
351 if (!empty($value))
352 {
353 foreach ($value as $key => $val)
354 {
355 if ($val != '')
356 {
357 $strProperty .= $strProperty ? "\n" : "";
358 $strProperty .= '<param name="'.yandex_text2xml($description[$key], $options).'">'.
359 yandex_text2xml($val, $options).'</param>';
360 }
361 }
362 }
363 }
364 else
365 {
366 if ($value != '')
367 {
368 $strProperty .= '<param name="'.yandex_text2xml($iblockProperty['NAME'], $options).'">'.
369 yandex_text2xml($value, $options).'</param>';
370 }
371 }
372 }
373 else
374 {
375 $param_h = yandex_text2xml($param, $options);
376 $strProperty .= '<'.$param_h.'>'.yandex_text2xml($value, $options).'</'.$param_h.'>';
377 }
378
379 unset($iblockProperty);
380 }
381
382 return $strProperty;
383}
384}
385
386if (!function_exists('yandexPrepareItems'))
387{
388 function yandexPrepareItems(array &$list, array $parents, array $options)
389 {
390 $descrField = 'PREVIEW_TEXT';
391 $descrTypeField = 'PREVIEW_TEXT_TYPE';
392 if (isset($options['DESCRIPTION']))
393 {
394 $descrField = $options['DESCRIPTION'];
395 $descrTypeField = $options['DESCRIPTION'].'_TYPE';
396 }
397
398 foreach (array_keys($list) as $index)
399 {
400 $row = &$list[$index];
401
402 $row['DETAIL_PAGE_URL'] = (string)$row['DETAIL_PAGE_URL'];
403 if ($row['DETAIL_PAGE_URL'] !== '')
404 {
405 $safeRow = array();
406 foreach ($row as $field => $value)
407 {
408 if ($field == 'PREVIEW_TEXT' || $field == 'DETAIL_TEXT')
409 continue;
411 continue;
412 if (is_array($value))
413 continue;
414 if (preg_match("/[;&<>\"]/", $value))
415 $safeRow[$field] = htmlspecialcharsEx($value);
416 else
417 $safeRow[$field] = $value;
418 $safeRow['~'.$field] = $value;
419 }
420 unset($field, $value);
421
422 if (isset($row['PARENT_ID']) && isset($parents[$row['PARENT_ID']]))
423 {
424 $safeRow['~DETAIL_PAGE_URL'] = str_replace(
425 array('#SERVER_NAME#', '#SITE_DIR#', '#PRODUCT_URL#'),
426 array($options['SITE_NAME'], $options['SITE_DIR'], $parents[$row['PARENT_ID']]),
427 $safeRow['~DETAIL_PAGE_URL']
428 );
429 }
430 else
431 {
432 $safeRow['~DETAIL_PAGE_URL'] = str_replace(
433 array('#SERVER_NAME#', '#SITE_DIR#'),
434 array($options['SITE_NAME'], $options['SITE_DIR']),
435 $safeRow['~DETAIL_PAGE_URL']
436 );
437 }
438 $row['DETAIL_PAGE_URL'] = \CIBlock::ReplaceDetailUrl($safeRow['~DETAIL_PAGE_URL'], $safeRow, false, 'E');
439 unset($safeRow);
440 }
441
442 if ($row['DETAIL_PAGE_URL'] == '')
443 $row['DETAIL_PAGE_URL'] = '/';
444 else
445 $row['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $row['DETAIL_PAGE_URL']);
446
447 $row['PICTURE'] = false;
448 $row['DETAIL_PICTURE'] = (int)$row['DETAIL_PICTURE'];
449 $row['PREVIEW_PICTURE'] = (int)$row['PREVIEW_PICTURE'];
450 if ($row['DETAIL_PICTURE'] > 0 || $row['PREVIEW_PICTURE'] > 0)
451 {
452 $pictureFile = CFile::GetFileArray($row['DETAIL_PICTURE'] > 0 ? $row['DETAIL_PICTURE'] : $row['PREVIEW_PICTURE']);
453 if (!empty($pictureFile))
454 {
455 if (strncmp($pictureFile['SRC'], '/', 1) == 0)
456 $picturePath = $options['PROTOCOL'].$options['SITE_NAME'].CHTTP::urnEncode($pictureFile['SRC'], 'utf-8');
457 else
458 $picturePath = $pictureFile['SRC'];
459 $row['PICTURE'] = $picturePath;
460 unset($picturePath);
461 }
462 unset($pictureFile);
463 }
464
465 $row['DESCRIPTION'] = '';
466 if ($row[$descrField] !== null)
467 {
468 $row['DESCRIPTION'] = yandex_text2xml(
470 $row[$descrTypeField] == 'html'
471 ? strip_tags(preg_replace_callback("'&[^;]*;'", 'yandex_replace_special', $row[$descrField]))
472 : preg_replace_callback("'&[^;]*;'", 'yandex_replace_special', $row[$descrField]),
473 $options['MAX_DESCRIPTION_LENGTH']
474 ),
476 );
477 }
478
479 unset($row);
480 }
481 unset($index);
482 }
483}
484
486
487if (isset($XML_DATA))
488{
489 if (is_string($XML_DATA) && CheckSerializedData($XML_DATA))
490 $XML_DATA = unserialize(stripslashes($XML_DATA), ['allowed_classes' => false]);
491}
492if (!isset($XML_DATA) || !is_array($XML_DATA))
493 $arRunErrors[] = GetMessage('YANDEX_ERR_BAD_XML_DATA');
494
496if (isset($XML_DATA['TYPE']) && isset($formatList[$XML_DATA['TYPE']]))
497 $yandexFormat = $XML_DATA['TYPE'];
498
499$productFormat = ($yandexFormat != 'none' ? ' type="'.htmlspecialcharsbx($yandexFormat).'"' : '');
500
503$fieldsExist = !empty($XML_DATA['XML_DATA']) && is_array($XML_DATA['XML_DATA']);
505if ($fieldsExist)
506{
507 foreach ($XML_DATA['XML_DATA'] as $key => $value)
508 {
509 if ($key == 'PARAMS')
510 $parametricFieldsExist = (!empty($value) && is_array($value));
511 if (is_array($value))
512 continue;
513 $value = (string)$value;
514 if ($value == '')
515 continue;
516 $fields[$key] = $value;
517 }
518 unset($key, $value);
519 $fieldsExist = !empty($fields);
520}
521
523{
524 $parametricFields = $XML_DATA['XML_DATA']['PARAMS'];
525 if (!empty($parametricFields))
526 {
527 foreach (array_keys($parametricFields) as $index)
528 {
529 if ((string)$parametricFields[$index] === '')
530 unset($parametricFields[$index]);
531 }
532 }
534}
535
538if ($fieldsExist)
539{
540 foreach ($fields as $id)
541 $yandexNeedPropertyIds[$id] = true;
542 unset($id);
543}
545{
546 foreach ($parametricFields as $id)
547 $yandexNeedPropertyIds[$id] = true;
548 unset($id);
549}
550
552 'DESCRIPTION' => 'PREVIEW_TEXT'
553];
554if (!empty($XML_DATA['COMMON_FIELDS']) && is_array($XML_DATA['COMMON_FIELDS']))
555 $commonFields = array_merge($commonFields, $XML_DATA['COMMON_FIELDS']);
556$descrField = $commonFields['DESCRIPTION'];
557
559 'ID', 'PROPERTY_TYPE', 'MULTIPLE', 'USER_TYPE'
560);
561
563 'USE_DOMAIN' => true,
564 'REFERRER_SEPARATOR' => '?'
565];
567 'USE_DOMAIN' => true,
568 'REFERRER_SEPARATOR' => '?'
569];
570
572$db_iblock = CIBlock::GetByID($IBLOCK_ID);
573if (!($ar_iblock = $db_iblock->Fetch()))
574{
575 $arRunErrors[] = str_replace('#ID#', $IBLOCK_ID, GetMessage('YANDEX_ERR_NO_IBLOCK_FOUND_EXT'));
576}
577/*elseif (!CIBlockRights::UserHasRightTo($IBLOCK_ID, $IBLOCK_ID, 'iblock_admin_display'))
578{
579 $arRunErrors[] = str_replace('#IBLOCK_ID#',$IBLOCK_ID,GetMessage('CET_ERROR_IBLOCK_PERM'));
580} */
581else
582{
583 $ar_iblock['PROPERTY'] = array();
584 $rsProps = \CIBlockProperty::GetList(
585 array('SORT' => 'ASC', 'NAME' => 'ASC'),
586 array('IBLOCK_ID' => $IBLOCK_ID, 'ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N')
587 );
588 while ($arProp = $rsProps->Fetch())
589 {
590 $arProp['ID'] = (int)$arProp['ID'];
591 $arProp['USER_TYPE'] = (string)$arProp['USER_TYPE'];
592 $arProp['CODE'] = (string)$arProp['CODE'];
593 if ($arProp['CODE'] == '')
594 $arProp['CODE'] = $arProp['ID'];
595 $arProp['LINK_IBLOCK_ID'] = (int)$arProp['LINK_IBLOCK_ID'];
596 $ar_iblock['PROPERTY'][$arProp['ID']] = $arProp;
597 }
598 unset($arProp, $rsProps);
599
600 $ar_iblock['DETAIL_PAGE_URL'] = (string)$ar_iblock['DETAIL_PAGE_URL'];
601 $itemUrlConfig['USE_DOMAIN'] = !(preg_match("/^(http|https):\\/\\//i", $ar_iblock['DETAIL_PAGE_URL']));
602 $itemUrlConfig['REFERRER_SEPARATOR'] = (mb_strpos($ar_iblock['DETAIL_PAGE_URL'], '?') === false ? '?' : '&amp;');
603}
604
607$SITE_ID = (isset($SITE_ID) ? (string)$SITE_ID : '');
608if ($SITE_ID === '')
609 $SITE_ID = $ar_iblock['LID'];
610$iterator = Main\SiteTable::getList(array(
611 'select' => array('LID', 'SERVER_NAME', 'SITE_NAME', 'DIR'),
612 'filter' => array('=LID' => $SITE_ID, '=ACTIVE' => 'Y')
613));
614$site = $iterator->fetch();
615unset($iterator);
616if (empty($site))
617{
618 $arRunErrors[] = GetMessage('BX_CATALOG_EXPORT_YANDEX_ERR_BAD_SITE');
619}
620else
621{
622 $site['SITE_NAME'] = (string)$site['SITE_NAME'];
623 if ($site['SITE_NAME'] === '')
624 $site['SITE_NAME'] = (string)Main\Config\Option::get('main', 'site_name');
625 $site['COMPANY_NAME'] = $COMPANY_NAME;
626 if ($site['COMPANY_NAME'] === '')
627 $site['COMPANY_NAME'] = (string)Main\Config\Option::get('main', 'site_name');
628 $site['SERVER_NAME'] = (string)$site['SERVER_NAME'];
629 if ($SETUP_SERVER_NAME !== '')
630 $site['SERVER_NAME'] = $SETUP_SERVER_NAME;
631 if ($site['SERVER_NAME'] === '')
632 {
633 $site['SERVER_NAME'] = (defined('SITE_SERVER_NAME')
634 ? SITE_SERVER_NAME
635 : (string)Main\Config\Option::get('main', 'server_name')
636 );
637 }
638 if ($site['SERVER_NAME'] === '')
639 {
640 $arRunErrors[] = GetMessage('BX_CATALOG_EXPORT_YANDEX_ERR_BAD_SERVER_NAME');
641 }
642}
643
645if (isset($ar_iblock['PROPERTY']))
646 $arProperties = $ar_iblock['PROPERTY'];
647
649$arOffers = false;
655 Iblock\PropertyTable::TYPE_STRING,
656 Iblock\PropertyTable::TYPE_NUMBER,
657 Iblock\PropertyTable::TYPE_LIST,
658 Iblock\PropertyTable::TYPE_ELEMENT,
659 Iblock\PropertyTable::TYPE_SECTION
660);
665);
667 'ZERO',
668 'NONZERO',
669 'EQUAL',
670 'NONEQUAL',
671);
673
674$arCatalog = CCatalogSku::GetInfoByIBlock($IBLOCK_ID);
675if (empty($arCatalog))
676{
677 $arRunErrors[] = str_replace('#ID#', $IBLOCK_ID, GetMessage('YANDEX_ERR_NO_IBLOCK_IS_CATALOG'));
678}
679else
680{
681 $arCatalog['VAT_ID'] = (int)$arCatalog['VAT_ID'];
683 if (!empty($arOffers['IBLOCK_ID']))
684 {
685 $intOfferIBlockID = $arOffers['IBLOCK_ID'];
686 $rsOfferIBlocks = CIBlock::GetByID($intOfferIBlockID);
687 if (($arOfferIBlock = $rsOfferIBlocks->Fetch()))
688 {
689 $boolOffers = true;
690 $rsProps = \CIBlockProperty::GetList(
691 array('SORT' => 'ASC', 'NAME' => 'ASC'),
692 array('IBLOCK_ID' => $intOfferIBlockID, 'ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N')
693 );
694 while ($arProp = $rsProps->Fetch())
695 {
696 $arProp['ID'] = (int)$arProp['ID'];
697 if ($arOffers['SKU_PROPERTY_ID'] != $arProp['ID'])
698 {
699 $arProp['USER_TYPE'] = (string)$arProp['USER_TYPE'];
700 $arProp['CODE'] = (string)$arProp['CODE'];
701 if ($arProp['CODE'] == '')
702 $arProp['CODE'] = $arProp['ID'];
703 $arProp['LINK_IBLOCK_ID'] = (int)$arProp['LINK_IBLOCK_ID'];
704
705 $ar_iblock['OFFERS_PROPERTY'][$arProp['ID']] = $arProp;
706 $arProperties[$arProp['ID']] = $arProp;
707 if (in_array($arProp['PROPERTY_TYPE'], $arSelectedPropTypes))
708 $arSelectOfferProps[] = $arProp['ID'];
709 }
710 }
711 unset($arProp, $rsProps);
712 $arOfferIBlock['LID'] = $site['LID'];
713
714 $arOfferIBlock['DETAIL_PAGE_URL'] = (string)$arOfferIBlock['DETAIL_PAGE_URL'];
715 if ($arOfferIBlock['DETAIL_PAGE_URL'] == '#PRODUCT_URL#')
716 {
718 }
719 else
720 {
721 $offerUrlConfig['USE_DOMAIN'] = !(preg_match("/^(http|https):\\/\\//i", $arOfferIBlock['DETAIL_PAGE_URL']));
722 $offerUrlConfig['REFERRER_SEPARATOR'] = (mb_strpos($arOfferIBlock['DETAIL_PAGE_URL'], '?') === false ? '?' : '&amp;');
723 }
724 }
725 else
726 {
727 $arRunErrors[] = GetMessage('YANDEX_ERR_BAD_OFFERS_IBLOCK_ID');
728 }
729 unset($rsOfferIBlocks);
730 }
731 if ($boolOffers)
732 {
734 $offersCatalog['VAT_ID'] = (int)$offersCatalog['VAT_ID'];
735 if (empty($XML_DATA['SKU_EXPORT']))
736 {
737 $arRunErrors[] = GetMessage('YANDEX_ERR_SKU_SETTINGS_ABSENT');
738 }
739 else
740 {
741 $arSKUExport = $XML_DATA['SKU_EXPORT'];;
742 if (empty($arSKUExport['SKU_EXPORT_COND']) || !in_array($arSKUExport['SKU_EXPORT_COND'],$arOffersSelectKeys))
743 {
744 $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_CONDITION_ABSENT');
745 }
746 if (YANDEX_SKU_EXPORT_PROP == $arSKUExport['SKU_EXPORT_COND'])
747 {
748 if (empty($arSKUExport['SKU_PROP_COND']) || !is_array($arSKUExport['SKU_PROP_COND']))
749 {
750 $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_PROPERTY_ABSENT');
751 }
752 else
753 {
754 if (empty($arSKUExport['SKU_PROP_COND']['PROP_ID']) || !in_array($arSKUExport['SKU_PROP_COND']['PROP_ID'],$arSelectOfferProps))
755 {
756 $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_PROPERTY_ABSENT');
757 }
758 if (empty($arSKUExport['SKU_PROP_COND']['COND']) || !in_array($arSKUExport['SKU_PROP_COND']['COND'],$arCondSelectProp))
759 {
760 $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_PROPERTY_COND_ABSENT');
761 }
762 else
763 {
764 if ($arSKUExport['SKU_PROP_COND']['COND'] == 'EQUAL' || $arSKUExport['SKU_PROP_COND']['COND'] == 'NONEQUAL')
765 {
766 if (empty($arSKUExport['SKU_PROP_COND']['VALUES']))
767 {
768 $arRunErrors[] = GetMessage('YANDEX_SKU_EXPORT_ERR_PROPERTY_VALUES_ABSENT');
769 }
770 }
771 }
772 }
773 }
774 }
775 }
776}
777
779if (empty($arRunErrors))
780{
781 if (
782 $arCatalog['CATALOG_TYPE'] == CCatalogSku::TYPE_FULL
783 || $arCatalog['CATALOG_TYPE'] == CCatalogSku::TYPE_PRODUCT
784 )
785 $propertyIdList[] = $arCatalog['SKU_PROPERTY_ID'];
786}
787
789foreach($arProperties as $key => $arProperty)
790{
791 $arUserTypeFormat[$arProperty['ID']] = false;
792 if ($arProperty['USER_TYPE'] == '')
793 continue;
794
795 $arUserType = \CIBlockProperty::GetUserType($arProperty['USER_TYPE']);
796 if (isset($arUserType['GetPublicViewHTML']))
797 {
798 $arUserTypeFormat[$arProperty['ID']] = $arUserType['GetPublicViewHTML'];
799 $arProperties[$key]['PROPERTY_TYPE'] = 'USER_TYPE';
800 }
801}
802unset($arUserType, $key, $arProperty);
803
806if (empty($arRunErrors))
807{
808 if (is_array($V))
809 {
810 foreach ($V as $key => $value)
811 {
812 if (trim($value)=="0")
813 {
814 $bAllSections = true;
815 break;
816 }
817 $value = (int)$value;
818 if ($value > 0)
819 {
821 }
822 }
823 }
824 if (!$bAllSections && !empty($arSections) && $CHECK_PERMISSIONS == 'Y')
825 {
826 $clearedValues = array();
827 $filter = array(
828 'IBLOCK_ID' => $IBLOCK_ID,
829 'ID' => $arSections
830 );
832 array(),
833 array_merge($filter, $permissionFilter),
834 false,
835 array('ID')
836 );
837 while ($row = $iterator->Fetch())
838 $clearedValues[] = (int)$row['ID'];
839 unset($row, $iterator);
840 $arSections = $clearedValues;
841 unset($clearedValues);
842 }
843
844 if (!$bAllSections && empty($arSections))
845 {
846 $arRunErrors[] = GetMessage('YANDEX_ERR_NO_SECTION_LIST');
847 }
848}
849
851if (!empty($XML_DATA['PRICE']))
852{
853 $XML_DATA['PRICE'] = (int)$XML_DATA['PRICE'];
854 if ($XML_DATA['PRICE'] > 0)
855 {
856 $priceIterator = Catalog\GroupAccessTable::getList([
857 'select' => ['CATALOG_GROUP_ID'],
858 'filter' => ['=CATALOG_GROUP_ID' => $XML_DATA['PRICE'], '=GROUP_ID' => 2]
859 ]);
860 $priceType = $priceIterator->fetch();
861 if (empty($priceType))
862 $arRunErrors[] = GetMessage('YANDEX_ERR_BAD_PRICE_TYPE');
863 else
864 $selectedPriceType = $XML_DATA['PRICE'];
865 unset($priceType, $priceIterator);
866 }
867 else
868 {
869 $arRunErrors[] = GetMessage('YANDEX_ERR_BAD_PRICE_TYPE');
870 }
871}
873if (empty($arRunErrors))
874{
875 if ($selectedPriceType > 0)
876 {
878 }
879 else
880 {
881 $priceTypeList = [];
882 $priceIterator = Catalog\GroupAccessTable::getList([
883 'select' => ['CATALOG_GROUP_ID'],
884 'filter' => ['=GROUP_ID' => 2],
885 'order' => ['CATALOG_GROUP_ID' => 'ASC']
886 ]);
887 while ($priceType = $priceIterator->fetch())
888 {
889 $priceTypeId = (int)$priceType['CATALOG_GROUP_ID'];
890 $priceTypeList[$priceTypeId] = $priceTypeId;
891 unset($priceTypeId);
892 }
893 unset($priceType, $priceIterator);
894 if (empty($priceTypeList))
895 $arRunErrors[] = GetMessage('BX_CATALOG_EXPORT_YANDEX_ERR_NO_AVAILABLE_PRICE_TYPES');
896 }
897}
898
899$usedProtocol = (isset($USE_HTTPS) && $USE_HTTPS == 'Y' ? 'https://' : 'http://');
900$filterAvailable = (isset($FILTER_AVAILABLE) && $FILTER_AVAILABLE == 'Y');
901$disableReferers = (isset($DISABLE_REFERERS) && $DISABLE_REFERERS == 'Y');
902$exportCharset = (isset($EXPORT_CHARSET) && is_string($EXPORT_CHARSET) ? $EXPORT_CHARSET : '');
903if ($exportCharset != 'UTF-8')
904 $exportCharset = 'windows-1251';
905
907 'ENABLE' => 'N',
908 'BASE_VAT' => ''
909);
910
912 '0%' => 'VAT_0',
913 '10%' => 'VAT_10',
914 '18%' => 'VAT_18'
915);
917
918if (!empty($XML_DATA['VAT_EXPORT']) && is_array($XML_DATA['VAT_EXPORT']))
919 $vatExportSettings = array_merge($vatExportSettings, $XML_DATA['VAT_EXPORT']);
921if ($vatExport)
922{
923 if ($vatExportSettings['BASE_VAT'] == '')
924 {
925 $vatExport = false;
926 }
927 else
928 {
929 if ($vatExportSettings['BASE_VAT'] != '-')
930 $vatList[0] = 'NO_VAT';
931
932 $filter = array('=RATE' => array_keys($vatRates));
933 if (isset($vatRates[$vatExportSettings['BASE_VAT']]))
934 $filter['!=RATE'] = $vatExportSettings['BASE_VAT'];
935 $iterator = Catalog\VatTable::getList(array(
936 'select' => array('ID', 'RATE'),
937 'filter' => $filter,
938 'order' => array('ID' => 'ASC')
939 ));
940 while ($row = $iterator->fetch())
941 {
942 $row['ID'] = (int)$row['ID'];
943 $row['RATE'] = (float)$row['RATE'];
944 $index = $row['RATE'].'%';
945 if (isset($vatRates[$index]))
946 $vatList[$row['ID']] = $vatRates[$index];
947 }
948 unset($index, $row, $iterator);
949 }
950}
951
953 'PROTOCOL' => $usedProtocol,
954 'CHARSET' => $exportCharset,
955 'SITE_NAME' => $site['SERVER_NAME'],
956 'SITE_DIR' => $site['DIR'],
957 'DESCRIPTION' => $descrField,
958 'MAX_DESCRIPTION_LENGTH' => 3000
959);
960
963if ($SETUP_FILE_NAME == '')
964{
965 $arRunErrors[] = GetMessage("CATI_NO_SAVE_FILE");
966}
968{
969 $arRunErrors[] = GetMessage("CES_ERROR_BAD_EXPORT_FILENAME");
970}
971else
972{
974}
975if (empty($arRunErrors))
976{
977/* if ($GLOBALS["APPLICATION"]->GetFileAccessPermission($SETUP_FILE_NAME) < "W")
978 {
979 $arRunErrors[] = str_replace('#FILE#', $SETUP_FILE_NAME,GetMessage('YANDEX_ERR_FILE_ACCESS_DENIED'));
980 } */
983}
984
986
987$BASE_CURRENCY = Currency\CurrencyManager::getBaseCurrency();
988
989if ($firstStep)
990{
991 if (empty($arRunErrors))
992 {
993 CheckDirPath($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME);
994
995 if (!$fp = @fopen($_SERVER["DOCUMENT_ROOT"].$sectionFileName, "wb"))
996 {
997 $arRunErrors[] = str_replace('#FILE#', $sectionFileName, GetMessage('YANDEX_ERR_FILE_OPEN_WRITING'));
998 }
999 else
1000 {
1001 if (!@fwrite($fp, '<? $disableReferers = '.($disableReferers ? 'true' : 'false').';'."\n"))
1002 {
1003 $arRunErrors[] = str_replace('#FILE#', $sectionFileName, GetMessage('YANDEX_ERR_SETUP_FILE_WRITE'));
1004 @fclose($fp);
1005 }
1006 else
1007 {
1008 if (!$disableReferers)
1009 {
1010 fwrite($fp, 'if (!isset($_GET["referer1"]) || $_GET["referer1"] == "") $_GET["referer1"] = "yandext";'."\n");
1011 fwrite($fp, '$strReferer1 = htmlspecialchars($_GET["referer1"]);'."\n");
1012 fwrite($fp, 'if (!isset($_GET["referer2"]) || $_GET["referer2"] == "") $_GET["referer2"] = "";'."\n");
1013 fwrite($fp, '$strReferer2 = htmlspecialchars($_GET["referer2"]);'."\n");
1014 }
1015 }
1016 }
1017 }
1018
1019 if (empty($arRunErrors))
1020 {
1022 fwrite($fp, 'header("Content-Type: text/xml; charset='.$itemOptions['CHARSET'].'");'."\n");
1023 fwrite($fp, 'echo "<"."?xml version=\"1.0\" encoding=\"'.$itemOptions['CHARSET'].'\"?".">"?>');
1024 fwrite($fp, "\n".'<!DOCTYPE yml_catalog SYSTEM "shops.dtd">'."\n");
1025 fwrite($fp, '<yml_catalog date="'.date("Y-m-d H:i").'">'."\n");
1026 fwrite($fp, '<shop>'."\n");
1027
1028 fwrite($fp,
1029 '<name>'.Main\Text\Encoding::convertEncoding(
1030 htmlspecialcharsbx($site['SITE_NAME'], ENT_QUOTES|ENT_XML1),
1032 $itemOptions['CHARSET']).
1033 "</name>\n"
1034 );
1035 fwrite($fp,
1036 '<company>'.Main\Text\Encoding::convertEncoding(
1037 htmlspecialcharsbx($site['COMPANY_NAME'], ENT_QUOTES|ENT_XML1),
1039 $itemOptions['CHARSET']).
1040 "</company>\n"
1041 );
1042 fwrite($fp, '<url>'.$usedProtocol.htmlspecialcharsbx($site['SERVER_NAME'])."</url>\n");
1043 fwrite($fp, '<platform>1C-Bitrix</platform>'."\n");
1044
1045 $strTmp = '<currencies>'."\n";
1046
1047 $RUR = 'RUB';
1048 $currencyIterator = Currency\CurrencyTable::getList(array(
1049 'select' => array('CURRENCY'),
1050 'filter' => array('=CURRENCY' => 'RUR')
1051 ));
1052 if ($currency = $currencyIterator->fetch())
1053 $RUR = 'RUR';
1054 unset($currency, $currencyIterator);
1055
1056 $arCurrencyAllowed = array($RUR, 'USD', 'EUR', 'UAH', 'BYR', 'BYN', 'KZT');
1057
1058 if (is_array($XML_DATA['CURRENCY']))
1059 {
1060 foreach ($XML_DATA['CURRENCY'] as $CURRENCY => $arCurData)
1061 {
1062 if (in_array($CURRENCY, $arCurrencyAllowed))
1063 {
1064 $strTmp .= '<currency id="'.$CURRENCY.'"'
1065 .' rate="'.($arCurData['rate'] == 'SITE' ? CCurrencyRates::ConvertCurrency(1, $CURRENCY, $RUR) : $arCurData['rate']).'"'
1066 .($arCurData['plus'] > 0 ? ' plus="'.(int)$arCurData['plus'].'"' : '')
1067 ." />\n";
1068 }
1069 }
1070 unset($CURRENCY, $arCurData);
1071 }
1072 else
1073 {
1074 $currencyIterator = Currency\CurrencyTable::getList(array(
1075 'select' => array('CURRENCY', 'SORT'),
1076 'filter' => array('@CURRENCY' => $arCurrencyAllowed),
1077 'order' => array('SORT' => 'ASC', 'CURRENCY' => 'ASC')
1078 ));
1079 while ($currency = $currencyIterator->fetch())
1080 $strTmp .= '<currency id="'.$currency['CURRENCY'].'" rate="'.(CCurrencyRates::ConvertCurrency(1, $currency['CURRENCY'], $RUR)).'" />'."\n";
1081 unset($currency, $currencyIterator);
1082 }
1083 $strTmp .= "</currencies>\n";
1084
1085 fwrite($fp, $strTmp);
1086 unset($strTmp);
1087
1088 //*****************************************//
1089
1090
1091 //*****************************************//
1092 $intMaxSectionID = 0;
1093
1094 $strTmpCat = '';
1095 $strTmpOff = '';
1096
1097 $arSectionIDs = array();
1098 $arAvailGroups = array();
1099 if (!$bAllSections)
1100 {
1101 for ($i = 0, $intSectionsCount = count($arSections); $i < $intSectionsCount; $i++)
1102 {
1103 $sectionIterator = CIBlockSection::GetNavChain($IBLOCK_ID, $arSections[$i], array('ID', 'IBLOCK_SECTION_ID', 'NAME', 'LEFT_MARGIN', 'RIGHT_MARGIN'));
1104 $curLEFT_MARGIN = 0;
1105 $curRIGHT_MARGIN = 0;
1106 while ($section = $sectionIterator->Fetch())
1107 {
1108 $section['ID'] = (int)$section['ID'];
1109 $section['IBLOCK_SECTION_ID'] = (int)$section['IBLOCK_SECTION_ID'];
1110 if ($arSections[$i] == $section['ID'])
1111 {
1112 $curLEFT_MARGIN = (int)$section['LEFT_MARGIN'];
1113 $curRIGHT_MARGIN = (int)$section['RIGHT_MARGIN'];
1114 $arSectionIDs[$section['ID']] = $section['ID'];
1115 }
1116 $arAvailGroups[$section['ID']] = array(
1117 'ID' => $section['ID'],
1118 'IBLOCK_SECTION_ID' => $section['IBLOCK_SECTION_ID'],
1119 'NAME' => $section['NAME']
1120 );
1121 if ($intMaxSectionID < $section['ID'])
1122 $intMaxSectionID = $section['ID'];
1123 }
1124 unset($section, $sectionIterator);
1125
1126 $filter = array(
1127 'IBLOCK_ID' => $IBLOCK_ID,
1128 '>LEFT_MARGIN' => $curLEFT_MARGIN,
1129 '<RIGHT_MARGIN' => $curRIGHT_MARGIN,
1130 'GLOBAL_ACTIVE' => 'Y'
1131 );
1132 $sectionIterator = CIBlockSection::GetList(
1133 array('LEFT_MARGIN' => 'ASC'),
1134 array_merge($filter, $permissionFilter),
1135 false,
1136 array('ID', 'IBLOCK_SECTION_ID', 'NAME')
1137 );
1138 while ($section = $sectionIterator->Fetch())
1139 {
1140 $section['ID'] = (int)$section['ID'];
1141 $section['IBLOCK_SECTION_ID'] = (int)$section['IBLOCK_SECTION_ID'];
1142 $arAvailGroups[$section['ID']] = $section;
1143 if ($intMaxSectionID < $section['ID'])
1144 $intMaxSectionID = $section['ID'];
1145 }
1146 unset($section, $sectionIterator);
1147 }
1148 }
1149 else
1150 {
1151 $filter = array(
1152 'IBLOCK_ID' => $IBLOCK_ID,
1153 'GLOBAL_ACTIVE' => 'Y'
1154 );
1155 $sectionIterator = CIBlockSection::GetList(
1156 array('LEFT_MARGIN' => 'ASC'),
1157 array_merge($filter, $permissionFilter),
1158 false,
1159 array('ID', 'IBLOCK_SECTION_ID', 'NAME')
1160 );
1161 while ($section = $sectionIterator->Fetch())
1162 {
1163 $section['ID'] = (int)$section['ID'];
1164 $section['IBLOCK_SECTION_ID'] = (int)$section['IBLOCK_SECTION_ID'];
1165 $arAvailGroups[$section['ID']] = $section;
1166 $arSectionIDs[$section['ID']] = $section['ID'];
1167 if ($intMaxSectionID < $section['ID'])
1168 $intMaxSectionID = $section['ID'];
1169 }
1170 unset($section, $sectionIterator);
1171 }
1172
1173 foreach ($arAvailGroups as $value)
1174 $strTmpCat .= '<category id="'.$value['ID'].'"'.($value['IBLOCK_SECTION_ID'] > 0 ? ' parentId="'.$value['IBLOCK_SECTION_ID'].'"' : '').'>'.yandex_text2xml($value['NAME'], $itemOptions).'</category>'."\n";
1175 unset($value);
1176
1177 $intMaxSectionID += 100000000;
1178
1179 fwrite($fp, "<categories>\n");
1180 fwrite($fp, $strTmpCat);
1181 fclose($fp);
1182 unset($strTmpCat);
1183
1184 $boolNeedRootSection = false;
1185
1186 $itemsFile = @fopen($_SERVER["DOCUMENT_ROOT"].$itemFileName, 'wb');
1187 if (!$itemsFile)
1188 {
1189 $arRunErrors[] = str_replace('#FILE#', $itemFileName, GetMessage('YANDEX_ERR_FILE_OPEN_WRITING'));
1190 }
1191 }
1192}
1193else
1194{
1195 $itemsFile = @fopen($_SERVER["DOCUMENT_ROOT"].$itemFileName, 'ab');
1196 if (!$itemsFile)
1197 {
1198 $arRunErrors[] = str_replace('#FILE#', $itemFileName, GetMessage('YANDEX_ERR_FILE_OPEN_WRITING'));
1199 }
1200}
1201unset($arSections);
1202
1203if (empty($arRunErrors))
1204{
1205 //*****************************************//
1206 $saleDiscountOnly = false;
1207 $calculationConfig = [
1208 'CURRENCY' => $BASE_CURRENCY,
1209 'USE_DISCOUNTS' => true,
1210 'RESULT_WITH_VAT' => true,
1212 ];
1213 if ($saleIncluded)
1214 {
1215 $saleDiscountOnly = (string)Main\Config\Option::get('sale', 'use_sale_discount_only') == 'Y';
1216 if ($saleDiscountOnly)
1217 $calculationConfig['PRECISION'] = (int)Main\Config\Option::get('sale', 'value_precision');
1218 }
1220 unset($calculationConfig);
1221
1223
1224 $itemFields = array(
1225 'ID', 'IBLOCK_ID', 'IBLOCK_SECTION_ID', 'NAME',
1226 'PREVIEW_PICTURE', $descrField, $descrField.'_TYPE', 'DETAIL_PICTURE', 'DETAIL_PAGE_URL',
1227 'AVAILABLE', 'TYPE', 'VAT_ID', 'VAT_INCLUDED'
1228 );
1229 $offerFields = array(
1230 'ID', 'IBLOCK_ID', 'IBLOCK_SECTION_ID', 'NAME',
1231 'PREVIEW_PICTURE', $descrField, $descrField.'_TYPE', 'DETAIL_PICTURE', 'DETAIL_PAGE_URL',
1232 'AVAILABLE', 'TYPE', 'VAT_ID', 'VAT_INCLUDED'
1233 );
1234
1235 $allowedTypes = array();
1236 switch ($arCatalog['CATALOG_TYPE'])
1237 {
1239 $allowedTypes = array(
1240 Catalog\ProductTable::TYPE_PRODUCT => true,
1241 Catalog\ProductTable::TYPE_SET => true
1242 );
1243 break;
1245 $allowedTypes = array(
1246 Catalog\ProductTable::TYPE_OFFER => true
1247 );
1248 break;
1250 $allowedTypes = array(
1251 Catalog\ProductTable::TYPE_PRODUCT => true,
1252 Catalog\ProductTable::TYPE_SET => true,
1253 Catalog\ProductTable::TYPE_SKU => true
1254 );
1255 break;
1257 $allowedTypes = array(
1258 Catalog\ProductTable::TYPE_SKU => true
1259 );
1260 break;
1261 }
1262
1263 $filter = array('IBLOCK_ID' => $IBLOCK_ID);
1264 if (!$bAllSections && !empty($arSectionIDs))
1265 {
1266 $filter['INCLUDE_SUBSECTIONS'] = 'Y';
1267 $filter['SECTION_ID'] = $arSectionIDs;
1268 }
1269 $filter['ACTIVE'] = 'Y';
1270 $filter['ACTIVE_DATE'] = 'Y';
1271 if ($filterAvailable)
1272 $filter['AVAILABLE'] = 'Y';
1273 $filter = array_merge($filter, $permissionFilter);
1274
1275 $offersFilter = array('ACTIVE' => 'Y', 'ACTIVE_DATE' => 'Y');
1276 if ($filterAvailable)
1277 $offersFilter['AVAILABLE'] = 'Y';
1278 $offersFilter = array_merge($offersFilter, $permissionFilter);
1279
1280 if (isset($allowedTypes[Catalog\ProductTable::TYPE_SKU]))
1281 {
1282 if ($arSKUExport['SKU_EXPORT_COND'] == YANDEX_SKU_EXPORT_PROP)
1283 {
1284 $strExportKey = '';
1285 $mxValues = false;
1286 if ($arSKUExport['SKU_PROP_COND']['COND'] == 'NONZERO' || $arSKUExport['SKU_PROP_COND']['COND'] == 'NONEQUAL')
1287 $strExportKey = '!';
1288 $strExportKey .= 'PROPERTY_'.$arSKUExport['SKU_PROP_COND']['PROP_ID'];
1289 if ($arSKUExport['SKU_PROP_COND']['COND'] == 'EQUAL' || $arSKUExport['SKU_PROP_COND']['COND'] == 'NONEQUAL')
1290 $mxValues = $arSKUExport['SKU_PROP_COND']['VALUES'];
1291 $offersFilter[$strExportKey] = $mxValues;
1292 }
1293 }
1294
1295 do
1296 {
1297 if (isset($CUR_ELEMENT_ID) && $CUR_ELEMENT_ID > 0)
1298 $filter['>ID'] = $CUR_ELEMENT_ID;
1299
1300 $existItems = false;
1301
1302 $itemIdsList = array();
1303 $items = array();
1304
1305 $skuIdsList = array();
1306 $simpleIdsList = array();
1307
1309 array('ID' => 'ASC'),
1310 $filter,
1311 false,
1312 $navParams,
1313 $itemFields
1314 );
1315 while ($row = $iterator->Fetch())
1316 {
1317 $finalExport = false; // items exist
1318 $existItems = true;
1319
1320 $id = (int)$row['ID'];
1321 $CUR_ELEMENT_ID = $id;
1322
1323 $row['TYPE'] = (int)$row['TYPE'];
1324 $elementType = $row['TYPE'];
1325 if (!isset($allowedTypes[$elementType]))
1326 continue;
1327
1328 $row['SECTIONS'] = array();
1329 if ($needProperties || $needDiscountCache)
1330 $row['PROPERTIES'] = array();
1331 $row['PRICES'] = array();
1332
1333 $items[$id] = $row;
1334 $itemIdsList[$id] = $id;
1335
1336 if ($elementType == Catalog\ProductTable::TYPE_SKU)
1337 $skuIdsList[$id] = $id;
1338 else
1339 $simpleIdsList[$id] = $id;
1340 }
1341 unset($row, $iterator);
1342
1343 if (!empty($items))
1344 {
1345 yandexPrepareItems($items, array(), $itemOptions);
1346
1347 foreach (array_chunk($itemIdsList, 500) as $pageIds)
1348 {
1349 $iterator = Iblock\SectionElementTable::getList(array(
1350 'select' => array('IBLOCK_ELEMENT_ID', 'IBLOCK_SECTION_ID'),
1351 'filter' => array('@IBLOCK_ELEMENT_ID' => $pageIds, '==ADDITIONAL_PROPERTY_ID' => null),
1352 'order' => array('IBLOCK_ELEMENT_ID' => 'ASC')
1353 ));
1354 while ($row = $iterator->fetch())
1355 {
1356 $id = (int)$row['IBLOCK_ELEMENT_ID'];
1357 $sectionId = (int)$row['IBLOCK_SECTION_ID'];
1358 $items[$id]['SECTIONS'][$sectionId] = $sectionId;
1359 unset($sectionId, $id);
1360 }
1361 unset($row, $iterator);
1362 }
1363 unset($pageIds);
1364
1365 if ($needProperties || $needDiscountCache)
1366 {
1367 if (!empty($propertyIdList))
1368 {
1369 \CIBlockElement::GetPropertyValuesArray(
1370 $items,
1371 $IBLOCK_ID,
1372 array(
1373 'ID' => $itemIdsList,
1374 'IBLOCK_ID' => $IBLOCK_ID
1375 ),
1376 array('ID' => $propertyIdList),
1377 array('USE_PROPERTY_ID' => 'Y', 'PROPERTY_FIELDS' => $propertyFields)
1378 );
1379 }
1380
1381 if ($needDiscountCache)
1382 {
1383 foreach ($itemIdsList as $id)
1385 unset($id);
1386 }
1387
1388 if (!$needProperties)
1389 {
1390 foreach ($itemIdsList as $id)
1391 $items[$id]['PROPERTIES'] = array();
1392 unset($id);
1393 }
1394 else
1395 {
1396 foreach ($itemIdsList as $id)
1397 {
1398 if (empty($items[$id]['PROPERTIES']))
1399 continue;
1400 foreach (array_keys($items[$id]['PROPERTIES']) as $index)
1401 {
1402 $propertyId = $items[$id]['PROPERTIES'][$index]['ID'];
1403 if (!isset($yandexNeedPropertyIds[$propertyId]))
1404 unset($items[$id]['PROPERTIES'][$index]);
1405 }
1406 unset($propertyId, $index);
1407 }
1408 unset($id);
1409 }
1410 }
1411
1412 if ($needDiscountCache)
1413 {
1415 \CCatalogDiscount::SetDiscountProductCache($itemIdsList, array('IBLOCK_ID' => $IBLOCK_ID, 'GET_BY_ID' => 'Y'));
1416 }
1417
1418 if (!empty($skuIdsList))
1419 {
1420 $offerPropertyFilter = array();
1421 if ($needProperties || $needDiscountCache)
1422 {
1423 if (!empty($propertyIdList))
1424 $offerPropertyFilter = array('ID' => $propertyIdList);
1425 }
1426
1427 $offers = \CCatalogSku::getOffersList(
1428 $skuIdsList,
1429 $IBLOCK_ID,
1430 $offersFilter,
1431 $offerFields,
1432 $offerPropertyFilter,
1433 array('USE_PROPERTY_ID' => 'Y', 'PROPERTY_FIELDS' => $propertyFields)
1434 );
1435 unset($offerPropertyFilter);
1436
1437 if (!empty($offers))
1438 {
1439 $offerLinks = array();
1440 $offerIdsList = array();
1441 $parentsUrl = array();
1442 foreach (array_keys($offers) as $productId)
1443 {
1444 unset($skuIdsList[$productId]);
1445 $items[$productId]['OFFERS'] = array();
1446 $parentsUrl[$productId] = $items[$productId]['DETAIL_PAGE_URL'];
1447 foreach (array_keys($offers[$productId]) as $offerId)
1448 {
1449 $productOffer = $offers[$productId][$offerId];
1450 $productOffer['VAT_ID'] = (int)$productOffer['VAT_ID'];
1451 if ($productOffer['VAT_ID'] == 0)
1452 $productOffer['VAT_ID'] = $offersCatalog['VAT_ID'];
1453
1454 $productOffer['PRICES'] = array();
1455 if ($needDiscountCache)
1456 \CCatalogDiscount::SetProductPropertiesCache($offerId, $productOffer['PROPERTIES']);
1457 if (!$needProperties)
1458 {
1459 $productOffer['PROPERTIES'] = array();
1460 }
1461 else
1462 {
1463 if (!empty($productOffer['PROPERTIES']))
1464 {
1465 foreach (array_keys($productOffer['PROPERTIES']) as $index)
1466 {
1467 $propertyId = $productOffer['PROPERTIES'][$index]['ID'];
1468 if (!isset($yandexNeedPropertyIds[$propertyId]))
1469 unset($productOffer['PROPERTIES'][$index]);
1470 }
1471 unset($propertyId, $index);
1472 }
1473 }
1474 $items[$productId]['OFFERS'][$offerId] = $productOffer;
1475 unset($productOffer);
1476
1477 $offerLinks[$offerId] = &$items[$productId]['OFFERS'][$offerId];
1478 $offerIdsList[$offerId] = $offerId;
1479 }
1480 unset($offerId);
1481 }
1482 if (!empty($offerIdsList))
1483 {
1484 yandexPrepareItems($offerLinks, $parentsUrl, $itemOptions);
1485
1486 foreach (array_chunk($offerIdsList, 500) as $pageIds)
1487 {
1488 if ($needDiscountCache)
1489 {
1492 $pageIds,
1493 array('IBLOCK_ID' => $arCatalog['IBLOCK_ID'], 'GET_BY_ID' => 'Y')
1494 );
1495 }
1496
1497 // load vat cache
1499 unset($vatList);
1500
1501 $priceFilter = [
1502 '@PRODUCT_ID' => $pageIds,
1503 [
1504 'LOGIC' => 'OR',
1505 '<=QUANTITY_FROM' => 1,
1506 '=QUANTITY_FROM' => null
1507 ],
1508 [
1509 'LOGIC' => 'OR',
1510 '>=QUANTITY_TO' => 1,
1511 '=QUANTITY_TO' => null
1512 ]
1513 ];
1514 if ($selectedPriceType > 0)
1515 $priceFilter['=CATALOG_GROUP_ID'] = $selectedPriceType;
1516 else
1517 $priceFilter['@CATALOG_GROUP_ID'] = $priceTypeList;
1518
1519 $iterator = Catalog\PriceTable::getList([
1520 'select' => ['ID', 'PRODUCT_ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY'],
1521 'filter' => $priceFilter
1522 ]);
1523
1524 while ($price = $iterator->fetch())
1525 {
1526 $id = (int)$price['PRODUCT_ID'];
1527 $priceTypeId = (int)$price['CATALOG_GROUP_ID'];
1528 $offerLinks[$id]['PRICES'][$priceTypeId] = $price;
1529 unset($priceTypeId, $id);
1530 }
1531 unset($price, $iterator);
1532
1533 if ($saleDiscountOnly)
1534 {
1536 $pageIds,
1538 );
1539 }
1540 }
1541 unset($pageIds);
1542 }
1543 unset($parentsUrl, $offerIdsList, $offerLinks);
1544 }
1545 unset($offers);
1546
1547 if (!empty($skuIdsList))
1548 {
1549 foreach ($skuIdsList as $id)
1550 {
1551 unset($items[$id]);
1552 unset($itemIdsList[$id]);
1553 }
1554 unset($id);
1555 }
1556 }
1557
1558 if (!empty($simpleIdsList))
1559 {
1560 foreach (array_chunk($simpleIdsList, 500) as $pageIds)
1561 {
1562 // load vat cache
1564 unset($vatList);
1565
1566 $priceFilter = [
1567 '@PRODUCT_ID' => $pageIds,
1568 [
1569 'LOGIC' => 'OR',
1570 '<=QUANTITY_FROM' => 1,
1571 '=QUANTITY_FROM' => null
1572 ],
1573 [
1574 'LOGIC' => 'OR',
1575 '>=QUANTITY_TO' => 1,
1576 '=QUANTITY_TO' => null
1577 ]
1578 ];
1579 if ($selectedPriceType > 0)
1580 $priceFilter['=CATALOG_GROUP_ID'] = $selectedPriceType;
1581 else
1582 $priceFilter['@CATALOG_GROUP_ID'] = $priceTypeList;
1583
1584 $iterator = Catalog\PriceTable::getList([
1585 'select' => ['ID', 'PRODUCT_ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY'],
1586 'filter' => $priceFilter
1587 ]);
1588
1589 while ($price = $iterator->fetch())
1590 {
1591 $id = (int)$price['PRODUCT_ID'];
1592 $priceTypeId = (int)$price['CATALOG_GROUP_ID'];
1593 $items[$id]['PRICES'][$priceTypeId] = $price;
1594 unset($priceTypeId, $id);
1595 }
1596 unset($price, $iterator);
1597
1598 if ($saleDiscountOnly)
1599 {
1601 $pageIds,
1603 );
1604 }
1605 }
1606 unset($pageIds);
1607 }
1608 }
1609
1610 $itemsContent = '';
1611 if (!empty($items))
1612 {
1613 foreach ($itemIdsList as $id)
1614 {
1615 $CUR_ELEMENT_ID = $id;
1616
1617 $row = $items[$id];
1618
1619 if (!empty($row['SECTIONS']))
1620 {
1621 foreach ($row['SECTIONS'] as $sectionId)
1622 {
1623 if (!isset($arAvailGroups[$sectionId]))
1624 continue;
1625 $row['CATEGORY_ID'] = $sectionId;
1626 }
1627 unset($sectionId);
1628 }
1629 else
1630 {
1631 $boolNeedRootSection = true;
1632 $row['CATEGORY_ID'] = $intMaxSectionID;
1633 }
1634 if (!isset($row['CATEGORY_ID']))
1635 continue;
1636
1637 if ($row['TYPE'] == Catalog\ProductTable::TYPE_SKU && !empty($row['OFFERS']))
1638 {
1639 $minOfferId = null;
1640 $minOfferPrice = null;
1641
1642 foreach (array_keys($row['OFFERS']) as $offerId)
1643 {
1644 if (empty($row['OFFERS'][$offerId]['PRICES']))
1645 {
1646 unset($row['OFFERS'][$offerId]);
1647 continue;
1648 }
1649
1650 $fullPrice = 0;
1651 $minPrice = 0;
1652 $minPriceCurrency = '';
1653
1654 $calculatePrice = CCatalogProduct::GetOptimalPrice(
1655 $row['OFFERS'][$offerId]['ID'],
1656 1,
1657 array(2),
1658 'N',
1659 $row['OFFERS'][$offerId]['PRICES'],
1660 $site['LID'],
1661 array()
1662 );
1663
1664 if (!empty($calculatePrice))
1665 {
1666 $minPrice = $calculatePrice['RESULT_PRICE']['DISCOUNT_PRICE'];
1667 $fullPrice = $calculatePrice['RESULT_PRICE']['BASE_PRICE'];
1668 $minPriceCurrency = $calculatePrice['RESULT_PRICE']['CURRENCY'];
1669 }
1670 unset($calculatePrice);
1671 if ($minPrice <= 0)
1672 {
1673 unset($row['OFFERS'][$offerId]);
1674 continue;
1675 }
1676 $row['OFFERS'][$offerId]['RESULT_PRICE'] = array(
1677 'MIN_PRICE' => $minPrice,
1678 'FULL_PRICE' => $fullPrice,
1679 'CURRENCY' => $minPriceCurrency
1680 );
1681 if ($minOfferPrice === null || $minOfferPrice > $minPrice)
1682 {
1683 $minOfferId = $offerId;
1684 $minOfferPrice = $minPrice;
1685 }
1686 }
1687 unset($offerId);
1688
1689 if ($arSKUExport['SKU_EXPORT_COND'] == YANDEX_SKU_EXPORT_MIN_PRICE)
1690 {
1691 if ($minOfferId === null)
1692 $row['OFFERS'] = array();
1693 else
1694 $row['OFFERS'] = array($minOfferId => $row['OFFERS'][$minOfferId]);
1695 }
1696 if (empty($row['OFFERS']))
1697 continue;
1698
1699 foreach ($row['OFFERS'] as $offer)
1700 {
1701 $available = ' available="'.($offer['AVAILABLE'] == 'Y' ? 'true' : 'false').'"';
1702 $itemsContent .= '<offer id="'.$offer['ID'].'"'.$productFormat.$available.">\n";
1703 unset($available);
1704
1705 $referer = '';
1706 if (!$disableReferers)
1707 $referer = $offerUrlConfig['REFERRER_SEPARATOR'].'r1=<?=$strReferer1; ?>&amp;r2=<?=$strReferer2; ?>';
1708
1709 $itemsContent .= "<url>".($offerUrlConfig['USE_DOMAIN'] ? $usedProtocol.$site['SERVER_NAME'] : '').htmlspecialcharsbx($offer['DETAIL_PAGE_URL']).$referer."</url>\n";
1710 unset($referer);
1711
1712 $minPrice = $offer['RESULT_PRICE']['MIN_PRICE'];
1713 $fullPrice = $offer['RESULT_PRICE']['FULL_PRICE'];
1714 $itemsContent .= "<price>".$minPrice."</price>\n";
1715 if ($minPrice < $fullPrice)
1716 $itemsContent .= "<oldprice>".$fullPrice."</oldprice>\n";
1717 $itemsContent .= "<currencyId>".$offer['RESULT_PRICE']['CURRENCY']."</currencyId>\n";
1718 if ($vatExport && isset($vatList[$offer['VAT_ID']]))
1719 $itemsContent .= "<vat>".$vatList[$offer['VAT_ID']]."</vat>\n";
1720
1721 $itemsContent .= "<categoryId>".$row['CATEGORY_ID']."</categoryId>\n";
1722
1723 $picture = (!empty($offer['PICTURE']) ? $offer['PICTURE'] : $row['PICTURE']);
1724 if (!empty($picture))
1725 $itemsContent .= "<picture>".$picture."</picture>\n";
1726 unset($picture);
1727
1728 $y = 0;
1729 foreach ($arYandexFields as $key)
1730 {
1731 switch ($key)
1732 {
1733 case 'name':
1734 if ($yandexFormat == 'vendor.model' || $yandexFormat == 'artist.title')
1735 continue;
1736
1737 $itemsContent .= "<name>".yandex_text2xml($offer['NAME'], $itemOptions)."</name>\n";
1738 break;
1739 case 'description':
1740 $itemsContent .= "<description>".
1741 ($offer['DESCRIPTION'] !== '' ? $offer['DESCRIPTION'] : $row['DESCRIPTION']).
1742 "</description>\n";
1743 break;
1744 case 'param':
1746 {
1747 foreach ($parametricFields as $paramKey => $prop_id)
1748 {
1749 $value = yandex_get_value(
1750 $offer,
1751 'PARAM_'.$paramKey,
1752 $prop_id,
1756 );
1757 if ($value == '')
1758 {
1759 $value = yandex_get_value(
1760 $row,
1761 'PARAM_'.$paramKey,
1762 $prop_id,
1766 );
1767 }
1768 if ($value != '')
1769 $itemsContent .= $value."\n";
1770 unset($value);
1771 }
1772 unset($paramKey, $prop_id);
1773 }
1774 break;
1775 case 'model':
1776 case 'title':
1777 if (!$fieldsExist || !isset($fields[$key]))
1778 {
1779 if (
1780 $key == 'model' && $yandexFormat == 'vendor.model'
1781 ||
1782 $key == 'title' && $yandexFormat == 'artist.title'
1783 )
1784 $itemsContent .= "<".$key.">".yandex_text2xml($offer['NAME'], $itemOptions)."</".$key.">\n";
1785 }
1786 else
1787 {
1788 $value = yandex_get_value(
1789 $offer,
1790 $key,
1791 $fields[$key],
1795 );
1796 if ($value == '')
1797 {
1798 $value = yandex_get_value(
1799 $row,
1800 $key,
1801 $fields[$key],
1805 );
1806 }
1807 if ($value != '')
1808 $itemsContent .= $value."\n";
1809 unset($value);
1810 }
1811 break;
1812 case 'year':
1813 default:
1814 if ($key == 'year')
1815 {
1816 $y++;
1817 if ($yandexFormat == 'artist.title')
1818 {
1819 if ($y == 1)
1820 continue;
1821 }
1822 else
1823 {
1824 if ($y > 1)
1825 continue;
1826 }
1827 }
1828 if ($fieldsExist && isset($fields[$key]))
1829 {
1830 $value = yandex_get_value(
1831 $offer,
1832 $key,
1833 $fields[$key],
1837 );
1838 if ($value == '')
1839 {
1840 $value = yandex_get_value(
1841 $row,
1842 $key,
1843 $fields[$key],
1847 );
1848 }
1849 if ($value != '')
1850 $itemsContent .= $value."\n";
1851 unset($value);
1852 }
1853 }
1854 }
1855
1856 $itemsContent .= '</offer>'."\n";
1857 }
1858 unset($offer);
1859 }
1860 elseif (isset($simpleIdsList[$id]) && !empty($row['PRICES']))
1861 {
1862 $row['VAT_ID'] = (int)$row['VAT_ID'];
1863 if ($row['VAT_ID'] == 0)
1864 $row['VAT_ID'] = $arCatalog['VAT_ID'];
1865
1866 $fullPrice = 0;
1867 $minPrice = 0;
1868 $minPriceCurrency = '';
1869
1870 $calculatePrice = CCatalogProduct::GetOptimalPrice(
1871 $row['ID'],
1872 1,
1873 array(2),
1874 'N',
1875 $row['PRICES'],
1876 $site['LID'],
1877 array()
1878 );
1879
1880 if (!empty($calculatePrice))
1881 {
1882 $minPrice = $calculatePrice['RESULT_PRICE']['DISCOUNT_PRICE'];
1883 $fullPrice = $calculatePrice['RESULT_PRICE']['BASE_PRICE'];
1884 $minPriceCurrency = $calculatePrice['RESULT_PRICE']['CURRENCY'];
1885 }
1886 unset($calculatePrice);
1887
1888 if ($minPrice <= 0)
1889 continue;
1890
1891 $available = ' available="'.($row['AVAILABLE'] == 'Y' ? 'true' : 'false').'"';
1892 $itemsContent .= '<offer id="'.$row['ID'].'"'.$productFormat.$available.">\n";
1893 unset($available);
1894
1895 $referer = '';
1896 if (!$disableReferers)
1897 $referer = $itemUrlConfig['REFERRER_SEPARATOR'].'r1=<?=$strReferer1; ?>&amp;r2=<?=$strReferer2; ?>';
1898
1899 $itemsContent .= "<url>".($itemUrlConfig['USE_DOMAIN'] ? $usedProtocol.$site['SERVER_NAME'] : '').htmlspecialcharsbx($row['DETAIL_PAGE_URL']).$referer."</url>\n";
1900 unset($referer);
1901
1902 $itemsContent .= "<price>".$minPrice."</price>\n";
1903 if ($minPrice < $fullPrice)
1904 $itemsContent .= "<oldprice>".$fullPrice."</oldprice>\n";
1905 $itemsContent .= "<currencyId>".$minPriceCurrency."</currencyId>\n";
1906 if ($vatExport && isset($vatList[$row['VAT_ID']]))
1907 $itemsContent .= "<vat>".$vatList[$row['VAT_ID']]."</vat>\n";
1908
1909 $itemsContent .= "<categoryId>".$row['CATEGORY_ID']."</categoryId>\n";
1910
1911 if (!empty($row['PICTURE']))
1912 $itemsContent .= "<picture>".$row['PICTURE']."</picture>\n";
1913
1914 $y = 0;
1915 foreach ($arYandexFields as $key)
1916 {
1917 switch ($key)
1918 {
1919 case 'name':
1920 if ($yandexFormat == 'vendor.model' || $yandexFormat == 'artist.title')
1921 continue;
1922
1923 $itemsContent .= "<name>".yandex_text2xml($row['NAME'], $itemOptions)."</name>\n";
1924 break;
1925 case 'description':
1926 $itemsContent .= "<description>".$row['DESCRIPTION']."</description>\n";
1927 break;
1928 case 'param':
1930 {
1931 foreach ($parametricFields as $paramKey => $prop_id)
1932 {
1933 $value = yandex_get_value(
1934 $row,
1935 'PARAM_'.$paramKey,
1936 $prop_id,
1940 );
1941 if ($value != '')
1942 $itemsContent .= $value."\n";
1943 unset($value);
1944 }
1945 unset($paramKey, $prop_id);
1946 }
1947 break;
1948 case 'model':
1949 case 'title':
1950 if (!$fieldsExist || !isset($fields[$key]))
1951 {
1952 if (
1953 $key == 'model' && $yandexFormat == 'vendor.model'
1954 ||
1955 $key == 'title' && $yandexFormat == 'artist.title'
1956 )
1957 $itemsContent .= "<".$key.">".yandex_text2xml($row['NAME'], $itemOptions)."</".$key.">\n";
1958 }
1959 else
1960 {
1961 $value = yandex_get_value(
1962 $row,
1963 $key,
1964 $fields[$key],
1968 );
1969 if ($value != '')
1970 $itemsContent .= $value."\n";
1971 unset($value);
1972 }
1973 break;
1974 case 'year':
1975 default:
1976 if ($key == 'year')
1977 {
1978 $y++;
1979 if ($yandexFormat == 'artist.title')
1980 {
1981 if ($y == 1)
1982 continue;
1983 }
1984 else
1985 {
1986 if ($y > 1)
1987 continue;
1988 }
1989 }
1990 if ($fieldsExist && isset($fields[$key]))
1991 {
1992 $value = yandex_get_value(
1993 $row,
1994 $key,
1995 $fields[$key],
1999 );
2000 if ($value != '')
2001 $itemsContent .= $value."\n";
2002 unset($value);
2003 }
2004 }
2005 }
2006
2007 $itemsContent .= "</offer>\n";
2008 }
2009
2010 unset($row);
2011
2012 if ($MAX_EXECUTION_TIME > 0 && (microtime(true) - START_EXEC_TIME) >= $MAX_EXECUTION_TIME)
2013 break;
2014 }
2015 unset($id);
2016
2018 'PRODUCT' => true,
2019 'SECTIONS' => true,
2020 'SECTION_CHAINS' => true,
2021 'PROPERTIES' => true
2022 ));
2025 }
2026
2027 if ($itemsContent !== '')
2028 fwrite($itemsFile, $itemsContent);
2029 unset($itemsContent);
2030
2031 unset($simpleIdsList, $skuIdsList);
2032 unset($items, $itemIdsList);
2033 }
2034 while ($MAX_EXECUTION_TIME == 0 && $existItems);
2035}
2036
2037if (empty($arRunErrors))
2038{
2039 if (is_resource($itemsFile))
2040 @fclose($itemsFile);
2041 unset($itemsFile);
2042}
2043
2044if (empty($arRunErrors))
2045{
2046 if ($MAX_EXECUTION_TIME == 0)
2047 $finalExport = true;
2048 if ($finalExport)
2049 {
2050 $process = true;
2051 $content = '';
2052 if ($boolNeedRootSection)
2053 $content .= '<category id="'.$intMaxSectionID.'">'.yandex_text2xml(GetMessage('YANDEX_ROOT_DIRECTORY'), $itemOptions).'</category>'."\n";
2054 $content .= "</categories>\n";
2055 $content .= "<offers>\n";
2056
2057 $items = file_get_contents($_SERVER["DOCUMENT_ROOT"].$itemFileName);
2058 if ($items === false)
2059 {
2060 $arRunErrors[] = GetMessage('YANDEX_STEP_ERR_DATA_FILE_NOT_READ');
2061 $process = false;
2062 }
2063
2064 if ($process)
2065 {
2066 $content .= $items;
2067 unset($items);
2068 $content .= "</offers>\n"."</shop>\n"."</yml_catalog>\n";
2069
2070 if (file_put_contents($_SERVER["DOCUMENT_ROOT"].$sectionFileName, $content, FILE_APPEND) === false)
2071 {
2072 $arRunErrors[] = str_replace('#FILE#', $sectionFileName, GetMessage('YANDEX_ERR_SETUP_FILE_WRITE'));
2073 $process = false;
2074 }
2075 }
2076 if ($process)
2077 {
2078 unlink($_SERVER["DOCUMENT_ROOT"].$itemFileName);
2079
2080 if (file_exists($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME))
2081 {
2082 if (!unlink($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME))
2083 {
2084 $arRunErrors[] = str_replace('#FILE#', $SETUP_FILE_NAME, GetMessage('BX_CATALOG_EXPORT_YANDEX_ERR_UNLINK_FILE'));
2085 $process = false;
2086 }
2087 }
2088 }
2089 if ($process)
2090 {
2091 if (!rename($_SERVER["DOCUMENT_ROOT"].$sectionFileName, $_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME))
2092 {
2093 $arRunErrors[] = str_replace('#FILE#', $sectionFileName, GetMessage('BX_CATALOG_EXPORT_YANDEX_ERR_UNLINK_FILE'));
2094 }
2095 }
2096 unset($process);
2097 }
2098}
2099
2101if ($saleIncluded)
2102 Sale\DiscountCouponsManager::unFreezeCouponStorage();
2103
2104if (!empty($arRunErrors))
2105 $strExportErrorMessage = implode('<br />',$arRunErrors);
2106
2108{
2109 if (isset($USER_TMP))
2110 {
2111 $USER = $USER_TMP;
2112 unset($USER_TMP);
2113 }
2114}
const YANDEX_SKU_EXPORT_PROP
Определения include.php:21
const YANDEX_SKU_EXPORT_ALL
Определения include.php:19
const BX_CATALOG_FILENAME_REG
Определения include.php:51
const YANDEX_SKU_EXPORT_MIN_PRICE
Определения include.php:20
if($USER->IsAuthorized()) if(!function_exists("yandex_replace_special")) if(!function_exists("yandex_text2xml")) $usedProtocol
Определения yandex.php:58
static preloadPriceData(array $productIds, array $catalogGroups)
Определения discountmanager.php:562
static setConfig(array $config)
Определения calculation.php:46
const TYPE_ELEMENT
Определения propertytable.php:68
const TYPE_FILE
Определения propertytable.php:67
const TYPE_LIST
Определения propertytable.php:70
const TYPE_SECTION
Определения propertytable.php:69
Определения loader.php:13
static convertEncoding($data, $charsetFrom, $charsetTo)
Определения encoding.php:17
static SetDiscountProductCache($arItem, $arParams=array())
Определения discount.php:3986
static SetProductSectionsCache($arItemIDs)
Определения discount.php:4147
static ClearDiscountCache($arTypes)
Определения discount.php:4224
static SetProductPropertiesCache($intProductID, $arProps)
Определения discount.php:4185
static Disable()
Определения discount_save.php:38
static Enable()
Определения discount_save.php:33
static GetByID($ID)
Определения catalog.php:281
static IsUserExists()
Определения catalog.php:1812
static ClearCache()
Определения product.php:171
static GetOptimalPrice($intProductID, $quantity=1, $arUserGroups=array(), $renewal="N", $priceList=array(), $siteID=false, $arDiscountCoupons=false)
Определения product.php:973
static ConvertCurrency($valSum, $curFrom, $curTo, $valDate="")
Определения currency_rate.php:393
static GetByID($ID)
Определения iblock.php:813
static GetNavChain($IBLOCK_ID, $SECTION_ID, $arSelect=array(), $arrayResult=false)
Определения iblocksection.php:204
static GetVATDataByIDList(array $list)
Определения product.php:204
const TYPE_OFFERS
Определения catalog_sku.php:22
static GetInfoByProductIBlock($intIBlockID)
Определения catalog_sku.php:141
const TYPE_PRODUCT
Определения catalog_sku.php:21
const TYPE_FULL
Определения catalog_sku.php:23
const TYPE_CATALOG
Определения catalog_sku.php:20
static GetFileArray($fileId, $uploadDir=false)
Определения file.php:1207
static GetList($arOrder=array("SORT"=>"ASC"), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения iblockelement.php:658
static SetCatalogDiscountCache($arCatalogGroups, $arUserGroups, $siteId=false)
Определения comp_pricetools.php:124
static GetList($arOrder=array("SORT"=>"ASC"), $arFilter=array(), $bIncCnt=false, $arSelect=array(), $arNavStartParams=false)
Определения iblocksection.php:14
static isValidField(string $field)
Определения querybuilder.php:95
$options
Определения commerceml2.php:49
$content
Определения commerceml.php:144
$arValues
Определения component_props.php:25
else $SETUP_FILE_NAME
Определения ebay_mip_run.php:56
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
$filter
Определения iblock_catalog_list.php:54
const BX_CAT_CRON
Определения cron_frame.php:16
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
if(! $ar_profile) $strFile
Определения cron_frame.php:59
if($ar_profile["DEFAULT_PROFILE"] !='Y') $firstStep
Определения cron_frame.php:80
$IBLOCK_ID
Определения csv_new_run.php:168
$SETUP_VARS_LIST
Определения csv_new_run.php:37
$arRunErrors
Определения csv_new_run.php:129
global $USER
Определения csv_new_run.php:40
$strExportErrorMessage
Определения csv_new_run.php:128
$bTmpUserCreated
Определения csv_new_run.php:41
$pageSize
Определения csv_new_run.php:34
$navParams
Определения csv_new_run.php:35
$MAX_EXECUTION_TIME
Определения csv_new_run.php:16
$INTERNAL_VARS_LIST
Определения csv_new_run.php:38
const LANG_CHARSET
Определения include.php:65
const START_EXEC_TIME
Определения start.php:12
CheckSerializedData($str, $max_depth=200)
Определения tools.php:4949
CheckDirPath($path)
Определения tools.php:2707
htmlspecialcharsEx($str)
Определения tools.php:2685
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
Rel2Abs($curdir, $relpath)
Определения tools.php:3297
GetMessage($name, $aReplace=null)
Определения tools.php:3397
TruncateText($strText, $intLen)
Определения tools.php:2185
$value
Определения Param.php:39
string $sectionId
Определения columnfields.php:71
Определения base32.php:2
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$text
Определения template_pdf.php:79
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$currency
Определения template.php:266
$items
Определения template.php:224
$val
Определения options.php:1793
$CURRENCY
Определения result.php:6
$arOfferIBlock
Определения yandex_detail.php:76
$arOffersSelectKeys
Определения yandex_detail.php:86
if(!empty($arOffers['IBLOCK_ID'])) $arCondSelectProp
Определения yandex_detail.php:115
$intOfferIBlockID
Определения yandex_detail.php:77
$arSelectOfferProps
Определения yandex_detail.php:78
$arOffers
Определения yandex_detail.php:75
$vatRates
Определения yandex_detail.php:156
$boolOffers
Определения yandex_detail.php:74
$arSelectedPropTypes
Определения yandex_detail.php:79
$itemUrlConfig
Определения yandex_run.php:562
$CHECK_PERMISSIONS
Определения yandex_run.php:41
if(empty($arRunErrors)) $itemsFile
Определения yandex_run.php:985
$rsProps
Определения yandex_run.php:584
$propertyFields
Определения yandex_run.php:558
$arSections
Определения yandex_run.php:805
$iterator
Определения yandex_run.php:610
$db_iblock
Определения yandex_run.php:572
$arSKUExport
Определения yandex_run.php:672
$formatList
Определения yandex_run.php:85
$filterAvailable
Определения yandex_run.php:900
$yandexNeedPropertyIds
Определения yandex_run.php:537
if(!CCatalog::IsUserExists()) $saleIncluded
Определения yandex_run.php:66
$yandexFormat
Определения yandex_run.php:495
$SITE_ID
Определения yandex_run.php:607
$parametricFieldsExist
Определения yandex_run.php:504
if($vatExport) $itemOptions
Определения yandex_run.php:952
$arYandexFields
Определения yandex_run.php:71
$ar_iblock['DETAIL_PAGE_URL']
Определения yandex_run.php:600
$descrField
Определения yandex_run.php:556
$arCatalog
Определения yandex_run.php:674
if(!empty($XML_DATA['PRICE'])) $priceTypeList
Определения yandex_run.php:872
else $permissionFilter
Определения yandex_run.php:45
$parametricFields
Определения yandex_run.php:502
$offerUrlConfig
Определения yandex_run.php:566
$site
Определения yandex_run.php:614
if(empty($arRunErrors)) $arUserTypeFormat
Определения yandex_run.php:788
if( $fieldsExist) if($parametricFieldsExist) $commonFields
Определения yandex_run.php:551
$fields
Определения yandex_run.php:501
if(!empty( $arOffers[ 'IBLOCK_ID'])) if($boolOffers) $propertyIdList
Определения yandex_run.php:778
$exportCharset
Определения yandex_run.php:902
$fieldsExist
Определения yandex_run.php:503
if( $site[ 'SERVER_NAME']==='') if($site['SERVER_NAME']==='') $arProperties
Определения yandex_run.php:644
$BASE_CURRENCY
Определения yandex_run.php:987
$COMPANY_NAME
Определения yandex_run.php:606
$vatExport
Определения yandex_run.php:920
$SETUP_SERVER_NAME
Определения yandex_run.php:605
$productFormat
Определения yandex_run.php:499
$itemFileName
Определения yandex_run.php:962
$sectionFileName
Определения yandex_run.php:961
$bAllSections
Определения yandex_run.php:804
if(empty($arRunErrors)) $selectedPriceType
Определения yandex_run.php:850
$offersCatalog
Определения yandex_run.php:652
if( $fieldsExist) if($parametricFieldsExist) $needProperties
Определения yandex_run.php:536
$vatList
Определения yandex_run.php:916
$disableReferers
Определения yandex_run.php:901
$vatExportSettings
Определения yandex_run.php:906
yandex_text2xml($text, $bHSC=false, $bDblQuote=false)
Определения yandex_simple_run.php:40
if( $USER->IsAuthorized()) yandex_replace_special($arg)
Определения yandex_simple_run.php:32