234 global $boolTranslitSection, $arTranslitSection;
238 $arChld = $arGrTmp[$tmpid.$parent];
239 if(!is_array($arChld))
return;
240 for(
$i=0, $intCount =
count($arChld);
$i<$intCount;
$i++)
242 $GROUP_XML_ID = $arChld[
$i][
"GROUP_XML_ID"];
243 $GROUP_NAME = $arChld[
$i][
"GROUP_NAME"];
245 $bs =
new CIBlockSection();
246 $res = CIBlockSection::GetList(
array(), Array(
"XML_ID"=>$GROUP_XML_ID,
"IBLOCK_ID"=>
$IBLOCK_ID,
'CHECK_PERMISSIONS' =>
'N'));
247 $bNewGroup_tmp = False;
250 $GROUP_ID =
$arr[
"ID"];
254 "IBLOCK_SECTION_ID"=>$parent_id
256 if ($boolTranslitSection)
257 $arFields[
'CODE'] = CUtil::translit($GROUP_NAME,
'ru', $arTranslitSection);
264 $bNewGroup_tmp = True;
267 "IBLOCK_SECTION_ID"=>$parent_id,
271 "XML_ID"=>$GROUP_XML_ID
273 if ($boolTranslitSection)
274 $arFields[
'CODE'] = CUtil::translit($GROUP_NAME,
'ru', $arTranslitSection);
276 $res = ($GROUP_ID>0);
281 $strImportErrorMessage .= str_replace(
"#ERROR#", $bs->LAST_ERROR, str_replace(
"#NAME#",
"[".$GROUP_ID.
"] \"".$GROUP_NAME.
"\" (".$GROUP_XML_ID.
")",
GetMessage(
"CICML_ERROR_ADD_SECTION"))).
".<br>";
295if (!function_exists(
"file_get_contents"))
299 $fd = fopen(
"$filename",
"rb");
314if (isset($_FILES[
"FILE_1C"]) && is_uploaded_file($_FILES[
"FILE_1C"][
"tmp_name"]))
319 if ($URL_FILE_1C <>
'')
321 $URL_FILE_1C =
Rel2Abs(
"/", $URL_FILE_1C);
322 if (file_exists(
$_SERVER[
"DOCUMENT_ROOT"].$URL_FILE_1C) && is_file(
$_SERVER[
"DOCUMENT_ROOT"].$URL_FILE_1C))
347 if ($iblocks->ExtractFields(
"f_"))
354if ($outFileAction!=
"F" && $outFileAction!=
"H" && $outFileAction!=
"D")
357if ($outFileAction!=
"F" && $outFileAction!=
"H")
358 $outFileAction =
"D";
365 if (!$xml_content || $xml_content ==
'')
371 if ($CONVERT_UTF8 !=
"Y" && $CONVERT_UTF8 !=
"N")
378 if (!$xml_content || $xml_content ==
'')
391if (!isset($keepExistingProperties))
393 $keepExistingProperties = ($outFileAction =
"D" ?
'N' :
'Y');
397 $keepExistingProperties = (
'N' == $keepExistingProperties ?
'N' :
'Y');
404include(__DIR__.
'/ru/commerceml_run_name.php');
410 $xml->LoadString($xml_content);
412 $comm = $xml->select_nodes(
"/BizTalk/Body/".
$nameUTF[
'CommerceInfo']);
413 if (!is_object($comm[0]))
415 $comm = $xml->select_nodes(
"/".
$nameUTF[
'CommerceInfo']);
416 if (!is_object($comm[0]))
419 $strVersion = $comm[0]->GetAttribute(
$nameUTF[
'CommerceInfoVersion']);
420 if (
null !== $strVersion)
422 if (version_compare($strVersion,
'2.0') >= 0)
427 if ($comm[0]->name ==
$nameUTF[
'Yandex'])
435 $arPriceType =
array();
436 $offerlists = $comm[0]->select_nodes(
"/".
$nameUTF[
'OffersList']);
437 if (is_array($offerlists))
439 for (
$i = 0, $intOFCount =
count($offerlists);
$i < $intOFCount;
$i++)
441 $xOfferListNode = $offerlists[
$i];
443 $props = $xOfferListNode->select_nodes(
"/".
$nameUTF[
'PropertyValue']);
444 for ($j = 0, $intPropCount =
count(
$props); $j < $intPropCount; $j++)
454 if (!$dbSite->Fetch())
457 $arSite = $dbSite->Fetch();
462 $el =
new CIBlockElement();
464 $tmpid = md5(uniqid(
""));
465 $arCatalogs =
array();
466 $arCatalogsParams =
array();
467 $catalogs = $comm[0]->select_nodes(
"/".
$nameUTF[
'Catalog']);
468 if (is_array($catalogs))
470 for (
$i = 0, $intCatCount =
count($catalogs);
$i < $intCatCount;
$i++)
472 $xCatNode = $catalogs[
$i];
474 $IBLOCK_XML_ID = $xCatNode->GetAttribute(
$nameUTF[
'ID']);
475 $IBLOCK_NAME = $xCatNode->GetAttribute(
$nameUTF[
'Name']);
476 $IBLOCK_DESC = $xCatNode->GetAttribute(
$nameUTF[
'Description']);
479 $bNewRecord_tmp =
false;
480 if ($res_arr =
$res->Fetch())
485 "NAME" => $IBLOCK_NAME,
487 "DESCRIPTION" => $IBLOCK_DESC
494 $bNewRecord_tmp =
true;
497 "NAME" => $IBLOCK_NAME,
498 "XML_ID" => $IBLOCK_XML_ID,
508 'DEFAULT_VALUE' =>
array(
509 'TRANSLITERATION' =>
'Y',
512 'SECTION_CODE' =>
array(
513 'DEFAULT_VALUE' =>
array(
514 'TRANSLITERATION' =>
'Y',
534 $boolTranslitElement =
false;
535 $boolTranslitSection =
false;
536 $arTranslitElement =
array();
537 $arTranslitSection =
array();
539 if (
'Y' == $boolIBlockTranslit)
541 $boolOutTranslit =
false;
543 if (isset(
$arIBlock[
'FIELDS'][
'CODE'][
'DEFAULT_VALUE']))
545 if (
'Y' ==
$arIBlock[
'FIELDS'][
'CODE'][
'DEFAULT_VALUE'][
'TRANSLITERATION']
546 &&
'Y' ==
$arIBlock[
'FIELDS'][
'CODE'][
'DEFAULT_VALUE'][
'USE_GOOGLE'])
548 $boolOutTranslit =
true;
551 if (isset(
$arIBlock[
'FIELDS'][
'SECTION_CODE'][
'DEFAULT_VALUE']))
553 if (
'Y' ==
$arIBlock[
'FIELDS'][
'SECTION_CODE'][
'DEFAULT_VALUE'][
'TRANSLITERATION']
554 &&
'Y' ==
$arIBlock[
'FIELDS'][
'SECTION_CODE'][
'DEFAULT_VALUE'][
'USE_GOOGLE'])
556 $boolOutTranslit =
true;
559 if ($boolOutTranslit)
561 $boolIBlockTranslit =
'N';
567 if (
'Y' == $boolIBlockTranslit)
569 if (isset(
$arIBlock[
'FIELDS'][
'CODE'][
'DEFAULT_VALUE']))
571 $arTransSettings =
$arIBlock[
'FIELDS'][
'CODE'][
'DEFAULT_VALUE'];
572 $boolTranslitElement = (
'Y' == $arTransSettings[
'TRANSLITERATION'] ? true :
false);
573 $arTranslitElement =
array(
574 "max_len" => $arTransSettings[
'TRANS_LEN'],
575 "change_case" => $arTransSettings[
'TRANS_CASE'],
576 "replace_space" => $arTransSettings[
'TRANS_SPACE'],
577 "replace_other" => $arTransSettings[
'TRANS_OTHER'],
578 "delete_repeat_replace" => (
'Y' == $arTransSettings[
'TRANS_EAT'] ?
true :
false),
579 "use_google" => (
'Y' == $arTransSettings[
'USE_GOOGLE'] ?
true :
false),
582 if (isset(
$arIBlock[
'FIELDS'][
'SECTION_CODE'][
'DEFAULT_VALUE']))
584 $arTransSettings =
$arIBlock[
'FIELDS'][
'SECTION_CODE'][
'DEFAULT_VALUE'];
585 $boolTranslitSection = (
'Y' == $arTransSettings[
'TRANSLITERATION'] ? true :
false);
586 $arTranslitSection =
array(
587 "max_len" => $arTransSettings[
'TRANS_LEN'],
588 "change_case" => $arTransSettings[
'TRANS_CASE'],
589 "replace_space" => $arTransSettings[
'TRANS_SPACE'],
590 "replace_other" => $arTransSettings[
'TRANS_OTHER'],
591 "delete_repeat_replace" => (
'Y' == $arTransSettings[
'TRANS_EAT'] ?
true :
false),
592 "use_google" => (
'Y' == $arTransSettings[
'USE_GOOGLE'] ?
true :
false),
608 $ibp =
new CIBlockProperty();
611 for ($j = 0, $intPropCount =
count(
$props); $j < $intPropCount; $j++)
615 $PROP_XML_ID = $xPropNode->GetAttribute(
$nameUTF[
'ID']);
616 $PROP_TYPE = $xPropNode->GetAttribute(
$nameUTF[
'DataType']);
617 $PROP_MULTIPLE = ($xPropNode->GetAttribute(
$nameUTF[
'Multiple']) ==
"1" ?
"Y" :
"N");
618 $PROP_NAME = $xPropNode->GetAttribute(
$nameUTF[
'Name']);
619 $PROP_DEF = $xPropNode->GetAttribute(
$nameUTF[
'DefaultValue']);
620 if ($PROP_TYPE ==
"enumeration")
625 if ($arPriceType[$IBLOCK_XML_ID] == $PROP_XML_ID)
629 $bNewRecord_tmp =
false;
630 if ($res_arr =
$res->Fetch())
632 $PROP_ID = $res_arr[
"ID"];
633 $res = $ibp->Update($PROP_ID,
635 "NAME" => $PROP_NAME,
636 "TYPE" => $PROP_TYPE,
637 "MULTIPLE" => $PROP_MULTIPLE,
638 "DEFAULT_VALUE" => $PROP_DEF,
645 $bNewRecord_tmp =
true;
647 "NAME" => $PROP_NAME,
650 "DEFAULT_VALUE" => $PROP_DEF,
651 "XML_ID" => $PROP_XML_ID,
653 "MULTIPLE" => $PROP_MULTIPLE,
654 "PROPERTY_TYPE" => $PROP_TYPE,
658 $res = (intval($PROP_ID) > 0);
663 $strImportErrorMessage .= str_replace(
"#ERROR#", $ibp->LAST_ERROR, str_replace(
"#NAME#",
"[".$PROP_ID.
"] \"".$PROP_NAME.
"\" (".$PROP_XML_ID.
")",
GetMessage(
"CICML_ERROR_ADD_PROPS"))).
".<br>";
674 if ($PROP_TYPE ==
"L")
677 $arPropertiesEnum[$PROP_XML_ID] =
array();
678 $prop_enums = $xPropNode->select_nodes(
"/".
$nameUTF[
'PropertyVariant']);
679 for (
$k = 0, $intEnumPropCount =
count($prop_enums);
$k < $intEnumPropCount;
$k++)
681 $xPropEnum = $prop_enums[
$k];
682 $PROP_ENUM_XML_ID = $xPropEnum->GetAttribute(
$nameUTF[
'ID']);
683 $PROP_ENUM_NAME = $xPropEnum->GetAttribute(
$nameUTF[
'Name']);
684 $PROP_ENUM_DEF = ($PROP_ENUM_XML_ID == $PROP_DEF ?
"Y" :
"N");
687 "DEF" => $PROP_ENUM_DEF,
689 "VALUE" => $PROP_ENUM_NAME,
690 "PROPERTY_ID" => $PROP_ID,
691 "XML_ID" => $PROP_ENUM_XML_ID
696 $PROP_ENUM_ID =
$arr[
"ID"];
703 $arPropertiesEnum[$PROP_XML_ID][$PROP_ENUM_XML_ID] = $PROP_ENUM_ID;
708 if (function_exists(
"catalog_property_mutator_1c"))
709 catalog_property_mutator_1c();
713 for ($j = 0, $intGroupCount =
count(
$groups); $j < $intGroupCount; $j++)
717 $GROUP_XML_ID = $xGroupNode->GetAttribute(
$nameUTF[
'ID']);
718 $GROUP_PARENT_XML_ID = $xGroupNode->GetAttribute(
$nameUTF[
'ParentCategory']);
719 $GROUP_NAME = $xGroupNode->GetAttribute(
$nameUTF[
'Name']);
721 $arGrTmp[$tmpid.$GROUP_PARENT_XML_ID][] =
array(
722 "GROUP_XML_ID" => $GROUP_XML_ID,
723 "GROUP_PARENT_XML_ID" => $GROUP_PARENT_XML_ID,
724 "GROUP_NAME" => $GROUP_NAME
732 $arProducts =
array();
733 $products = $xCatNode->select_nodes(
"/".
$nameUTF[
'Product']);
734 for ($j = 0, $intProdCount =
count($products); $j < $intProdCount; $j++)
736 $xProductNode = $products[$j];
738 $PRODUCT_XML_ID = $xProductNode->GetAttribute(
$nameUTF[
'ID']);
739 $PRODUCT_PARENT_XML_ID = $xProductNode->GetAttribute(
$nameUTF[
'ParentCategory']);
740 $PRODUCT_NAME = $xProductNode->GetAttribute(
$nameUTF[
'Name']);
743 $GROUPS_ID =
array();
744 if ($PRODUCT_PARENT_XML_ID <>
'' &&
$arGroups[$PRODUCT_PARENT_XML_ID] <>
'')
745 $GROUPS_ID[] =
$arGroups[$PRODUCT_PARENT_XML_ID];
747 $prod_groups = $xProductNode->select_nodes(
"/".
$nameUTF[
'CategoryReference']);
748 for (
$k = 0, $intProdGroupCount =
count($prod_groups);
$k < $intProdGroupCount;
$k++)
750 $xProductGroupsNode = $prod_groups[
$k];
751 $PRODUCT_GROUP_XML_ID = $xProductGroupsNode->GetAttribute(
$nameUTF[
'IdInCatalog']);
752 if (
$arGroups[$PRODUCT_GROUP_XML_ID] <>
'')
753 $GROUPS_ID[] =
$arGroups[$PRODUCT_GROUP_XML_ID];
756 $prop_vals = $xProductNode->select_nodes(
"/".
$nameUTF[
'PropertyValue']);
757 for (
$k = 0, $intPropValCount =
count($prop_vals);
$k < $intPropValCount;
$k++)
759 $xPropertyValueNode = $prop_vals[
$k];
761 $PROP_VAL_PROPERTY_XML_ID = $xPropertyValueNode->GetAttribute(
$nameUTF[
'PropertyId']);
762 $PROP_VAL_VALUE = $xPropertyValueNode->GetAttribute(
$nameUTF[
'Value']);
765 if (is_array($arPropertiesEnum[$PROP_VAL_PROPERTY_XML_ID]))
767 if ($arPropertiesEnum[$PROP_VAL_PROPERTY_XML_ID][$PROP_VAL_VALUE] <>
'')
768 $PROP[
$arProperties[$PROP_VAL_PROPERTY_XML_ID]][] = $arPropertiesEnum[$PROP_VAL_PROPERTY_XML_ID][$PROP_VAL_VALUE];
771 $PROP[
$arProperties[$PROP_VAL_PROPERTY_XML_ID]][] = $PROP_VAL_VALUE;
775 $arLoadProductArray =
array(
776 "MODIFIED_BY" =>
$USER->GetID(),
777 "IBLOCK_SECTION" => $GROUPS_ID,
779 "NAME" => $PRODUCT_NAME,
780 "XML_ID" => $PRODUCT_XML_ID,
782 "PROPERTY_VALUES" => $PROP
784 if ($boolTranslitElement)
785 $arLoadProductArray[
'CODE'] =
CUtil::translit($PRODUCT_NAME,
'ru', $arTranslitElement);
788 $bNewRecord_tmp =
false;
791 $PRODUCT_ID =
$arr[
"ID"];
793 $arLoadProductArray[
'ACTIVE'] =
'Y';
794 if (function_exists(
"catalog_product_mutator_1c"))
796 $arLoadProductArray = catalog_product_mutator_1c($arLoadProductArray, $xProductNode,
false);
798 $res = $el->Update($PRODUCT_ID, $arLoadProductArray);
802 $bNewRecord_tmp =
true;
803 $arLoadProductArray[
"ACTIVE"] =
"Y";
804 if (function_exists(
"catalog_product_mutator_1c"))
805 $arLoadProductArray = catalog_product_mutator_1c($arLoadProductArray, $xProductNode,
true);
806 $PRODUCT_ID = $el->Add($arLoadProductArray);
807 $res = ($PRODUCT_ID > 0);
812 $strImportErrorMessage .= str_replace(
"#ERROR#", $el->LAST_ERROR, str_replace(
"#NAME#",
"[".$PRODUCT_ID.
"] \"".$PRODUCT_NAME.
"\" (".$PRODUCT_XML_ID.
")",
GetMessage(
"CICML_ERROR_ADDING_PRODUCT"))).
".<br>";
820 $arProducts[$PRODUCT_XML_ID] = $PRODUCT_ID;
824 $arCatalogsParams[$IBLOCK_XML_ID] =
array(
826 "arPropertiesEnum" => $arPropertiesEnum,
828 "arProducts" => $arProducts
832 if (
'N' == $keepExistingProperties)
847 if ($outFileAction !=
"F")
849 $bs =
new CIBlockSection;
853 if ($outFileAction !=
"H")
859 $bs->Update(
$arr[
"ID"],
array(
"NAME" =>
$arr[
"NAME"],
"ACTIVE" =>
"N"));
866 if ($outFileAction !=
"H")
872 $el->Update(
$arr[
"ID"],
array(
"ACTIVE" =>
"N"));
883 include(__DIR__.
'/ru/commerceml_run_cur.php');
893 $arProductsTmpA = $arCatalogsParams;
895 if (is_array($offerlists))
897 for (
$i = 0, $intOFListCount =
count($offerlists);
$i < $intOFListCount;
$i++)
899 $xOfferListNode = $offerlists[
$i];
901 $IBLOCK_XML_ID = $xOfferListNode->GetAttribute(
$nameUTF[
'CatalogID']);
902 $OFFER_LIST_DESC = $xOfferListNode->GetAttribute(
$nameUTF[
'Description']);
904 if ($OFFER_LIST_CURRENCY ==
'')
905 $OFFER_LIST_CURRENCY =
"USD";
908 $props = $xOfferListNode->select_nodes(
"/".
$nameUTF[
'PropertyValue']);
909 if (!is_object(
$props[0]))
915 $PRICE_ID =
$arr[
"ID"];
919 "NAME" => $PRICE_TYPE,
920 "USER_LANG" =>
array(
"ru" => $PRICE_TYPE)
924 $arProducts = $arCatalogsParams[$IBLOCK_XML_ID][
"arProducts"];
927 $offers = $xOfferListNode->select_nodes(
"/".
$nameUTF[
'Offer']);
929 for ($j = 0, $intOtOFCount =
count($offers); $j < $intOtOFCount; $j++)
931 $xOfferNode = $offers[$j];
933 $PRODUCT_XML_ID = $xOfferNode->GetAttribute(
$nameUTF[
'ProductId']);
938 if (!isset($arProducts[$PRODUCT_XML_ID]))
940 if (!isset($arIBlockCacheTmp[$IBLOCK_XML_ID])
941 || intval($arIBlockCacheTmp[$IBLOCK_XML_ID]) <= 0)
944 if ($ar_res_tmp = $db_res_tmp->Fetch())
946 $arIBlockCacheTmp[$IBLOCK_XML_ID] = intval($ar_res_tmp[
"ID"]);
951 if ($ar_res_tmp = $db_res_tmp->Fetch())
953 $PRODUCT_ID = intval($ar_res_tmp[
"ID"]);
954 $arCatalogsParams[$IBLOCK_XML_ID][
"arProducts"][$PRODUCT_XML_ID] = $PRODUCT_ID;
959 $PRODUCT_ID = intval($arProducts[$PRODUCT_XML_ID]);
962 if ($PRODUCT_ID <= 0)
965 unset($arProductsTmpA[$IBLOCK_XML_ID][
"arProducts"][$PRODUCT_XML_ID]);
967 $OFFER_PRICE = DoubleVal(str_replace(
",",
".", $xOfferNode->GetAttribute(
$nameUTF[
'Price'])));
968 $OFFER_UPAK = $xOfferNode->GetAttribute(
$nameUTF[
'Package']);
969 $OFFER_QUANTITY = intval($xOfferNode->GetAttribute(
$nameUTF[
'Amount']));
970 $OFFER_UNIT = $xOfferNode->GetAttribute(
$nameUTF[
'Unit']);
972 if ($OFFER_CURRENCY ==
'')
973 $OFFER_CURRENCY = $OFFER_LIST_CURRENCY;
975 $arLoadOfferArray =
array(
977 "QUANTITY" => $OFFER_QUANTITY
979 if (function_exists(
"catalog_offer_mutator_1c"))
981 $arLoadOfferArray = catalog_offer_mutator_1c($arLoadOfferArray, $xOfferNode);
987 "PRODUCT_ID" => $PRODUCT_ID,
988 "CATALOG_GROUP_ID" => $PRICE_ID,
989 "PRICE" => $OFFER_PRICE,
990 "CURRENCY" => $OFFER_CURRENCY
996 "PRODUCT_ID" => $PRODUCT_ID,
997 "CATALOG_GROUP_ID" => $PRICE_ID
1008 if (COption::GetOptionString(
"catalog",
"deactivate_1c_no_price",
"N")==
"Y")
1010 foreach ($arProductsTmpA as $keyA=>$valA)
1012 foreach ($valA[
"arProducts"] as $keyB=>$valB)
1014 $res = $el->Update(intval($valB), Array(
"ACTIVE" =>
"N"));
1051 if (isset($USER_TMP))