Answer the question
In order to leave comments, you need to log in
How can I get to them and overwrite the meta properties in Bitrix?
here is the working code, but only for fields not in the seo tab, how to modify it for the seo tab?
function copy_from_fields_to_propertys_values($IBLOCK_ID, $_FROM_FIELD_NAMES, $TO_PROPERTY_NAMES){
/* *
* $_FROM_FIELD_NAMES = array(DATE_ACTIVE_FROM, DATE_ACTIVE_TO);
* $TO_PROPERTY_NAMES = array(DATE_BEGIN, DATE_END);
* copy_from_fields_to_propertys_values(22, array("DATE_ACTIVE_FROM","DATE_ACTIVE_TO"), array("DATE_BEGIN","DATE_END"));
* */
if ( CModule::IncludeModule ( "iblock" ) ){
$arOrder = array(
"sort" => "ASC",
);
$arFilter = array(
"IBLOCK_ID" => $IBLOCK_ID,
);
foreach ( $TO_PROPERTY_NAMES as $property_name ) {
$TO_PROPERTY_NAMES_with_prop[] = 'PROPERTY_' . $property_name;
}
$arSelect = array(
"NAME",
"ID"
);
$arSelect = array_merge ( $arSelect, $_FROM_FIELD_NAMES, $TO_PROPERTY_NAMES_with_prop );
$db_elemens = CIBlockElement::GetList ( $arOrder, $arFilter, false, false, $arSelect );
while ( $arElement = $db_elemens->Fetch () ) {
$PRODUCT_ID = $arElement["ID"];
foreach ( $TO_PROPERTY_NAMES as $key => $property_name ) {
CIBlockElement::SetPropertyValues ( $PRODUCT_ID, $IBLOCK_ID, $arElement[$_FROM_FIELD_NAMES[$key]], $property_name );
}
}
} else {
die( "Модуль iblock не установлен" );
}
}
copy_from_fields_to_propertys_values( 839, array("UN_TITLE","UN_DESCR","UN_KEY"), array("ELEMENT_META_TITLE","ELEMENT_META_DESCRIPTION","ELEMENT_META_KEYWORDS"));
Answer the question
In order to leave comments, you need to log in
* $_FROM_FIELD_NAMES = array(DATE_ACTIVE_FROM, DATE_ACTIVE_TO);
* $TO_PROPERTY_NAMES = array(DATE_BEGIN, DATE_END);
* copy_from_fields_to_propertys_values(22, array("DATE_ACTIVE_FROM","DATE_ACTIVE_TO"), array("DATE_BEGIN","DATE_END"));
* */
/* для сео свойств */
function copy_from_fields_to_propertys_values($SECTION_ID, $_FROM_FIELD_NAMES){
if ( CModule::IncludeModule ( "iblock" ) ){
$arOrder = array(
"sort" => "ASC",
);
$arFilter = array(
//"IBLOCK_ID" => $IBLOCK_ID,
"SECTION_ID" => $SECTION_ID
);
foreach ( $_FROM_FIELD_NAMES as $property_name ) {
$_FROM_PROPERTY_NAMES_with_prop[] = 'PROPERTY_' . $property_name;
}
$arSelect = array(
"NAME",
"ID" );
$arSelect = array_merge ( $arSelect,$_FROM_PROPERTY_NAMES_with_prop );
$db_elemens = CIBlockElement::GetList ( $arOrder, $arFilter, false, false, $arSelect );
while ( $arElement = $db_elemens->Fetch () ) {
$PRODUCT_ID = $arElement["ID"];
$el = new CIBlockElement;
$arLoadProductArray = Array(
"IPROPERTY_TEMPLATES" => array(
"ELEMENT_META_TITLE" => $arElement["PROPERTY_UN_TITLE_VALUE"],
"ELEMENT_META_DESCRIPTION" => $arElement["PROPERTY_UN_DESCR_VALUE"],
"ELEMENT_META_KEYWORDS" => $arElement["PROPERTY_UN_KEY_VALUE"],
)
);
$res = $el->Update($PRODUCT_ID, $arLoadProductArray); }
} else {
die( "Модуль iblock не установлен" );
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question