1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
csv_new_run.php
См. документацию.
1<?php
2//<title>CSV (new)</title>
7
24
25use Bitrix\Main,
28
29IncludeModuleLangFile($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/catalog/import_setup_templ.php');
30$startImportExecTime = microtime(true);
31
32global $USER;
36{
37 $bTmpUserCreated = true;
38 if (isset($USER))
39 $USER_TMP = $USER;
40 $USER = new CUser();
41}
42
45
46global
58
69
82
83$NUM_CATALOG_LEVELS = intval(COption::GetOptionString("catalog", "num_catalog_levels"));
84
86if ($max_execution_time <= 0)
88if (defined('BX_CAT_CRON') && true == BX_CAT_CRON)
90
91if (defined("CATALOG_LOAD_NO_STEP") && CATALOG_LOAD_NO_STEP)
93
94$separateSku = (string)Main\Config\Option::get('catalog', 'show_catalog_tab_with_offers') === 'Y';
95
97
99
100if (!function_exists('CSVCheckTimeout'))
101{
102 function CSVCheckTimeout($max_execution_time)
103 {
104 return ($max_execution_time <= 0) || (microtime(true)-START_EXEC_TIME <= (2*$max_execution_time/3));
105 }
106}
107
109
110if ($URL_DATA_FILE <> '')
111{
112 $URL_DATA_FILE = Rel2Abs("/", $URL_DATA_FILE);
113 if (file_exists($_SERVER["DOCUMENT_ROOT"].$URL_DATA_FILE) && is_file($_SERVER["DOCUMENT_ROOT"].$URL_DATA_FILE))
114 $DATA_FILE_NAME = $URL_DATA_FILE;
115}
116
117if ($DATA_FILE_NAME == '')
118 $strImportErrorMessage .= GetMessage("CATI_NO_DATA_FILE")."<br>";
119
121if ($IBLOCK_ID <= 0)
122{
123 $strImportErrorMessage .= GetMessage("CATI_NO_IBLOCK")."<br>";
124}
125else
126{
127 $arIBlock = CIBlock::GetArrayByID($IBLOCK_ID);
128 if (false === $arIBlock)
129 {
130 $strImportErrorMessage .= GetMessage("CATI_NO_IBLOCK")."<br>";
131 }
132}
133
134if ('' == $strImportErrorMessage)
135{
136 $bWorkflow = CModule::IncludeModule("workflow") && ($arIBlock["WORKFLOW"] != "N");
137
138 $bIBlockIsCatalog = false;
139 $arSku = false;
140 $rsCatalogs = CCatalog::GetList(
141 array(),
142 array('IBLOCK_ID' => $IBLOCK_ID),
143 false,
144 false,
145 array('IBLOCK_ID', 'PRODUCT_IBLOCK_ID', 'SKU_PROPERTY_ID')
146 );
147 if ($arCatalog = $rsCatalogs->Fetch())
148 {
149 $bIBlockIsCatalog = true;
150 $arCatalog['IBLOCK_ID'] = (int)$arCatalog['IBLOCK_ID'];
151 $arCatalog['PRODUCT_IBLOCK_ID'] = (int)$arCatalog['PRODUCT_IBLOCK_ID'];
152 $arCatalog['SKU_PROPERTY_ID'] = (int)$arCatalog['SKU_PROPERTY_ID'];
153 if (0 < $arCatalog['PRODUCT_IBLOCK_ID'] && 0 < $arCatalog['SKU_PROPERTY_ID'])
154 {
156 }
157 }
158
159 $csvFile = new CCSVData();
160 $csvFile->LoadFile($_SERVER["DOCUMENT_ROOT"].$DATA_FILE_NAME);
161
162 if ($fields_type!="F" && $fields_type!="R")
163 $strImportErrorMessage .= GetMessage("CATI_NO_FILE_FORMAT")."<br>";
164}
165
166if ('' == $strImportErrorMessage)
167{
168 $arDataFileFields = array();
169 $fields_type = (($fields_type=="F") ? "F" : "R" );
170
171 $csvFile->SetFieldsType($fields_type);
172
173 if ($fields_type == "R")
174 {
175 $first_names_r = (($first_names_r=="Y") ? "Y" : "N" );
176 $csvFile->SetFirstHeader(($first_names_r=="Y") ? true : false);
177
178 $delimiter_r_char = "";
179 switch ($delimiter_r)
180 {
181 case "TAB":
182 $delimiter_r_char = "\t";
183 break;
184 case "ZPT":
185 $delimiter_r_char = ",";
186 break;
187 case "SPS":
188 $delimiter_r_char = " ";
189 break;
190 case "OTR":
191 $delimiter_r_char = mb_substr($delimiter_other_r, 0, 1);
192 break;
193 case "TZP":
194 $delimiter_r_char = ";";
195 break;
196 }
197
198 if (mb_strlen($delimiter_r_char) != 1)
199 $strImportErrorMessage .= GetMessage("CATI_NO_DELIMITER")."<br>";
200
201 if ('' == $strImportErrorMessage)
202 $csvFile->SetDelimiter($delimiter_r_char);
203 }
204 else
205 {
206 $first_names_f = (($first_names_f=="Y") ? "Y" : "N" );
207 $csvFile->SetFirstHeader(($first_names_f=="Y") ? true : false);
208
209 if ($metki_f == '')
210 $strImportErrorMessage .= GetMessage("CATI_NO_METKI")."<br>";
211
212 if ('' == $strImportErrorMessage)
213 {
214 $arMetkiTmp = preg_split("/[\D]/i", $metki_f);
215
216 $arMetki = array();
217 for ($i = 0, $intCount = count($arMetkiTmp); $i < $intCount; $i++)
218 {
219 if (intval($arMetkiTmp[$i]) > 0)
220 {
221 $arMetki[] = intval($arMetkiTmp[$i]);
222 }
223 }
224
225 if (!is_array($arMetki) || count($arMetki)<1)
226 $strImportErrorMessage .= GetMessage("CATI_NO_METKI")."<br>";
227
228 if ('' == $strImportErrorMessage)
229 $csvFile->SetWidthMap($arMetki);
230 }
231 }
232
233 if ('' == $strImportErrorMessage)
234 {
235 $bFirstHeaderTmp = $csvFile->GetFirstHeader();
236 $csvFile->SetFirstHeader(false);
237 if ($arRes = $csvFile->Fetch())
238 {
239 for ($i = 0, $intCount = count($arRes); $i < $intCount; $i++)
240 {
241 $arDataFileFields[$i] = $arRes[$i];
242 }
243 }
244 else
245 {
246 $strImportErrorMessage .= GetMessage("CATI_NO_DATA")."<br>";
247 }
248 global $NUM_FIELDS;
249 $NUM_FIELDS = count($arDataFileFields);
250 }
251}
252
253if ('' == $strImportErrorMessage)
254{
255 $bFieldsPres = false;
256 for ($i = 0; $i < $NUM_FIELDS; $i++)
257 {
258 if (${"field_".$i} <> '')
259 {
260 $bFieldsPres = true;
261 break;
262 }
263 }
264 if (!$bFieldsPres)
265 $strImportErrorMessage .= GetMessage("CATI_NO_FIELDS")."<br>";
266}
267
268if ('' == $strImportErrorMessage)
269{
270 $USE_TRANSLIT = (isset($USE_TRANSLIT) && 'Y' == $USE_TRANSLIT ? 'Y' : 'N');
271 if ('Y' == $USE_TRANSLIT)
272 {
273 $boolOutTranslit = false;
274 if (isset($arIBlock['FIELDS']['CODE']['DEFAULT_VALUE']))
275 {
276 if ('Y' == $arIBlock['FIELDS']['CODE']['DEFAULT_VALUE']['TRANSLITERATION']
277 && 'Y' == $arIBlock['FIELDS']['CODE']['DEFAULT_VALUE']['USE_GOOGLE'])
278 {
279 $boolOutTranslit = true;
280 }
281 }
282 if (isset($arIBlock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE']))
283 {
284 if ('Y' == $arIBlock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE']['TRANSLITERATION']
285 && 'Y' == $arIBlock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE']['USE_GOOGLE'])
286 {
287 $boolOutTranslit = true;
288 }
289 }
290 if ($boolOutTranslit)
291 {
292 $USE_TRANSLIT = 'N';
293 $strImportErrorMessage .= GetMessage("CATI_USE_CODE_TRANSLIT_OUT")."<br>";
294 }
295 }
296 if ('Y' == $USE_TRANSLIT)
297 {
298 $TRANSLIT_LANG = (isset($TRANSLIT_LANG) ? strval($TRANSLIT_LANG) : '');
299 if (!empty($TRANSLIT_LANG))
300 {
301 $rsTransLangs = CLanguage::GetByID($TRANSLIT_LANG);
302 if (!($arTransLang = $rsTransLangs->Fetch()))
303 {
304 $TRANSLIT_LANG = '';
305 }
306 }
307 if (empty($TRANSLIT_LANG))
308 {
309 $USE_TRANSLIT = 'N';
310 $strImportErrorMessage .= GetMessage("CATI_CODE_TRANSLIT_LANG_ERR")."<br>";
311 }
312 }
313 $updateTranslit = false;
314 if ($USE_TRANSLIT == 'Y')
315 {
316 $updateTranslit = true;
317 if (isset($USE_UPDATE_TRANSLIT) && $USE_UPDATE_TRANSLIT == 'N')
318 $updateTranslit = false;
319 }
320}
321
322$IMAGE_RESIZE = (isset($IMAGE_RESIZE) && 'Y' == $IMAGE_RESIZE ? 'Y' : 'N');
325if (empty($arSku))
326 $CML2_LINK_IS_XML = 'N';
327
328if ('' == $strImportErrorMessage)
329{
330 $currentUserID = $USER->GetID();
331
333 $arDisableFields = array(
334 'CP_QUANTITY' => true,
335 'CP_PURCHASING_PRICE' => true,
336 'CP_PURCHASING_CURRENCY' => true,
337 );
338
339 $arProductCache = array();
340 $arPropertyListCache = array();
341 $arSectionCache = array();
342 $arElementCache = array();
343
344 $productPriceCache = array();
345 $processedProductPriceCache = array();
346
347 $csvFile->SetPos($CUR_FILE_POS);
348 $arRes = $csvFile->Fetch();
349 if ($CUR_FILE_POS<=0 && $bFirstHeaderTmp)
350 {
351 $arRes = $csvFile->Fetch();
352 }
353
354 $bs = new CIBlockSection();
355 $el = new CIBlockElement();
356 $bWasIterations = false;
357
358 $defaultMeasureId = null;
359 $measure = CCatalogMeasure::getDefaultMeasure();
360 if (!empty($measure))
361 {
362 if ($measure['ID'] > 0)
363 $defaultMeasureId = $measure['ID'];
364 }
365 unset($measure);
366
369 if ($arRes)
370 {
371 $bWasIterations = true;
372 if ($bFirstLoadStep)
373 {
374 $tmpid = md5(uniqid(""));
375 $line_num = 0;
376 $correct_lines = 0;
377 $error_lines = 0;
378 $killed_lines = 0;
379
380 $arIBlockProperty = array();
381 $arIBlockPropertyValue = array();
382 $multiplePropertyValuesCheck = array();
383 $bThereIsGroups = false;
384 $bDeactivationStarted = false;
385 $arProductGroups = array();
386 $currentProductSection = [];
387 $bUpdatePrice = 'N';
388 }
389
390 $boolTranslitElement = false;
391
392 $boolTranslitSection = false;
393 $arTranslitElement = array();
394 $arTranslitSection = array();
395 if ('Y' == $USE_TRANSLIT)
396 {
397 if (isset($arIBlock['FIELDS']['CODE']['DEFAULT_VALUE']))
398 {
399 $arTransSettings = $arIBlock['FIELDS']['CODE']['DEFAULT_VALUE'];
400 $boolTranslitElement = ($arTransSettings['TRANSLITERATION'] == 'Y');
401 $arTranslitElement = array(
402 "max_len" => $arTransSettings['TRANS_LEN'],
403 "change_case" => $arTransSettings['TRANS_CASE'],
404 "replace_space" => $arTransSettings['TRANS_SPACE'],
405 "replace_other" => $arTransSettings['TRANS_OTHER'],
406 "delete_repeat_replace" => ($arTransSettings['TRANS_EAT'] == 'Y'),
407 );
408 }
409 if (isset($arIBlock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE']))
410 {
411 $arTransSettings = $arIBlock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE'];
412 $boolTranslitSection = ($arTransSettings['TRANSLITERATION'] == 'Y');
413 $arTranslitSection = array(
414 "max_len" => $arTransSettings['TRANS_LEN'],
415 "change_case" => $arTransSettings['TRANS_CASE'],
416 "replace_space" => $arTransSettings['TRANS_SPACE'],
417 "replace_other" => $arTransSettings['TRANS_OTHER'],
418 "delete_repeat_replace" => ($arTransSettings['TRANS_EAT'] == 'Y'),
419 );
420 }
421 }
422
423 // Prepare load arrays
424 $strAvailGroupFields = COption::GetOptionString("catalog", "allowed_group_fields", $defCatalogAvailGroupFields);
425 $arAvailGroupFields = explode(",", $strAvailGroupFields);
426 $arAvailGroupFields_names = array();
427 for ($i = 0, $intCount = count($arAvailGroupFields), $intCount2 = count($arCatalogAvailGroupFields); $i < $intCount; $i++)
428 {
429 for ($j = 0; $j < $intCount2; $j++)
430 {
431 if ($arCatalogAvailGroupFields[$j]["value"]==$arAvailGroupFields[$i])
432 {
433 $arAvailGroupFields_names[$arAvailGroupFields[$i]] = array(
434 "field" => $arCatalogAvailGroupFields[$j]["field"],
435 "important" => $arCatalogAvailGroupFields[$j]["important"]
436 );
437 break;
438 }
439 }
440 }
441
442 // Prepare load arrays
443 $strAvailProdFields = COption::GetOptionString("catalog", "allowed_product_fields", $defCatalogAvailProdFields);
444 $arAvailProdFields = explode(",", $strAvailProdFields);
445 $arAvailProdFields_names = array();
446 for ($i = 0, $intCount = count($arAvailProdFields), $intCount2 = count($arCatalogAvailProdFields); $i < $intCount; $i++)
447 {
448 for ($j = 0; $j < $intCount2; $j++)
449 {
450 if ($arCatalogAvailProdFields[$j]["value"]==$arAvailProdFields[$i])
451 {
452 $arAvailProdFields_names[$arAvailProdFields[$i]] = array(
453 "field" => $arCatalogAvailProdFields[$j]["field"],
454 "important" => $arCatalogAvailProdFields[$j]["important"]
455 );
456 break;
457 }
458 }
459 }
460
461 // Prepare load arrays
462 $strAvailPriceFields = COption::GetOptionString("catalog", "allowed_product_fields", $defCatalogAvailPriceFields);
463 $arAvailPriceFields = explode(",", $strAvailPriceFields);
464 $arAvailPriceFields_names = array();
465 for ($i = 0, $intCount = count($arAvailPriceFields), $intCount2 = count($arCatalogAvailPriceFields); $i < $intCount; $i++)
466 {
467 if ($boolUseStoreControl && array_key_exists($arAvailPriceFields[$i], $arDisableFields))
468 continue;
469
470 for ($j = 0; $j < $intCount2; $j++)
471 {
472 if ($arCatalogAvailPriceFields[$j]["value"]==$arAvailPriceFields[$i])
473 {
474 $arAvailPriceFields_names[$arAvailPriceFields[$i]] = array(
475 "field" => $arCatalogAvailPriceFields[$j]["field"],
476 "important" => $arCatalogAvailPriceFields[$j]["important"]
477 );
478 break;
479 }
480 }
481 }
482
483 // Prepare load arrays
484 $strAvailValueFields = COption::GetOptionString("catalog", "allowed_price_fields", $defCatalogAvailValueFields);
485 $arAvailValueFields = explode(",", $strAvailValueFields);
486 $arAvailValueFields_names = array();
487 for ($i = 0, $intCount = count($arAvailValueFields), $intCount2 = count($arCatalogAvailValueFields); $i < $intCount; $i++)
488 {
489 for ($j = 0; $j < $intCount2; $j++)
490 {
491 if ($arCatalogAvailValueFields[$j]["value"] == $arAvailValueFields[$i])
492 {
493 $arAvailValueFields_names[$arAvailValueFields[$i]] = array(
494 "field_name_size" => $arCatalogAvailValueFields[$j]["value_size"],
495 "field" => $arCatalogAvailValueFields[$j]["field"],
496 "important" => $arCatalogAvailValueFields[$j]["important"]
497 );
498 break;
499 }
500 }
501 }
502
503 $previousProductId = false;
504 $updateFacet = false;
505 $newProducts = array();
506 CIBlock::disableClearTagCache();
507 // main
508 do
509 {
510 $strErrorR = "";
511 $line_num++;
512
513
514 $arGroupsTmp = array();
515
516 for ($i = 0; $i < $NUM_CATALOG_LEVELS; $i++)
517 {
518 $arGroupsTmp1 = array();
519 foreach ($arAvailGroupFields_names as $key => $value)
520 {
521 $ind = -1;
522 for ($i_tmp = 0; $i_tmp < $NUM_FIELDS; $i_tmp++)
523 {
524 if (${"field_".$i_tmp} == $key.$i)
525 {
526 $ind = $i_tmp;
527 break;
528 }
529 }
530
531 if ($ind>-1)
532 {
533 $arGroupsTmp1[$value["field"]] = trim($arRes[$ind]);
534 $bThereIsGroups = true;
535 }
536 }
537 $arGroupsTmp[] = $arGroupsTmp1;
538 }
539
540 $i = count($arGroupsTmp)-1;
541 while ($i>=0)
542 {
543 foreach ($arAvailGroupFields_names as $key => $value)
544 {
545 if ($value["important"]=="Y" && isset($arGroupsTmp[$i][$value["field"]]) && '' !== $arGroupsTmp[$i][$value["field"]])
546 {
547 break 2;
548 }
549 }
550 unset($arGroupsTmp[$i]);
551 $i--;
552 }
553
554 for ($i = 0, $intCount = count($arGroupsTmp); $i < $intCount; $i++)
555 {
556 if (isset($arGroupsTmp[$i]['NAME']) && '' === $arGroupsTmp[$i]["NAME"])
557 {
558 $arGroupsTmp[$i]["NAME"] = GetMessage("CATI_NOMAME");
559 }
560 $arGroupsTmp[$i]["TMP_ID"] = $tmpid;
561 }
562
563 $LAST_GROUP_CODE = 0;
564 $sectionKey = '';
565 for ($i = 0, $intCount = count($arGroupsTmp); $i < $intCount; $i++)
566 {
567 $sectionFilter = '';
568 $arFilter = array("IBLOCK_ID" => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N');
569 if (isset($arGroupsTmp[$i]["XML_ID"]) && '' !== $arGroupsTmp[$i]["XML_ID"])
570 {
571 $arFilter["=XML_ID"] = $arGroupsTmp[$i]["XML_ID"];
572 $sectionFilter = 'XML'.md5($arGroupsTmp[$i]["XML_ID"]);
573 }
574 elseif (isset($arGroupsTmp[$i]["NAME"]) && '' !== $arGroupsTmp[$i]["NAME"])
575 {
576 $arFilter["=NAME"] = $arGroupsTmp[$i]["NAME"];
577 $sectionFilter = 'NAME'.md5($arGroupsTmp[$i]["NAME"]);
578 }
579
580 if ($LAST_GROUP_CODE>0)
581 {
582 $arFilter["SECTION_ID"] = $LAST_GROUP_CODE;
583 $arGroupsTmp[$i]["IBLOCK_SECTION_ID"] = $LAST_GROUP_CODE;
584 }
585 else
586 {
587 $arFilter["SECTION_ID"] = 0;
588 $arGroupsTmp[$i]["IBLOCK_SECTION_ID"] = false;
589 }
590 $sectionKey .= $LAST_GROUP_CODE.':';
591 $sectionIndex = $sectionKey.$sectionFilter;
592 if (!isset($arSectionCache[$sectionIndex]))
593 {
594 if (isset($arGroupsTmp[$i]["PICTURE"]))
595 {
596 $arGroupsTmp[$i]["PICTURE"] = trim($arGroupsTmp[$i]["PICTURE"]);
597 $bFilePres = false;
598 if ('' !== $arGroupsTmp[$i]["PICTURE"])
599 {
600 if (preg_match("/^(ftp|ftps|http|https):\\/\\//", $arGroupsTmp[$i]["PICTURE"]))
601 {
602 $arGroupsTmp[$i]["PICTURE"] = CFile::MakeFileArray($arGroupsTmp[$i]["PICTURE"]);
603 }
604 else
605 {
606 $arGroupsTmp[$i]["PICTURE"] = CFile::MakeFileArray($io->GetPhysicalName($_SERVER["DOCUMENT_ROOT"].$PATH2IMAGE_FILES."/".$arGroupsTmp[$i]["PICTURE"]));
607 if (!empty($arGroupsTmp[$i]["PICTURE"]) && is_array($arGroupsTmp[$i]["PICTURE"]))
608 $arGroupsTmp[$i]["PICTURE"]['COPY_FILE'] = 'Y';
609 }
610 $bFilePres = (!empty($arGroupsTmp[$i]["PICTURE"])
611 && isset($arGroupsTmp[$i]["PICTURE"]["tmp_name"])
612 && '' !== $arGroupsTmp[$i]["PICTURE"]["tmp_name"]
613 );
614 }
615 if (!$bFilePres)
616 unset($arGroupsTmp[$i]["PICTURE"]);
617 }
618 if (isset($arGroupsTmp[$i]["DETAIL_PICTURE"]))
619 {
620 $arGroupsTmp[$i]["DETAIL_PICTURE"] = trim($arGroupsTmp[$i]["DETAIL_PICTURE"]);
621 $bFilePres = false;
622 if ('' !== $arGroupsTmp[$i]["DETAIL_PICTURE"])
623 {
624 if (preg_match("/^(ftp|ftps|http|https):\\/\\//", $arGroupsTmp[$i]["DETAIL_PICTURE"]))
625 {
626 $arGroupsTmp[$i]["DETAIL_PICTURE"] = CFile::MakeFileArray($arGroupsTmp[$i]["DETAIL_PICTURE"]);
627 }
628 else
629 {
630 $arGroupsTmp[$i]["DETAIL_PICTURE"] = CFile::MakeFileArray($io->GetPhysicalName($_SERVER["DOCUMENT_ROOT"].$PATH2IMAGE_FILES."/".$arGroupsTmp[$i]["DETAIL_PICTURE"]));
631 if (!empty($arGroupsTmp[$i]["DETAIL_PICTURE"]) && is_array($arGroupsTmp[$i]["DETAIL_PICTURE"]))
632 $arGroupsTmp[$i]["DETAIL_PICTURE"]['COPY_FILE'] = 'Y';
633 }
634 $bFilePres = (!empty($arGroupsTmp[$i]["DETAIL_PICTURE"])
635 && isset($arGroupsTmp[$i]["DETAIL_PICTURE"]["tmp_name"])
636 && '' !== $arGroupsTmp[$i]["DETAIL_PICTURE"]["tmp_name"]
637 );
638 }
639 if (!$bFilePres)
640 unset($arGroupsTmp[$i]["DETAIL_PICTURE"]);
641 }
642
643 $res = CIBlockSection::GetList(array(), $arFilter, false, array('ID'));
644 if ($arr = $res->Fetch())
645 {
646 if ($boolTranslitSection && $updateTranslit)
647 {
648 if (!isset($arGroupsTmp[$i]['CODE']) || '' === $arGroupsTmp[$i]['CODE'])
649 {
650 $arGroupsTmp[$i]['CODE'] = CUtil::translit($arGroupsTmp[$i]["NAME"], $TRANSLIT_LANG, $arTranslitSection);
651 }
652 }
653 $LAST_GROUP_CODE = $arr["ID"];
654 $res = $bs->Update($LAST_GROUP_CODE, $arGroupsTmp[$i], true, true, 'Y' === $IMAGE_RESIZE);
655 if (!$res)
656 {
657 $strErrorR .= GetMessage("CATI_LINE_NO")." ".$line_num.". ".GetMessage("CATI_ERR_UPDATE_SECT")." ".$bs->LAST_ERROR."<br>";
658 }
659 }
660 else
661 {
662 if ($boolTranslitSection)
663 {
664 if (!isset($arGroupsTmp[$i]['CODE']) || '' === $arGroupsTmp[$i]['CODE'])
665 {
666 $arGroupsTmp[$i]['CODE'] = CUtil::translit($arGroupsTmp[$i]["NAME"], $TRANSLIT_LANG, $arTranslitSection);
667 }
668 }
669 $arGroupsTmp[$i]["IBLOCK_ID"] = $IBLOCK_ID;
670 $arGroupsTmp[$i]["ACTIVE"] = (isset($arGroupsTmp[$i]["ACTIVE"]) && 'N' === $arGroupsTmp[$i]["ACTIVE"] ? 'N' : 'Y');
671 $LAST_GROUP_CODE = $bs->Add($arGroupsTmp[$i], true, true, 'Y' === $IMAGE_RESIZE);
672 if (!$LAST_GROUP_CODE)
673 {
674 $strErrorR .= GetMessage("CATI_LINE_NO")." ".$line_num.". ".GetMessage("CATI_ERR_ADD_SECT")." ".$bs->LAST_ERROR."<br>";
675 }
676 }
677
678 if ('' === $strErrorR)
679 {
680 $arSectionCache[$sectionIndex] = $LAST_GROUP_CODE;
681 }
682 }
683 else
684 {
685 $LAST_GROUP_CODE = $arSectionCache[$sectionIndex];
686 }
687 }
688
689 $arFilter = array("IBLOCK_ID" => $IBLOCK_ID);
690 if ('' === $strErrorR)
691 {
692 $arLoadProductArray = array(
693 "MODIFIED_BY" => $currentUserID,
694 "IBLOCK_ID" => $IBLOCK_ID,
695 "TMP_ID" => $tmpid
696 );
697 foreach ($arAvailProdFields_names as $key => $value)
698 {
699 $ind = -1;
700 for ($i_tmp = 0; $i_tmp < $NUM_FIELDS; $i_tmp++)
701 {
702 if (${"field_".$i_tmp} == $key)
703 {
704 $ind = $i_tmp;
705 break;
706 }
707 }
708
709 if ($ind>-1)
710 {
711 $arLoadProductArray[$value["field"]] = trim($arRes[$ind]);
712 }
713 }
714
715 if (isset($arLoadProductArray["XML_ID"]) && '' !== $arLoadProductArray["XML_ID"])
716 {
717 $arFilter["=XML_ID"] = $arLoadProductArray["XML_ID"];
718 }
719 else
720 {
721 if (isset($arLoadProductArray["NAME"]) && '' !== $arLoadProductArray["NAME"])
722 {
723 $arFilter["=NAME"] = $arLoadProductArray["NAME"];
724 }
725 else
726 {
727 $strErrorR .= GetMessage("CATI_LINE_NO")." ".$line_num.". ".GetMessage("CATI_NOIDNAME")."<br>";
728 }
729 }
730 }
731
732 if ('' === $strErrorR)
733 {
734 if (isset($arLoadProductArray["PREVIEW_PICTURE"]))
735 {
736 $arLoadProductArray["PREVIEW_PICTURE"] = trim($arLoadProductArray["PREVIEW_PICTURE"]);
737 $bFilePres = false;
738 if ('' !== $arLoadProductArray["PREVIEW_PICTURE"])
739 {
740 if (preg_match("/^(ftp|ftps|http|https):\\/\\//", $arLoadProductArray["PREVIEW_PICTURE"]))
741 {
742 $arLoadProductArray["PREVIEW_PICTURE"] = CFile::MakeFileArray($arLoadProductArray["PREVIEW_PICTURE"]);
743 }
744 else
745 {
746 $arLoadProductArray["PREVIEW_PICTURE"] = CFile::MakeFileArray($io->GetPhysicalName($_SERVER["DOCUMENT_ROOT"].$PATH2IMAGE_FILES."/".$arLoadProductArray["PREVIEW_PICTURE"]));
747 if (!empty($arLoadProductArray["PREVIEW_PICTURE"]) && is_array($arLoadProductArray["PREVIEW_PICTURE"]))
748 $arLoadProductArray["PREVIEW_PICTURE"]["COPY_FILE"] = "Y";
749 }
750 $bFilePres = (!empty($arLoadProductArray["PREVIEW_PICTURE"])
751 && isset($arLoadProductArray["PREVIEW_PICTURE"]["tmp_name"])
752 && '' !== $arLoadProductArray["PREVIEW_PICTURE"]["tmp_name"]
753 );
754 }
755 if (!$bFilePres)
756 unset($arLoadProductArray["PREVIEW_PICTURE"]);
757 }
758
759 if (isset($arLoadProductArray["DETAIL_PICTURE"]))
760 {
761 $arLoadProductArray["DETAIL_PICTURE"] = trim($arLoadProductArray["DETAIL_PICTURE"]);
762 $bFilePres = false;
763 if ('' !== $arLoadProductArray["DETAIL_PICTURE"])
764 {
765 if (preg_match("/^(ftp|ftps|http|https):\\/\\//", $arLoadProductArray["DETAIL_PICTURE"]))
766 {
767 $arLoadProductArray["DETAIL_PICTURE"] = CFile::MakeFileArray($arLoadProductArray["DETAIL_PICTURE"]);
768 }
769 else
770 {
771 $arLoadProductArray["DETAIL_PICTURE"] = CFile::MakeFileArray($io->GetPhysicalName($_SERVER["DOCUMENT_ROOT"].$PATH2IMAGE_FILES."/".$arLoadProductArray["DETAIL_PICTURE"]));
772 if (!empty($arLoadProductArray["DETAIL_PICTURE"]) && is_array($arLoadProductArray["DETAIL_PICTURE"]))
773 $arLoadProductArray["DETAIL_PICTURE"]["COPY_FILE"] = "Y";
774 }
775 $bFilePres = (!empty($arLoadProductArray["DETAIL_PICTURE"])
776 && isset($arLoadProductArray["DETAIL_PICTURE"]["tmp_name"])
777 && '' !== $arLoadProductArray["DETAIL_PICTURE"]["tmp_name"]
778 );
779 }
780 if (!$bFilePres)
781 unset($arLoadProductArray["DETAIL_PICTURE"]);
782 }
783
784 $res = CIBlockElement::GetList(
785 array(),
786 $arFilter,
787 false,
788 false,
789 array('ID', 'PREVIEW_PICTURE', 'DETAIL_PICTURE', 'IBLOCK_SECTION_ID')
790 );
791 if ($arr = $res->Fetch())
792 {
793 $PRODUCT_ID = (int)$arr['ID'];
794 if (isset($arLoadProductArray["PREVIEW_PICTURE"]) && intval($arr["PREVIEW_PICTURE"])>0)
795 {
796 $arLoadProductArray["PREVIEW_PICTURE"]["old_file"] = $arr["PREVIEW_PICTURE"];
797 }
798 if (isset($arLoadProductArray["DETAIL_PICTURE"]) && intval($arr["DETAIL_PICTURE"])>0)
799 {
800 $arLoadProductArray["DETAIL_PICTURE"]["old_file"] = $arr["DETAIL_PICTURE"];
801 }
802 if ($boolTranslitElement && $updateTranslit)
803 {
804 if (!isset($arLoadProductArray['CODE']) || '' === $arLoadProductArray['CODE'])
805 {
806 $arLoadProductArray['CODE'] = CUtil::translit($arLoadProductArray["NAME"], $TRANSLIT_LANG, $arTranslitElement);
807 }
808 }
809 if ($bThereIsGroups)
810 {
811 if (!isset($currentProductSection[$PRODUCT_ID]))
812 $currentProductSection[$PRODUCT_ID] = $arr['IBLOCK_SECTION_ID'];
813 $LAST_GROUP_CODE_tmp = (($LAST_GROUP_CODE > 0) ? $LAST_GROUP_CODE : false);
814 if (!isset($arProductGroups[$PRODUCT_ID]))
815 $arProductGroups[$PRODUCT_ID] = array();
816 if (!in_array($LAST_GROUP_CODE_tmp, $arProductGroups[$PRODUCT_ID]))
817 {
818 $arProductGroups[$PRODUCT_ID][] = $LAST_GROUP_CODE_tmp;
819 }
820 $arLoadProductArray["IBLOCK_SECTION"] = $arProductGroups[$PRODUCT_ID];
821 $arLoadProductArray['IBLOCK_SECTION_ID'] = $currentProductSection[$PRODUCT_ID];
822 $updateFacet = true;
823 }
824 $res = $el->Update($PRODUCT_ID, $arLoadProductArray, $bWorkflow, false, 'Y' === $IMAGE_RESIZE);
825 }
826 else
827 {
828 if ($bThereIsGroups)
829 {
830 $arLoadProductArray["IBLOCK_SECTION"] = (($LAST_GROUP_CODE>0) ? $LAST_GROUP_CODE : false);
831 }
832 if ($arLoadProductArray["ACTIVE"] != "N")
833 $arLoadProductArray["ACTIVE"] = "Y";
834 if ($boolTranslitElement)
835 {
836 if (!isset($arLoadProductArray['CODE']) || '' === $arLoadProductArray['CODE'])
837 {
838 $arLoadProductArray['CODE'] = CUtil::translit($arLoadProductArray["NAME"], $TRANSLIT_LANG, $arTranslitElement);
839 }
840 }
841
842 $PRODUCT_ID = $el->Add($arLoadProductArray, $bWorkflow, false, 'Y' === $IMAGE_RESIZE);
843 if ($bThereIsGroups)
844 {
845 if (!isset($arProductGroups[$PRODUCT_ID]))
846 $arProductGroups[$PRODUCT_ID] = array();
847 $arProductGroups[$PRODUCT_ID][] = (($LAST_GROUP_CODE > 0) ? $LAST_GROUP_CODE : false);
848 }
849 $res = ($PRODUCT_ID > 0);
850 if ($res)
851 $newProducts[$PRODUCT_ID] = true;
852 }
853
854 if (!$res)
855 {
856 $strErrorR .= GetMessage("CATI_LINE_NO")." ".$line_num.". ".GetMessage("CATI_ERROR_LOADING")." ".$el->LAST_ERROR."<br>";
857 }
858 }
859
860 if ('' === $strErrorR)
861 {
862 $PROP = array();
863 for ($i = 0; $i < $NUM_FIELDS; $i++)
864 {
865 if (0 == strncmp(${"field_".$i}, "IP_PROP", 7))
866 {
867 $cur_prop_id = intval(mb_substr(${"field_".$i}, 7));
868 if (!isset($arIBlockProperty[$cur_prop_id]))
869 {
870 $res1 = CIBlockProperty::GetByID($cur_prop_id, $IBLOCK_ID);
871 if ($arRes1 = $res1->Fetch())
872 $arIBlockProperty[$cur_prop_id] = $arRes1;
873 else
874 $arIBlockProperty[$cur_prop_id] = array();
875 }
876 if (!empty($arIBlockProperty[$cur_prop_id]) && is_array($arIBlockProperty[$cur_prop_id]))
877 {
878 $multipleCheckId = $arRes[$i];
879 if ('Y' == $CML2_LINK_IS_XML && $cur_prop_id == $arSku['SKU_PROPERTY_ID'])
880 {
881 $arRes[$i] = trim($arRes[$i]);
882 if ('' != $arRes[$i])
883 {
884 if (!isset($arProductCache[$arRes[$i]]))
885 {
886 $rsProducts = CIBlockElement::GetList(
887 array(),
888 array('IBLOCK_ID' => $arSku['PRODUCT_IBLOCK_ID'], '=XML_ID' => $arRes[$i]),
889 false,
890 false,
891 array('ID')
892 );
893 if ($arParentProduct = $rsProducts->Fetch())
894 $arProductCache[$arRes[$i]] = $arParentProduct['ID'];
895 }
896 $arRes[$i] = (isset($arProductCache[$arRes[$i]]) ? $arProductCache[$arRes[$i]] : '');
897 }
898 }
899 elseif ($arIBlockProperty[$cur_prop_id]["PROPERTY_TYPE"]=="L")
900 {
901 $arRes[$i] = trim($arRes[$i]);
902 if ('' !== $arRes[$i])
903 {
904 $propValueHash = md5($arRes[$i]);
905 if (!isset($arPropertyListCache[$cur_prop_id]))
906 {
907 $arPropertyListCache[$cur_prop_id] = array();
908 $propEnumRes = CIBlockPropertyEnum::GetList(
909 array('SORT' => 'ASC', 'VALUE' => 'ASC'),
910 array('IBLOCK_ID' => $IBLOCK_ID, 'PROPERTY_ID' => $arIBlockProperty[$cur_prop_id]['ID'])
911 );
912 while ($propEnumValue = $propEnumRes->Fetch())
913 $arPropertyListCache[$cur_prop_id][md5($propEnumValue['VALUE'])] = $propEnumValue['ID'];
914 }
915 if (!isset($arPropertyListCache[$cur_prop_id][$propValueHash]))
916 {
917 $arPropertyListCache[$cur_prop_id][$propValueHash] = CIBlockPropertyEnum::Add(
918 array(
919 "PROPERTY_ID" => $arIBlockProperty[$cur_prop_id]['ID'],
920 "VALUE" => $arRes[$i],
921 "TMP_ID" => $tmpid
922 )
923 );
924 }
925 if (isset($arPropertyListCache[$cur_prop_id][$propValueHash]))
926 {
927 $arRes[$i] = $arPropertyListCache[$cur_prop_id][$propValueHash];
928 }
929 else
930 {
931 $arRes[$i] = '';
932 }
933 }
934 }
935 elseif ($arIBlockProperty[$cur_prop_id]["PROPERTY_TYPE"]=="F")
936 {
937 $arRes[$i] = trim($arRes[$i]);
938 if(preg_match("/^(ftp|ftps|http|https):\\/\\//", $arRes[$i]))
939 $arRes[$i] = CFile::MakeFileArray($arRes[$i]);
940 else
941 $arRes[$i] = CFile::MakeFileArray($io->GetPhysicalName($_SERVER["DOCUMENT_ROOT"].$PATH2IMAGE_FILES.'/'.$arRes[$i]));
942
943 if (!is_array($arRes[$i]) || !array_key_exists("tmp_name", $arRes[$i]))
944 $arRes[$i] = '';
945 }
946 if (!is_array($arRes[$i]))
947 {
948 $arRes[$i] = trim($arRes[$i]);
949 if ($arRes[$i] == '')
950 $multipleCheckId = $arRes[$i];
951 }
952
953 if ($arIBlockProperty[$cur_prop_id]["MULTIPLE"]=="Y")
954 {
955 if (!isset($arIBlockPropertyValue[$PRODUCT_ID]))
956 {
957 $arIBlockPropertyValue[$PRODUCT_ID] = array();
958 $multiplePropertyValuesCheck[$PRODUCT_ID] = array();
959 }
960 if (
961 !isset($arIBlockPropertyValue[$PRODUCT_ID][$cur_prop_id])
962 || !is_array($arIBlockPropertyValue[$PRODUCT_ID][$cur_prop_id])
963 )
964 {
965 $arIBlockPropertyValue[$PRODUCT_ID][$cur_prop_id] = array();
966 $multiplePropertyValuesCheck[$PRODUCT_ID][$cur_prop_id] = array();
967 }
968
969 if (
970 !in_array($multipleCheckId, $multiplePropertyValuesCheck[$PRODUCT_ID][$cur_prop_id])
971 )
972 {
973 $arIBlockPropertyValue[$PRODUCT_ID][$cur_prop_id][] = $arRes[$i];
974 $multiplePropertyValuesCheck[$PRODUCT_ID][$cur_prop_id][] = $multipleCheckId;
975 }
976
977 $PROP[$cur_prop_id] = $arIBlockPropertyValue[$PRODUCT_ID][$cur_prop_id];
978 }
979 else
980 {
981 $PROP[$cur_prop_id] = $arRes[$i];
982 }
983 }
984 }
985 }
986
987 if (!empty($PROP))
988 {
989 CIBlockElement::SetPropertyValuesEx($PRODUCT_ID, $IBLOCK_ID, $PROP);
990 $updateFacet = true;
991 }
992 }
993
994 if ('' == $strErrorR && $bIBlockIsCatalog)
995 {
996 $arLoadOfferArray = array(
997 'ID' => $PRODUCT_ID,
998 'TMP_ID' => $tmpid
999 );
1000 foreach ($arAvailPriceFields_names as $key => $value)
1001 {
1002 $ind = -1;
1003 for ($i_tmp = 0; $i_tmp < $NUM_FIELDS; $i_tmp++)
1004 {
1005 if (${"field_".$i_tmp} == $key)
1006 {
1007 $ind = $i_tmp;
1008 break;
1009 }
1010 }
1011
1012 if ($ind > -1)
1013 $arLoadOfferArray[$value["field"]] = trim($arRes[$ind]);
1014 }
1015
1016 $arLoadOfferArray = array(
1017 'fields' => $arLoadOfferArray,
1018 'external_fields' => array(
1019 'IBLOCK_ID' => $IBLOCK_ID
1020 )
1021 );
1022 $row = Catalog\Model\Product::getList(array(
1023 'select' => array('ID'),
1024 'filter' => array('=ID' => $PRODUCT_ID)
1025 ))->fetch();
1026 if (empty($row))
1027 {
1028 if ($boolUseStoreControl)
1029 {
1030 $arLoadOfferArray['fields']['QUANTITY'] = 0;
1031 $arLoadOfferArray['fields']['QUANTITY_RESERVED'] = 0;
1032 $arLoadOfferArray['fields']['QUANTITY_TRACE'] = Catalog\ProductTable::STATUS_YES;
1033 $arLoadOfferArray['fields']['CAN_BUY_ZERO'] = Catalog\ProductTable::STATUS_NO;
1034 $arLoadOfferArray['fields']['PURCHASING_PRICE'] = null;
1035 $arLoadOfferArray['fields']['PURCHASING_CURRENCY'] = null;
1036 }
1037 else
1038 {
1039 if (isset($arLoadOfferArray['fields']['QUANTITY']) && $arLoadOfferArray['fields']['QUANTITY'] === '')
1040 unset($arLoadOfferArray['fields']['QUANTITY']);
1041 $emptyStartPrice = (
1042 (
1043 isset($arLoadOfferArray['fields']['PURCHASING_PRICE'])
1044 && $arLoadOfferArray['fields']['PURCHASING_PRICE'] === ''
1045 )
1046 &&
1047 (
1048 isset($arLoadOfferArray['fields']['PURCHASING_CURRENCY'])
1049 && $arLoadOfferArray['fields']['PURCHASING_CURRENCY'] === ''
1050 )
1051 );
1052 if ($emptyStartPrice)
1053 {
1054 unset($arLoadOfferArray['fields']['PURCHASING_PRICE']);
1055 unset($arLoadOfferArray['fields']['PURCHASING_CURRENCY']);
1056 }
1057 unset($emptyStartPrice);
1058 if (isset($arLoadOfferArray['fields']['PURCHASING_PRICE']))
1059 {
1060 $arLoadOfferArray['fields']['PURCHASING_PRICE'] = str_replace(
1061 array(' ', ','),
1062 array('', '.'),
1063 $arLoadOfferArray['fields']['PURCHASING_PRICE']
1064 );
1065 }
1066 }
1067 if (isset($arLoadOfferArray['fields']['WEIGHT']) && $arLoadOfferArray['fields']['WEIGHT'] === '')
1068 unset($arLoadOfferArray['fields']['WEIGHT']);
1069 if (empty($arLoadOfferArray['fields']['MEASURE']) && $defaultMeasureId !== null)
1070 $arLoadOfferArray['fields']['MEASURE'] = $defaultMeasureId;
1071 $productResult = Catalog\Model\Product::add($arLoadOfferArray);
1072 }
1073 else
1074 {
1075 if (!$boolUseStoreControl)
1076 {
1077 if (isset($arLoadOfferArray['fields']['QUANTITY']) && $arLoadOfferArray['fields']['QUANTITY'] === '')
1078 $arLoadOfferArray['fields']['QUANTITY'] = 0;
1079 $emptyStartPrice = (
1080 (
1081 isset($arLoadOfferArray['fields']['PURCHASING_PRICE'])
1082 && $arLoadOfferArray['fields']['PURCHASING_PRICE'] === ''
1083 )
1084 &&
1085 (
1086 isset($arLoadOfferArray['fields']['PURCHASING_CURRENCY'])
1087 && $arLoadOfferArray['fields']['PURCHASING_CURRENCY'] === ''
1088 )
1089 );
1090 if ($emptyStartPrice)
1091 {
1092 $arLoadOfferArray['fields']['PURCHASING_PRICE'] = null;
1093 $arLoadOfferArray['fields']['PURCHASING_CURRENCY'] = null;
1094 }
1095 unset($emptyStartPrice);
1096 if (isset($arLoadOfferArray['fields']['PURCHASING_PRICE']))
1097 {
1098 $arLoadOfferArray['fields']['PURCHASING_PRICE'] = str_replace(
1099 array(' ', ','),
1100 array('', '.'),
1101 $arLoadOfferArray['fields']['PURCHASING_PRICE']
1102 );
1103 }
1104 }
1105 if (isset($arLoadOfferArray['fields']['WEIGHT']) && $arLoadOfferArray['fields']['WEIGHT'] === '')
1106 $arLoadOfferArray['fields']['WEIGHT'] = 0;
1107 $productResult = Catalog\Model\Product::update($PRODUCT_ID, $arLoadOfferArray);
1108 }
1109 unset($row);
1110 unset($arLoadOfferArray);
1111 if (!$productResult->isSuccess())
1112 {
1113 $strErrorR .= GetMessage('CATI_LINE_NO').' '.$line_num.'. '.implode('; ', $productResult->getErrorMessages());
1114 }
1115 else
1116 {
1117 $quantityFrom = 0;
1118 $quantityTo = 0;
1119 for ($j = 0; $j < $NUM_FIELDS; $j++)
1120 {
1121 if (${"field_".$j} == "CV_QUANTITY_FROM")
1122 $quantityFrom = (int)$arRes[$j];
1123 elseif (${"field_".$j} == "CV_QUANTITY_TO")
1124 $quantityTo = (int)$arRes[$j];
1125 }
1126 if ($quantityFrom <= 0)
1127 $quantityFrom = null;
1128 if ($quantityTo <= 0)
1129 $quantityTo = null;
1130
1131 $arFields = array();
1133 for ($j = 0; $j < $NUM_FIELDS; $j++)
1134 {
1135 foreach ($arAvailValueFields_names as $key => $value)
1136 {
1137 if (0 == strncmp(${"field_".$j}, $key."_", $value['field_name_size'] + 1))
1138 {
1139 $strTempKey = intval(mb_substr(${"field_".$j}, $value['field_name_size'] + 1));
1140 if (!isset($arFields[$strTempKey]))
1141 {
1142 $arFields[$strTempKey] = array(
1143 "PRODUCT_ID" => $PRODUCT_ID,
1144 "CATALOG_GROUP_ID" => $strTempKey,
1145 "QUANTITY_FROM" => $quantityFrom,
1146 "QUANTITY_TO" => $quantityTo,
1147 "TMP_ID" => $tmpid
1148 );
1149 $priceTypeList[$strTempKey] = $strTempKey;
1150 }
1151 $arFields[$strTempKey][$value["field"]] = trim($arRes[$j]);
1152 }
1153 }
1154 }
1155
1156 if (!empty($arFields))
1157 {
1158 if (!isset($productPriceCache[$PRODUCT_ID]))
1159 {
1160 $productPriceCache[$PRODUCT_ID] = array();
1161 $priceIterator = Catalog\Model\Price::getList(array(
1162 'select' => array('ID', 'CATALOG_GROUP_ID', 'QUANTITY_FROM', 'QUANTITY_TO'),
1163 'filter' => array('=PRODUCT_ID' => $PRODUCT_ID, '@CATALOG_GROUP_ID' => $priceTypeList)
1164 ));
1165 while ($row = $priceIterator->fetch())
1166 {
1167 $hash = ($row['QUANTITY_FROM'] === null ? 'ZERO' : $row['QUANTITY_FROM']).'-'.
1168 ($row['QUANTITY_TO'] === null ? 'INF' : $row['QUANTITY_TO']);
1169 $priceType = (int)$row['CATALOG_GROUP_ID'];
1170 if (!isset($productPriceCache[$PRODUCT_ID][$priceType]))
1171 $productPriceCache[$PRODUCT_ID][$priceType] = array();
1172 $productPriceCache[$PRODUCT_ID][$priceType][$hash] = (int)$row['ID'];
1173 }
1174 unset($row, $priceIterator);
1175 }
1176
1177 foreach ($arFields as $key => $value)
1178 {
1179 $strPriceErr = '';
1180
1181 $hash = ($value['QUANTITY_FROM'] === null ? 'ZERO' : $value['QUANTITY_FROM']).'-'.
1182 ($value['QUANTITY_TO'] === null ? 'INF' : $value['QUANTITY_TO']);
1183 $priceType = (int)$value['CATALOG_GROUP_ID'];
1184
1185 if (!isset($processedProductPriceCache[$PRODUCT_ID][$priceType][$hash]))
1186 {
1187 if (!isset($processedProductPriceCache[$PRODUCT_ID]))
1188 $processedProductPriceCache[$PRODUCT_ID] = array();
1189 if (!isset($processedProductPriceCache[$PRODUCT_ID][$priceType]))
1190 $processedProductPriceCache[$PRODUCT_ID][$priceType] = array();
1191
1192 $priceId = (isset($productPriceCache[$PRODUCT_ID][$priceType][$hash])
1193 ? $productPriceCache[$PRODUCT_ID][$priceType][$hash]
1194 : null
1195 );
1196
1197 if ($priceId !== null)
1198 {
1199 $emptyPrice = (
1200 (isset($value['PRICE']) && '' === $value['PRICE']) &&
1201 (isset($value['CURRENCY']) && '' === $value['CURRENCY'])
1202 );
1203 $boolEraseClear = ('Y' == $CLEAR_EMPTY_PRICE ? $emptyPrice :false);
1204 if ($boolEraseClear)
1205 {
1206 $priceResult = Catalog\Model\Price::delete($priceId);
1207 if (!$priceResult->isSuccess())
1208 {
1209 $strPriceErr = implode('; ', $priceResult->getErrorMessages());
1210 if ($strPriceErr !== '')
1211 $strPriceErr = GetMessage('CATI_ERR_PRICE_DELETE').$strPriceErr;
1212 else
1213 $strPriceErr = GetMessage('CATI_ERR_PRICE_DELETE');
1214 }
1215 unset($priceResult);
1216 }
1217 else
1218 {
1219 if (!$emptyPrice)
1220 {
1221 if (isset($value['PRICE']))
1222 $value['PRICE'] = str_replace(array(' ', ','), array('', '.'), $value['PRICE']);
1223 }
1224 else
1225 {
1226 $value = [
1227 "TMP_ID" => $tmpid
1228 ];
1229 }
1230
1231 $priceResult = Catalog\Model\Price::update($priceId, $value);
1232 if ($priceResult->isSuccess())
1233 {
1234 $bUpdatePrice = 'Y';
1235 }
1236 else
1237 {
1238 $strPriceErr = implode('; ', $priceResult->getErrorMessages());
1239 if ($strPriceErr !== '')
1240 $strPriceErr = GetMessage('CATI_ERR_PRICE_UPDATE').$strPriceErr;
1241 else
1242 $strPriceErr = GetMessage('CATI_ERR_PRICE_UPDATE_UNKNOWN');
1243 }
1244 unset($priceResult);
1245 }
1246 unset($productPriceCache[$PRODUCT_ID][$priceType][$hash]);
1247 $processedProductPriceCache[$PRODUCT_ID][$priceType][$hash] = $priceId;
1248 }
1249 else
1250 {
1251 $boolEmptyNewPrice = (
1252 (isset($value['PRICE']) && '' === $value['PRICE'])
1253 && (isset($value['CURRENCY']) && '' === $value['CURRENCY'])
1254 );
1255 if (!$boolEmptyNewPrice)
1256 {
1257 if (isset($value['PRICE']))
1258 $value['PRICE'] = str_replace(array(' ', ','), array('', '.'), $value['PRICE']);
1259
1260 $priceResult = Catalog\Model\Price::add($value);
1261 if ($priceResult->isSuccess())
1262 {
1263 $bUpdatePrice = 'Y';
1264 $processedProductPriceCache[$PRODUCT_ID][$priceType][$hash] = $priceResult->getId();
1265 }
1266 else
1267 {
1268 $strPriceErr = implode('; ', $priceResult->getErrorMessages());
1269 if ($strPriceErr !== '')
1270 $strPriceErr = GetMessage('CATI_ERR_PRICE_ADD').$strPriceErr;
1271 else
1272 $strPriceErr = GetMessage('CATI_ERR_PRICE_ADD_UNKNOWN');
1273 }
1274 unset($priceResult);
1275 }
1276 }
1277 if ('' != $strPriceErr)
1278 {
1279 $strErrorR .= GetMessage("CATI_LINE_NO")." ".$line_num.". ".$strPriceErr.'<br>';
1280 break;
1281 }
1282 else
1283 {
1284 $updateFacet = true;
1285 }
1286 }
1287 }
1288 }
1289 }
1290 }
1291
1292 if ('' == $strErrorR)
1293 {
1294 $correct_lines++;
1295 if ($previousProductId === false)
1296 $previousProductId = $PRODUCT_ID;
1297 if ($previousProductId != $PRODUCT_ID)
1298 {
1299 CIBlockElement::UpdateSearch($previousProductId, true);
1300 $ipropValues = new \Bitrix\Iblock\InheritedProperty\ElementValues($IBLOCK_ID, $previousProductId);
1301 $ipropValues->clearValues();
1302 unset($ipropValues);
1303 if ($updateFacet)
1304 {
1305 if (isset($newProducts[$previousProductId]))
1306 CCatalogSKU::ClearCache();
1307 }
1308 $updateFacet = false;
1309 if (!empty($productPriceCache[$previousProductId]))
1310 {
1311 foreach ($productPriceCache[$previousProductId] as $priceTypeRows)
1312 {
1313 if (!empty($priceTypeRows) && is_array($priceTypeRows))
1314 {
1315 foreach ($priceTypeRows as $priceId)
1316 {
1317 $priceResult = Catalog\Model\Price::delete($priceId);
1318 if (!$priceResult->isSuccess())
1319 {
1320 $strPriceErr = implode('; ', $priceResult->getErrorMessages());
1321 if ($strPriceErr !== '')
1322 $strPriceErr = GetMessage('CATI_ERR_PRICE_DELETE').$strPriceErr;
1323 else
1324 $strPriceErr = GetMessage('CATI_ERR_PRICE_DELETE');
1325 $strErrorR .= GetMessage("CATI_LINE_NO")." ".$line_num.". ".$strPriceErr.'<br>';
1326 break 2;
1327 }
1328 }
1329 }
1330 }
1331 unset($productPriceCache[$previousProductId]);
1332 }
1333 if (!empty($processedProductPriceCache[$previousProductId]))
1334 unset($processedProductPriceCache[$previousProductId]);
1335
1336 if (isset($arIBlockPropertyValue[$previousProductId]))
1337 {
1338 unset($arIBlockPropertyValue[$previousProductId]);
1339 }
1340 if (isset($multiplePropertyValuesCheck[$previousProductId]))
1341 {
1342 unset($multiplePropertyValuesCheck[$previousProductId]);
1343 }
1344 if (isset($currentProductSection[$previousProductId]))
1345 {
1346 unset($currentProductSection[$previousProductId]);
1347 }
1348 if (isset($arProductGroups[$previousProductId]))
1349 {
1350 unset($arProductGroups[$previousProductId]);
1351 }
1352
1353 $previousProductId = $PRODUCT_ID;
1354 }
1355 }
1356 else
1357 {
1358 $error_lines++;
1359 $strImportErrorMessage .= $strErrorR;
1360 }
1361
1362 if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time))) break;
1363 }
1364 while ($arRes = $csvFile->Fetch());
1365 }
1366 if ($PRODUCT_ID > 0)
1367 {
1368 CIBlockElement::UpdateSearch($PRODUCT_ID, true);
1369 $ipropValues = new \Bitrix\Iblock\InheritedProperty\ElementValues($IBLOCK_ID, $PRODUCT_ID);
1370 $ipropValues->clearValues();
1371 unset($ipropValues);
1372 if ($updateFacet)
1373 {
1374 if (isset($newProducts[$PRODUCT_ID]))
1375 CCatalogSKU::ClearCache();
1376 }
1377 $updateFacet = false;
1378
1379 if (!empty($productPriceCache[$PRODUCT_ID]))
1380 {
1381 foreach ($productPriceCache[$PRODUCT_ID] as $priceTypeRows)
1382 {
1383 if (!empty($priceTypeRows) && is_array($priceTypeRows))
1384 {
1385 foreach ($priceTypeRows as $priceId)
1386 {
1387 $priceResult = Catalog\Model\Price::delete($priceId);
1388 if (!$priceResult->isSuccess())
1389 {
1390 $strPriceErr = implode('; ', $priceResult->getErrorMessages());
1391 if ($strPriceErr !== '')
1392 $strPriceErr = GetMessage('CATI_ERR_PRICE_DELETE').$strPriceErr;
1393 else
1394 $strPriceErr = GetMessage('CATI_ERR_PRICE_DELETE');
1395 $strErrorR .= GetMessage("CATI_LINE_NO")." ".$line_num.". ".$strPriceErr.'<br>';
1396 break 2;
1397 }
1398 }
1399 }
1400 }
1401 unset($productPriceCache[$PRODUCT_ID]);
1402 }
1403 if (!empty($processedProductPriceCache[$PRODUCT_ID]))
1404 unset($processedProductPriceCache[$PRODUCT_ID]);
1405 }
1410
1412// start additional actions //
1414
1415 // activate 'in-file' sections
1416 if ($bAllLinesLoaded && $bThereIsGroups && $inFileAction == 'A' && !$bDeactivationStarted)
1417 {
1418 $res = CIBlockSection::GetList(
1419 array(),
1420 array("IBLOCK_ID" => $IBLOCK_ID, "TMP_ID" => $tmpid, "ACTIVE" => "N", 'CHECK_PERMISSIONS' => 'N'),
1421 false,
1422 array('ID', 'NAME')
1423 );
1424 while($arr = $res->Fetch())
1425 {
1426 $bs->Update($arr["ID"], array("NAME"=>$arr["NAME"], "ACTIVE" => "Y"));
1427 if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time)))
1428 break;
1429 }
1430 }
1431
1432 // activate 'in-file' elements
1433 if ($bAllLinesLoaded && $inFileAction=="A" && !$bDeactivationStarted)
1434 {
1436 $res = CIBlockElement::GetList(
1437 array(),
1438 array("IBLOCK_ID" => $IBLOCK_ID, "TMP_ID" => $tmpid, "ACTIVE" => "N"),
1439 false,
1440 false,
1441 array('ID')
1442 );
1443 while($arr = $res->Fetch())
1444 {
1445 $el->Update($arr["ID"], array("ACTIVE" => "Y"));
1446 if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time)))
1447 break;
1448 }
1451 }
1452
1453 // update or delete 'not-in-file sections'
1454 if ($bAllLinesLoaded && $outFileAction != 'F' && $bThereIsGroups)
1455 {
1456 if ($outFileAction == "D")
1458 $res = CIBlockSection::GetList(
1459 array(),
1460 array("IBLOCK_ID" => $IBLOCK_ID, "!TMP_ID" => $tmpid, 'CHECK_PERMISSIONS' => 'N'),
1461 false,
1462 array('ID', 'NAME')
1463 );
1464
1465 while($arr = $res->Fetch())
1466 {
1467 if ($outFileAction=="D")
1468 {
1469 CIBlockSection::Delete($arr["ID"]);
1470 }
1471 elseif ($outFileAction == 'H' || $outFileAction == 'M') // H or M
1472 {
1473 $bDeactivationStarted = true;
1474 $bs->Update($arr["ID"], array("NAME"=>$arr["NAME"], "ACTIVE" => "N", "TMP_ID" => $tmpid));
1475 }
1476
1477 if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time)))
1478 break;
1479 }
1480 if ($outFileAction == "D")
1481 {
1484 }
1485 }
1486
1487 // update or delete 'not-in-file' elements
1488 if ($bAllLinesLoaded && $outFileAction != "F")
1489 {
1491 if ($bIBlockIsCatalog && $outFileAction=="M")
1492 {
1494 $arProductArray['TMP_ID'] = $tmpid;
1495 $filter = array('=IBLOCK_ELEMENT.IBLOCK_ID' => $IBLOCK_ID, '!=TMP_ID' => $tmpid);
1496 if (!$separateSku)
1497 {
1499 }
1500 $res = Catalog\Model\Product::getList(array(
1501 'select' => array('ID'),
1502 'filter' => $filter,
1503 'order' => array('ID' => 'ASC')
1504 ));
1505 while($arr = $res->fetch())
1506 {
1507 $result = Catalog\Model\Product::update($arr['ID'], $arProductArray);
1508 $killed_lines++;
1509
1510 if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time)))
1511 break;
1512 }
1513 unset($arr, $res);
1514 }
1515 else
1516 {
1517 $res = CIBlockElement::GetList(
1518 array('ID' => 'ASC'),
1519 array("IBLOCK_ID" => $IBLOCK_ID, "!TMP_ID" => $tmpid),
1520 false,
1521 false,
1522 array('ID')
1523 );
1524 while($arr = $res->Fetch())
1525 {
1526 if ($outFileAction == "D")
1527 {
1528 CIBlockElement::Delete($arr["ID"]);
1529 $killed_lines++;
1530 }
1531 elseif ($outFileAction == "H") // H
1532 {
1533 $bDeactivationStarted = true;
1534 $el->Update($arr["ID"], array("ACTIVE" => "N", "TMP_ID" => $tmpid));
1535 $killed_lines++;
1536 }
1537
1538 if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time)))
1539 break;
1540 }
1541 unset($arr, $res);
1542 }
1545 }
1546
1547 // delete 'not-in-file' element prices
1548 if ($bAllLinesLoaded && $bIBlockIsCatalog && 'Y' == $bUpdatePrice && $outFileAction=="D")
1549 {
1550 $filter = array(
1551 '=ELEMENT.IBLOCK_ID' => $IBLOCK_ID,
1552 '!=TMP_ID' => $tmpid
1553 );
1554 if (!$separateSku)
1555 {
1556 $filter['!=PRODUCT.TYPE'] = Catalog\ProductTable::TYPE_SKU;
1557 }
1559 $res = Catalog\Model\Price::getList(array(
1560 'select' => array('ID'),
1561 'filter' => $filter
1562 ));
1563 while($arr = $res->fetch())
1564 {
1565 $priceResult = Catalog\Model\Price::delete($arr['ID']);
1566
1567 if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time)))
1568 break;
1569 }
1572 }
1573
1574 if (!$bAllLinesLoaded)
1575 {
1576 $bAllDataLoaded = false;
1577
1579 "tmpid,line_num,correct_lines,"
1580 . "error_lines,killed_lines,"
1581 . "arIBlockProperty,arIBlockPropertyValue,"
1582 . "multiplePropertyValuesCheck,"
1583 . "bThereIsGroups,"
1584 . "bDeactivationStarted,"
1585 . "arProductGroups,"
1586 . "currentProductSection,"
1587 . "bUpdatePrice"
1588 ;
1589 $SETUP_VARS_LIST = "IBLOCK_ID,URL_DATA_FILE,fields_type,first_names_r,delimiter_r,delimiter_other_r,first_names_f,metki_f,PATH2IMAGE_FILES,outFileAction,inFileAction,max_execution_time,IMAGE_RESIZE,USE_TRANSLIT,TRANSLIT_LANG,CLEAR_EMPTY_PRICE,CML2_LINK_IS_XML";
1590 for ($i = 0; $i < $NUM_FIELDS; $i++)
1591 $SETUP_VARS_LIST .= ",field_".$i;
1592 $CUR_FILE_POS = $csvFile->GetPos();
1593 }
1594 else
1595 {
1596 CIBlock::enableClearTagCache();
1597 CIBlock::clearIblockTagCache($IBLOCK_ID);
1598 }
1599}
1600
1602{
1603 if (isset($USER_TMP))
1604 {
1605 $USER = $USER_TMP;
1606 unset($USER_TMP);
1607 }
1608}
$hash
Определения ajax_redirector.php:8
global $APPLICATION
Определения include.php:80
static isUsedInventoryManagement()
Определения state.php:42
static enableDeferredCalculation()
Определения sku.php:87
static disableDeferredCalculation()
Определения sku.php:97
static calculate()
Определения sku.php:450
const STATUS_YES
Определения product.php:66
static getDefaultAvailableSettings()
Определения product.php:908
const TYPE_SKU
Определения product.php:72
const STATUS_NO
Определения product.php:67
static disableDeferredIndexing()
Определения manager.php:300
static runDeferredIndexing($iblockId)
Определения manager.php:321
static enableDeferredIndexing()
Определения manager.php:290
static IsUserExists()
Определения catalog.php:1812
static GetByID($ID)
Определения language.php:99
static GetInstance()
Определения virtual_io.php:60
Определения csv_data.php:10
const FIELDS_PRICE
Определения csv_settings.php:9
static getDefaultSettings($type, $extFormat=false)
Определения csv_settings.php:335
const FIELDS_CURRENCY
Определения csv_settings.php:12
static getSettingsFields($type, $extFormat=false)
Определения csv_settings.php:14
const FIELDS_PRICE_EXT
Определения csv_settings.php:10
const FIELDS_ELEMENT
Определения csv_settings.php:7
const FIELDS_CATALOG
Определения csv_settings.php:8
const FIELDS_SECTION
Определения csv_settings.php:11
static GetList($arOrder=array(), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения catalog.php:15
static Add($arFields)
Определения iblockpropertyenum.php:127
static GetList($arOrder=array("SORT"=>"ASC", "VALUE"=>"ASC"), $arFilter=array())
Определения iblockpropertyenum.php:18
static IncludeModule($module_name)
Определения module.php:151
$startImportExecTime
Определения commerceml_g_run.php:20
global $strImportOKMessage
Определения commerceml_g_run.php:35
global $strImportErrorMessage
Определения commerceml_g_run.php:35
if(!function_exists("file_get_contents")) $DATA_FILE_NAME
Определения commerceml_run.php:307
if(''===$strImportErrorMessage) if(''===$strImportErrorMessage) $USE_TRANSLIT
Определения commerceml_run.php:388
$arFields
Определения dblapprove.php:5
$arr
Определения file_new.php:624
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$filter
Определения iblock_catalog_list.php:54
const BX_CAT_CRON
Определения cron_frame.php:16
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $arCatalogAvailPriceFields
Определения cron_frame.php:84
global $defCatalogAvailValueFields
Определения cron_frame.php:97
global $arCatalogAvailQuantityFields
Определения cron_frame.php:88
global $defCatalogAvailProdFields
Определения cron_frame.php:93
global $defCatalogAvailQuantityFields
Определения cron_frame.php:99
global $arCatalogAvailProdFields
Определения cron_frame.php:82
global $defCatalogAvailCurrencies
Определения cron_frame.php:103
global $arCatalogAvailGroupFields
Определения cron_frame.php:90
global $arCatalogAvailValueFields
Определения cron_frame.php:86
global $defCatalogAvailPriceFields
Определения cron_frame.php:95
global $defCatalogAvailGroupFields
Определения cron_frame.php:101
$arSku
Определения csv_new_run.php:183
$IBLOCK_ID
Определения csv_new_run.php:168
$SETUP_VARS_LIST
Определения csv_new_run.php:37
global $USER
Определения csv_new_run.php:40
if(empty($arRunErrors)) $CML2_LINK_IS_XML
Определения csv_new_run.php:209
$NUM_CATALOG_LEVELS
Определения csv_new_run.php:124
$bTmpUserCreated
Определения csv_new_run.php:41
$INTERNAL_VARS_LIST
Определения csv_new_run.php:38
if(!file_exists($_SERVER["DOCUMENT_ROOT"]. $strFile)) $bFirstLoadStep
Определения cron_frame.php:74
if(false===$arIBlock) if(''==$strImportErrorMessage) if(''==$strImportErrorMessage) if(''==$strImportErrorMessage) if(''==$strImportErrorMessage) $IMAGE_RESIZE
Определения csv_new_run.php:322
$max_execution_time
Определения csv_new_run.php:85
$bAllLinesLoaded
Определения csv_new_run.php:96
$CLEAR_EMPTY_PRICE
Определения csv_new_run.php:323
$io
Определения csv_new_run.php:98
$separateSku
Определения csv_new_run.php:94
const START_EXEC_TIME
Определения start.php:12
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
Rel2Abs($curdir, $relpath)
Определения tools.php:3297
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$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
$arRes
Определения options.php:104
$arFilter
Определения user_search.php:106
$arIBlock['PROPERTY']
Определения yandex_detail.php:172
$arCatalog
Определения yandex_run.php:674
if(!empty($XML_DATA['PRICE'])) $priceTypeList
Определения yandex_run.php:872