Korusol
6/22/2017 - 4:07 PM

#kubirubi# скрипт для замены метатегов

#kubirubi# скрипт для замены метатегов

<?php
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
if(isset($_COOKIE['debugsah'])) {
    CModule::IncludeModule("iblock");

    $prop = 'META_DESCRIPTION';

    $arSelect = Array("ID", 'PROPERTY_'.$prop);
    $arFilter = Array("IBLOCK_ID"=>IntVal(2), '!PROPERTY_'.$prop => false);
    $res = CIBlockElement::GetList(Array(), $arFilter, false, Array("nPageSize"=>500), $arSelect);
    $testArr = [];
    while($ob = $res->fetch())
    {
        $testArr[$ob['ID']] = $ob['PROPERTY_'.$prop.'_VALUE'];
    }
    echo '<pre>';
    print_r($testArr);
    echo '</pre>';


    if(count($testArr) > 0){
        foreach ($testArr as $id => $propValue) {
            $el = new CIBlockElement;
            $arLoadProductArray = Array(
                "IPROPERTY_TEMPLATES"=>Array(
                    "ELEMENT_META_DESCRIPTION" => $propValue,
                )
            );
            $res = $el->Update($id, $arLoadProductArray);
            CIBlockElement::SetPropertyValuesEx($id, false, array($prop => ''));
            $el->Update($id, $arLoadProductArray);
        }
    }
}


require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/epilog_after.php");