A
A
Anumik2016-09-07 07:11:15
1C-Bitrix
Anumik, 2016-09-07 07:11:15

How to replace the menu from the selected city?

Good day
Site on Bitrix, there is a main site and its copies in subdirectories corresponding to different cities, when choosing a city, a cookie is written, in the .left.menu_ext.php file, a part of the menu is assembled with the following code:

<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();

global $APPLICATION;

    if(CModule::IncludeModule("iblock"))
        {
    if ($_COOKIE['userCity']=='irkutsk') {
      $IBLOCK_ID = 25;
    } elseif ($_COOKIE['userCity']=='rostov') {
      $IBLOCK_ID = 49;
    } elseif ($_COOKIE['userCity']=='khabarovsk') {
      $IBLOCK_ID = 48;
    } elseif ($_COOKIE['userCity']=='rostov') {
      $IBLOCK_ID = 31;
    } else {
      $IBLOCK_ID = 5;
    }
       // указываем из какого инфоблока берем элементы
$arOrder = Array("SORT"=>"ASC");    // сортируем по свойству SORT по возрастанию
$arSelect = Array("ID", "NAME", "IBLOCK_ID", "DETAIL_PAGE_URL");
$arFilter = Array("IBLOCK_ID"=>$IBLOCK_ID, "ACTIVE"=>"Y");
$res = CIBlockElement::GetList($arOrder, $arFilter, false, false, $arSelect);
    while($ob = $res->GetNextElement())
    {
    $arFields = $ob->GetFields();            // берем поля
// начинаем наполнять массив aMenuLinksExt нужными данными
    $aMenuLinksExt[] = Array(
                $arFields['NAME'],
                $arFields['DETAIL_PAGE_URL'],
                Array(),
                Array(),
                ""
                );
    }        //     while($ob = $res->GetNextElement())
}    //     if(CModule::IncludeModule("iblock"))
 $aMenuLinks = array_merge($aMenuLinksExt, $aMenuLinks);
// $aMenuLinks = array_merge($aMenuLinks);
?>

but here is the design:
if ($_COOKIE['userCity']=='irkutsk') {
      $IBLOCK_ID = 25;
    } elseif ($_COOKIE['userCity']=='rostov') {
      $IBLOCK_ID = 49;
    } elseif ($_COOKIE['userCity']=='khabarovsk') {
      $IBLOCK_ID = 48;
    } elseif ($_COOKIE['userCity']=='rostov') {
      $IBLOCK_ID = 31;
    } else {
      $IBLOCK_ID = 5;
    }

does not work, I write the cookie, but it still displays elements from the main IB (addresses are not replaced)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yaroslav Alexandrov, 2016-09-07
@alexyarik

There is no binding to the site (SITE_ID), it seems to me that this is the reason

O
Oleg Maksimenko, 2016-09-07
@olegprof

Is $_COOKIE['userCity'] exactly what you expect? Is the menu component's cache disabled?

S
Sergey, 2016-09-07
@gangstarcj

To work with cookies in Bitrix, you must use the methods
https://dev.1c-bitrix.ru/api_help/main/reference/c...
https://dev.1c-bitrix.ru/api_help/main/reference/c ...
See if the cookie name is "userCity"?
PS Use instead of many if else - switch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question