Beispiel #1
0
 public static function UpdatePropertyList($prop_id, $list)
 {
     foreach ($list as $id => $arEnum) {
         $value = trim($arEnum["VALUE"], " \t\n\r");
         if (strlen($value)) {
             $dbEnum = CIBlockPropertyEnum::GetByID($id);
             if (is_array($dbEnum)) {
                 $def = isset($arEnum["DEF"]) ? $arEnum["DEF"] : $dbEnum["DEF"];
                 $sort = intval($arEnum["SORT"]);
                 if ($dbEnum["VALUE"] != $value || $dbEnum["SORT"] != $sort || $dbEnum["DEF"] != $def) {
                     $dbEnum["VALUE"] = $value;
                     $dbEnum["SORT"] = $sort;
                     $dbEnum["DEF"] = $def;
                     unset($dbEnum["ID"]);
                     CIBlockPropertyEnum::Update($id, $dbEnum);
                 }
             } else {
                 $arEnum["PROPERTY_ID"] = $prop_id;
                 CIBlockPropertyEnum::Add($arEnum);
             }
         } else {
             CIBlockPropertyEnum::Delete($id);
         }
     }
 }
Beispiel #2
0
 function CheckManufacturer($xml)
 {
     $propertyId = $this->PROPERTY_MAP["CML2_MANUFACTURER"];
     $enumXmlId = $xml[$this->mess["IBLOCK_XML2_ID"]];
     $enumName = $xml[$this->mess["IBLOCK_XML2_NAME"]];
     $enumValue = CIBlockPropertyEnum::GetList(array(), array("PROPERTY_ID" => $propertyId, "XML_ID" => $enumXmlId));
     $enum = $enumValue->Fetch();
     if ($enum) {
         if ($enum["VALUE"] !== $enumName) {
             CIBlockPropertyEnum::Update($enum["ID"], array("VALUE" => $enumName));
         }
         return $enum["ID"];
     } else {
         return CIBlockPropertyEnum::Add(array("VALUE" => $enumName, "PROPERTY_ID" => $propertyId, "DEF" => "N", "XML_ID" => $enumXmlId));
     }
 }
						$PROP_ENUM_XML_ID = $xPropEnum->GetAttribute($nameUTF['ID']);
						$PROP_ENUM_NAME = $xPropEnum->GetAttribute($nameUTF['Name']);
						$PROP_ENUM_DEF = ($PROP_ENUM_XML_ID==$PROP_DEF?"Y":"N");

						$arFields = Array(
							"DEF"=>$PROP_ENUM_DEF,
							"TMP_ID"=>$tmpid,
							"VALUE"=>$PROP_ENUM_NAME,
							"PROPERTY_ID"=>$PROP_ID,
							"XML_ID"=>$PROP_ENUM_XML_ID
						);
						$res = CIBlockPropertyEnum::GetList(array(), Array("PROPERTY_ID"=>$PROP_ID, "XML_ID"=>$PROP_ENUM_XML_ID));
						if($arr = $res->Fetch())
						{
							$PROP_ENUM_ID = $arr["ID"];
							$pren->Update($PROP_ENUM_ID, $arFields);
						}
						else
						{
							$PROP_ENUM_ID = $pren->Add($arFields);
						}
						$arPropertiesEnum[$PROP_XML_ID][$PROP_ENUM_XML_ID] = $PROP_ENUM_ID;
					}
				}
			}

			if (function_exists("catalog_property_mutator_1c"))
				catalog_property_mutator_1c();

			$arGrTmp = array();
			$groups = $xCatNode->select_nodes("/".$nameUTF['Category']);
