/** * Create property. * * @param int $iblockID Iblock id. * @param string $propertyCode Property code. * @param array $propertyParams Property params. * @return bool|int */ public static function createProperty($iblockID, $propertyCode, $propertyParams = array()) { self::$errors = array(); $iblockID = (int) $iblockID; $propertyCode = (string) $propertyCode; if ($iblockID <= 0 || $propertyCode === '') { return false; } $iblockIterator = Iblock\IblockTable::getList(array('select' => array('ID'), 'filter' => array('ID' => $iblockID))); if (!($iblock = $iblockIterator->fetch())) { return false; } unset($iblock, $iblockIterator); $propertyIterator = Iblock\PropertyTable::getList(array('select' => array('ID'), 'filter' => array('IBLOCK_ID' => $iblockID, '=CODE' => $propertyCode))); if ($property = $propertyIterator->fetch()) { return (int) $property['ID']; } unset($propertyIterator); $propertyDescription = self::getPropertyDescription($propertyCode, $propertyParams); if ($propertyDescription === false) { return false; } $propertyDescription['IBLOCK_ID'] = $iblockID; if (!self::validatePropertyDescription($propertyDescription)) { return false; } $propertyResult = Iblock\PropertyTable::add($propertyDescription); if ($propertyResult->isSuccess()) { return $propertyResult->getId(); } else { self::$errors = $propertyResult->getErrorMessages(); return false; } }
} elseif ($bPropertyAjax) { CUtil::JSPostUnescape(); } if ($bPropertyAjax) $str_IBLOCK_ELEMENT_SECTION = $_REQUEST["IBLOCK_SECTION"]; if (is_array($str_IBLOCK_ELEMENT_SECTION)) $str_IBLOCK_ELEMENT_SECTION = array_unique($str_IBLOCK_ELEMENT_SECTION); $clearedByCopyProperties = array(); if ($bCopy) { $clearedByCopyProperties = CIBlockPropertyTools::getClearedPropertiesID($IBLOCK_ID); } $arPROP_tmp = array(); $properties = CIBlockProperty::GetList(array("SORT"=>"ASC", "NAME"=>"ASC"), array("IBLOCK_ID"=>$IBLOCK_ID, "ACTIVE"=>"Y", "CHECK_PERMISSIONS"=>"N")); while($prop_fields = $properties->Fetch()) { $prop_values = array(); $prop_values_with_descr = array(); if ( $bPropertyAjax && is_array($_POST["PROP"]) && array_key_exists($prop_fields["ID"], $_POST["PROP"]) ) { $prop_values = $_POST["PROP"][$prop_fields["ID"]]; $prop_values_with_descr = $prop_values;
/** * Validate and modify exist property. * * @param string $propertyCode Property code. * @param array $property Current property data. * @return bool * @throws Exception */ protected static function validateExistProperty($propertyCode, $property) { $result = true; switch ($propertyCode) { case self::CODE_SKU_LINK: $fields = array(); if ($property['USER_TYPE'] != self::USER_TYPE_SKU_LINK) { $fields['USER_TYPE'] = self::USER_TYPE_SKU_LINK; } if ($property['XML_ID'] != self::XML_SKU_LINK) { $fields['XML_ID'] = self::XML_SKU_LINK; } if (!empty($fields)) { $propertyResult = Iblock\PropertyTable::update($property['ID'], $fields); if (!$propertyResult->isSuccess()) { self::$errors = $propertyResult->getErrorMessages(); $result = false; } unset($propertyResult); } unset($fields); break; } return $result; }
} } unset($propIBlock, $propertyIterator); if (($propBlogPostID == 0 || $propBlogCommentsCountID == 0) && $arParams['BLOG_FROM_AJAX'] === 'N') { if ($propBlogPostID == 0) { $propBlogPostID = (int) CIBlockPropertyTools::createProperty($arParams['IBLOCK_ID'], CIBlockPropertyTools::CODE_BLOG_POST); if ($propBlogPostID == 0) { $arResult['ERRORS'] = array_merge($arResult['ERRORS'], CIBlockPropertyTools::getErrors()); CIBlockPropertyTools::clearErrors(); } } if ($propBlogCommentsCountID == 0) { $propBlogCommentsCountID = (int) CIBlockPropertyTools::createProperty($arParams['IBLOCK_ID'], CIBlockPropertyTools::CODE_BLOG_COMMENTS_COUNT); if ($propBlogCommentsCountID == 0) { $arResult['ERRORS'] = array_merge($arResult['ERRORS'], CIBlockPropertyTools::getErrors()); CIBlockPropertyTools::clearErrors(); } } } $arResult['BLOG_DATA']['BLOG_POST_ID_PROP'] = $propBlogPostID; $arResult['BLOG_DATA']['BLOG_COMMENTS_COUNT_PROP'] = $propBlogCommentsCountID; } if ($arResult['BLOG_DATA']['BLOG_ID'] == 0 || $arResult['BLOG_DATA']['BLOG_POST_ID_PROP'] == 0 || $arResult['BLOG_DATA']['BLOG_COMMENTS_COUNT_PROP'] == 0) { $arResult['BLOG_USE'] = false; $arResult['BLOG_FROM_AJAX'] = false; } } $arSelect = array("ID", "IBLOCK_ID", "NAME", "PREVIEW_TEXT", "DETAIL_PAGE_URL", "PREVIEW_TEXT_TYPE", "DATE_CREATE", "CREATED_BY"); if ($arResult['BLOG_USE']) { $arSelect[] = 'PROPERTY_' . $arResult['BLOG_DATA']['BLOG_POST_ID_PROP']; $arSelect[] = 'PROPERTY_' . $arResult['BLOG_DATA']['BLOG_COMMENTS_COUNT_PROP'];
/** * @deprecated deprecated since catalog 16.0.0 * @see CIBlockPropertyTools::createProperty * * @param int $ID Parent iblock id. * @param int $SKUID Offer iblock id. * @return int|false */ public static function LinkSKUIBlock($ID, $SKUID) { global $APPLICATION; $arMsg = array(); $boolResult = true; $propertyId = 0; $ID = (int) $ID; if (0 >= $ID) { $arMsg[] = array('id' => 'PRODUCT_IBLOCK_ID', 'text' => Loc::getMessage('BT_MOD_CATALOG_ERR_PRODUCT_ID_INVALID')); $boolResult = false; } $SKUID = (int) $SKUID; if (0 >= $SKUID) { $arMsg[] = array('id' => 'OFFERS_IBLOCK_ID', 'text' => Loc::getMessage('BT_MOD_CATALOG_ERR_OFFERS_ID_INVALID')); $boolResult = false; } if ($ID == $SKUID) { $arMsg[] = array('id' => 'OFFERS_IBLOCK_ID', 'text' => Loc::getMessage('BT_MOD_CATALOG_ERR_PRODUCT_ID_SELF')); $boolResult = false; } if ($boolResult) { $propertyId = CIBlockPropertyTools::createProperty($SKUID, CIBlockPropertyTools::CODE_SKU_LINK, array('LINK_IBLOCK_ID' => $ID)); if (!$propertyId) { $arMsg = CIBlockPropertyTools::getErrors(); $boolResult = false; } } if (!$boolResult) { $obError = new CAdminException($arMsg); $APPLICATION->ResetException(); $APPLICATION->ThrowException($obError); return $boolResult; } else { return $propertyId; } }
function CheckSKUProperty($ID, $SKUID) { $ID = (int) $ID; $SKUID = (int) $SKUID; if ($ID > 0 && $SKUID > 0) { $propertyId = CIBlockPropertyTools::createProperty($SKUID, CIBlockPropertyTools::CODE_SKU_LINK, array('LINK_IBLOCK_ID' => $ID)); if ($propertyId) { $arResult = array('RESULT' => 'OK', 'VALUE' => $propertyId); } else { $arResult = array('RESULT' => 'ERROR', 'MESSAGE' => implode('. ', CIBlockPropertyTools::getErrors())); } } else { $arResult = array('RESULT' => 'ERROR', 'MESSAGE' => GetMessage('IB_E_OF_ERR_SKU_IBLOCKS_IS_ABSENT')); } return $arResult; }