Beispiel #4
0
 public static function ImportPropsFromXML($BID, $xmlPath, &$arOldNewID)
 {
     if (file_exists($xmlPath) && $BID && CModule::IncludeModule('iblock')) {
         require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/classes/general/xml.php';
         $arExistProps = array();
         $rsProp = CIBlockProperty::GetList(array(), array('IBLOCK_ID' => $BID));
         while ($arProp = $rsProp->Fetch()) {
             $arExistProps[$arProp['CODE']] = $arProp;
         }
         $arExistEnums = array();
         $rsEnum = CIBlockPropertyEnum::GetList(array(), array('IBLOCK_ID' => $BID));
         while ($arEnum = $rsEnum->Fetch()) {
             $arExistEnums[$arEnum['PROPERTY_ID'] . '_' . $arEnum['XML_ID']] = $arEnum;
         }
         $arOldNewID = array();
         $xml = new CDataXML();
         $ep = new CIBlockProperty();
         $en = new CIBlockPropertyEnum();
         if ($xml->Load($xmlPath)) {
             if ($node = $xml->SelectNodes('/asd_iblock_props/props/')) {
                 foreach ($node->children() as $child) {
                     $arProp = array_pop($child->__toArray());
                     $arFields = array('IBLOCK_ID' => $BID);
                     foreach ($arProp as $code => $v) {
                         $arFields[strtoupper($code)] = is_array($v[0]['#']['cdata-section']) ? $v[0]['#']['cdata-section'][0]['#'] : $v[0]['#'];
                     }
                     if (isset($arExistProps[$arFields['CODE']])) {
                         $arOldNewID[$arFields['OLD_ID']] = $arExistProps[$arFields['CODE']]['ID'];
                         $ep->Update($arExistProps[$arFields['CODE']]['ID'], $arFields);
                     } else {
                         $arOldNewID[$arFields['OLD_ID']] = $arFields['ID'] = $ep->Add($arFields);
                         $arExistProps[$arFields['CODE']] = $arFields;
                     }
                 }
             }
             if ($node = $xml->SelectNodes('/asd_iblock_props/enums/')) {
                 foreach ($node->children() as $child) {
                     $arProp = array_pop($child->__toArray());
                     $arFields = array('IBLOCK_ID' => $BID);
                     foreach ($arProp as $code => $v) {
                         $arFields[strtoupper($code)] = is_array($v[0]['#']['cdata-section']) ? $v[0]['#']['cdata-section'][0]['#'] : $v[0]['#'];
                     }
                     $arFields['PROPERTY_ID'] = $arExistProps[$arFields['PROPERTY_CODE']]['ID'];
                     if (isset($arExistEnums[$arFields['PROPERTY_ID'] . '_' . $arFields['XML_ID']])) {
                         $en->Update($arExistEnums[$arFields['PROPERTY_ID'] . '_' . $arFields['XML_ID']]['ID'], $arFields);
                     } else {
                         $en->Add($arFields);
                     }
                 }
             }
         }
     }
 }
Beispiel #5
0
 /**
  *
  */
 public function process()
 {
     if ($this->processed) {
         return;
     }
     $this->processed = true;
     foreach ($this->generateData() as $k => $v) {
         $this->data[$k] = $v;
     }
     $this->update();
     $o = new \CIBlock();
     $mesages = $this->messages();
     $o->SetMessages($this->getId(), $mesages);
     $fields = $this->fields();
     $o->SetFields($this->getId(), $fields);
     $props = $this->loadProperties();
     $newProps = $this->properties();
     foreach ($this->urlsProps() as $key => $data) {
         $newProps[$key] = $data;
     }
     $o = new \CIBlockProperty();
     foreach ($props as $prop => $data) {
         if (!isset($newProps[$prop])) {
             $o->Delete($data['ID']);
         }
     }
     foreach ($newProps as $prop => $data) {
         $data['CODE'] = $prop;
         if ($data['PROPERTY_TYPE'] == 'E' || $data['PROPERTY_TYPE'] == 'G') {
             if (!isset($data['LINK_IBLOCK_ID'])) {
                 if (isset($data['LINK_IBLOCK_CODE'])) {
                     $data['LINK_IBLOCK_ID'] = self::codeToId($data['LINK_IBLOCK_CODE']);
                 }
             }
         }
         if (isset($props[$prop])) {
             $id = $props[$prop]['ID'];
             $o->Update($id, $data);
         } else {
             $data['IBLOCK_ID'] = $this->getId();
             $id = $o->Add($data);
         }
         if ($data['PROPERTY_TYPE'] == 'L' && isset($data['ITEMS']) && is_array($data['ITEMS'])) {
             $items = array();
             $newItems = $data['ITEMS'];
             $res = \CIBlockPropertyEnum::GetList(array(), array('PROPERTY_ID' => $id, 'CHECK_PERMISSIONS' => 'N'));
             while ($row = $res->Fetch()) {
                 $iid = $row['ID'];
                 $eid = $row['EXTERNAL_ID'];
                 if (!isset($newItems[$eid])) {
                     \CIBlockPropertyEnum::Delete($iid);
                 } else {
                     $items[$eid] = $row;
                 }
             }
             $eo = new \CIBlockPropertyEnum();
             foreach ($newItems as $eid => $edata) {
                 if (is_string($edata)) {
                     $edata = array('VALUE' => $edata);
                 }
                 $edata['PROPERTY_ID'] = $id;
                 $edata['EXTERNAL_ID'] = $eid;
                 $edata['XML_ID'] = $eid;
                 if (isset($items[$eid])) {
                     $eo->Update($items[$eid]['ID'], $edata);
                 } else {
                     $eo->Add($edata);
                 }
             }
         }
     }
 }