my code stock.com

Snippet options

Download: Download snippet as testphp.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");

?>

<?php
    $APPLICATION->SetTitle('ТОВАРЫ ДЛЯ ХУДОЖЕСТВЕННОЙ ГИМНАСТИКИ '. $_REQUEST["ELEMENT_CODE"]);
    $APPLICATION->AddChainItem($_REQUEST["ELEMENT_CODE"]);

    //Подготовка получения списка брендов:
    if (CModule::IncludeModule('highloadblock')) {
       $arHLBlock = Bitrix\Highloadblock\HighloadBlockTable::getById(2)->fetch();
       $obEntity = Bitrix\Highloadblock\HighloadBlockTable::compileEntity($arHLBlock);
       $strEntityDataClass = $obEntity->getDataClass();
    }

    //Получение списка активных брендов:
    unset($arItems);
    $arItems = array();
    if (CModule::IncludeModule('highloadblock')) {
       $rsData = $strEntityDataClass::getList(array(
          'select' => array('ID', 'UF_NAME', 'UF_RUS_NAME', 'UF_FILE', 'UF_DESCRIPTION', 'UF_LONG_DESCRIPTION', 'UF_BANNER_MD', 'UF_BANNER_LG', 'UF_COLOR_LIST_BLOCK', 'UF_ACTIVE', 'UF_XML_ID'),
          'filter' => array('=UF_ACTIVE' => 'Y', '=UF_XML_ID' => $_REQUEST["ELEMENT_CODE"]),
          'order' => array('ID' => 'ASC'),
          'limit' => '1',
       ));
       while ($arItem = $rsData->Fetch()) {
          $arItems[] = $arItem;
       }
    }

    //Если массив пуст то показываем что страница не найдена
    if (empty($arItems)){
        LocalRedirect("/404.php", "404 Not Found");
        return;
    }

    foreach ($arItems as $key => $value) {
        $arItems[$key]['LOGO'] = CFile::GetPath($value['UF_FILE']);
        $arItems[$key]['BANNER_MD'] = CFile::GetPath($value['UF_BANNER_MD']);
        $arItems[$key]['BANNER_LG'] = CFile::GetPath($value['UF_BANNER_LG']);
        //Добавляем надпись "Своя продукция" если имя производителя = Инес
        if ($arItems[$key]['UF_XML_ID'] == 'ines') {
            $arItems[$key]['OUR_PRODUCTION'] = TRUE;
        }
    }

    //Получаем список не пустые категорий
    CModule::IncludeModule("IBlock");
    CModule::IncludeModule("Catalog");
    function getSectionList(){
        $arLincs = array();
        $arOrder = array('LEFT_MARGIN' => 'ASC');
        $arFilter = array('ACTIVE' => 'Y', 'GLOBAL_ACTIVE' => 'Y');
        $arSelect = array('ID', 'IBLOCK_SECTION_ID', 'NAME', 'LEFT_MARGIN', 'SECTION_PAGE_URL', 'DEPTH_LEVEL', 'ELEMENT_CNT');
        $dbSection = CIBlockSection::GetList($arOrder, $arFilter, true, $arSelect);
        while( $arSection = $dbSection-> GetNext(true, false) ){
            $SectionID = $arSection['ID'];
            $ParentSectionID = (int) $arSection['IBLOCK_SECTION_ID'];
            $arLincs[$SectionID] = array(
                'NAME' => $arSection['NAME'],
                'URL' => $arSection['SECTION_PAGE_URL'],
                'DEPTH' => $arSection['DEPTH_LEVEL'],
            );
        }

        return $arLincs;
    }

    function getTovarListForBrand($brand){
        $arCat = array();
        $arOrder = array();
        $arFilter = array("IBLOCK_ID"=>2, "ACTIVE"=>"Y", 'PROPERTY_BRAND_REF' => $brand);
        $arSelect = array();
        $dbElement = CIBlockElement::GetList($arOrder, $arFilter, array('IBLOCK_SECTION_ID'), $arSelect);
        while( $arElement = $dbElement->Fetch() ){
            $arCat[] = $arElement;
        }

        return $arCat;
    }

    function getTovarRandomListForBrand($brand){
        $arCat = array();
        $arOrder = array("RAND" => "ASC");
        $arFilter = array("IBLOCK_ID"=>2, "ACTIVE"=>"Y", 'PROPERTY_BRAND_REF' => $brand);
        $arSelect = array('ID');
        $dbElement = CIBlockElement::GetList($arOrder, $arFilter, false, array("nTopCount" => 8), $arSelect);
        while( $arElement = $dbElement->GetNextElement() ){
            $arCat[] = $arElement->fields['ID'];
        }
        return $arCat;
    }

    //Получаем список всех категорий
    $allSection = getSectionList();

    //Получаем список товаров для запрошенного бренда
    $allElementForBrand = getTovarListForBrand($_REQUEST["ELEMENT_CODE"]);

    //Собираем категории для определенного бренда
    $arrBrandsCategoryList = array();
    foreach ($allElementForBrand as $key => $value) {
        //Условием регулируем глубину категорий, по умолчанию выводим все
        if ($allSection[$value['IBLOCK_SECTION_ID']]['DEPTH'] <= 3 && 1) {
            $arrBrandsCategoryList[] = array_merge($allSection[$value['IBLOCK_SECTION_ID']], array('COUNT' => $value['CNT']));
        }
    }


    //Получаем список id из 8 случайных товаров запрошенного бренда
    $randomElementForBrand = getTovarRandomListForBrand($_REQUEST["ELEMENT_CODE"]);

?>

<div class="brands-detail">
    <div style="background: #EFF1F3;" class="banner">
        <div class="banner-background">
            <div style="background-image: url(<?=$arItems[0]['BANNER_MD'] ?>);" class="hidden-lg"></div>
            <div style="background-image: url(<?=$arItems[0]['BANNER_LG'] ?>);" class="hidden-xs hidden-sm hidden-md"></div>
        </div>
        <div class="banner-contents">
            <div class="row">
                <div class="col-lg-5 col-sm-7 col-lg-push-6 col-sm-push-5">
                    <img src="<?=$arItems[0]['LOGO'] ?>" alt="image">
                    <?php if (isset($arItems[0]['OUR_PRODUCTION']) && $arItems[0]['OUR_PRODUCTION']): ?>
                        <span class="sticker">Собственный <br>бренд</span>
                    <?php endif ?>
                    <p><?=$arItems[0]['UF_LONG_DESCRIPTION'] ?></p>
                </div>
            </div>
        </div>
    </div>
    <div class="category-nav-wrapper">
        <div class="category-nav">
            <?php
            //Если есть не пустые категории то выводим
            if(!empty($arrBrandsCategoryList)):?>
                <div class="row">
                    <?php foreach ($arrBrandsCategoryList as $key => $value): ?>
                        <div class="col-sm-4 category-link-wrapper">
                            <a title="<?php print $value['NAME']; ?> - <?=$arItems[0]['UF_NAME'] ?> (товаров: <?php print $value['COUNT']; ?>)" href="<?php print $value['URL']; ?>"><span><?php print $value['NAME']; ?></span></a>
                        </div>
                    <?php endforeach; ?>
                </div>
            <?php endif; ?>
        </div>
    </div>
    <div class="suggestions-wrapper">
        <div class="suggestions-heading">
            <p class="h2 text-center">ПРЕДЛАГАЕМ ТОВАРЫ <?php print $arItems[0]['UF_NAME']; ?></p>
        </div>
        <div class="suggestions-body">
            <?php
                //Запрашиваем товары по списку найденных ID но только те количество в наличии которых > 0
                $arrFilter = array('ID' => $randomElementForBrand);
                $cnt_not_0_tovar = CIBlockElement::GetList(array(), array_merge(array("IBLOCK_ID" => 2), $arrFilter), array(), false, array("ID"));
                //Выводим найденные товары только если они есть в наличии
                if ($cnt_not_0_tovar > 0) {
                    $intSectionID = $APPLICATION->IncludeComponent(
                        "bitrix:catalog.section",
                        'random_slider',
                        array(
                            "IBLOCK_TYPE" => "catalog",
                            "IBLOCK_ID" => "2",
                            "SECTION_ID" => $_REQUEST["SECTION_ID"],
                            "SECTION_CODE" => "",
                            "ELEMENT_SORT_FIELD" => "desc",
                            "ELEMENT_SORT_ORDER" => "asc",
                            "ELEMENT_SORT_FIELD2" => "id",
                            "ELEMENT_SORT_ORDER2" => "desc",

                            "PROPERTY_CODE" => array(
                                0 => "BRAND_REF",
                                1 => "MANUFACTURER",
                                2 => "MATERIAL",
                                3 => "",
                            ),
                            "META_KEYWORDS" => "-",
                            "META_DESCRIPTION" => "-",
                            "BROWSER_TITLE" => "-",
                            "INCLUDE_SUBSECTIONS" => "Y",
                            "SHOW_ALL_WO_SECTION" => "Y",
                            "BASKET_URL" => "/personal/cart/",
                            "ACTION_VARIABLE" => "action",
                            "PRODUCT_ID_VARIABLE" => "id",
                            "SECTION_ID_VARIABLE" => "SECTION_ID",
                            "PRODUCT_QUANTITY_VARIABLE" => "quantity",
                            "PRODUCT_PROPS_VARIABLE" => "prop",
                            "FILTER_NAME" => "arrFilter",
                            "CACHE_TYPE" => "A",
                            "CACHE_TIME" => "36000000",
                            "CACHE_FILTER" => "N",
                            "CACHE_GROUPS" => "N",
                            "SET_TITLE" => "Y",
                            "SET_STATUS_404" => "Y",
                            "DISPLAY_COMPARE" => "N",
                            "PAGE_ELEMENT_COUNT" => 8,
                            "LINE_ELEMENT_COUNT" => "3",
                            "PRICE_CODE" => array(
                                0 => "BASE",
                            ),
                            "USE_PRICE_COUNT" => "Y",
                            "SHOW_PRICE_COUNT" => "1",

                            "PRICE_VAT_INCLUDE" => "Y",
                            "USE_PRODUCT_QUANTITY" => "Y",
                            "ADD_PROPERTIES_TO_BASKET" => "Y",
                            "PARTIAL_PRODUCT_PROPERTIES" => "Y",
                            "PRODUCT_PROPERTIES" => array(
                            ),

                            "DISPLAY_TOP_PAGER" => "Y",
                            "DISPLAY_BOTTOM_PAGER" => "Y",
                            "PAGER_TITLE" => "Товары",
                            "PAGER_SHOW_ALWAYS" => "N",
                            "PAGER_DESC_NUMBERING" => "N",
                            "PAGER_DESC_NUMBERING_CACHE_TIME" => "36000",
                            "PAGER_SHOW_ALL" => "N",
                            "PAGER_TEMPLATE" => "pagination",

                            "OFFERS_CART_PROPERTIES" => "",
                            "OFFERS_FIELD_CODE" => array(
                                0 => "",
                                1 => "",
                            ),
                            "OFFERS_PROPERTY_CODE" => array(
                                0 => "",
                                1 => "",
                            ),
                            "OFFERS_SORT_FIELD" => "sort",
                            "OFFERS_SORT_ORDER" => "asc",
                            "OFFERS_SORT_FIELD2" => "id",
                            "OFFERS_SORT_ORDER2" => "desc",
                            "OFFERS_LIMIT" => "5",

                            /*"SECTION_URL" => "/catalog/#SECTION_CODE_PATH#/",
                            "DETAIL_URL" => "/catalog/#SECTION_CODE_PATH#/#ELEMENT_CODE#/",*/
                            'CONVERT_CURRENCY' => "N",
                            'HIDE_NOT_AVAILABLE' => "N",

                            'LABEL_PROP' => "-",
                            'ADD_PICT_PROP' => "-",
                            'PRODUCT_DISPLAY_MODE' => "N",

                            'OFFER_ADD_PICT_PROP' => "-",
                            'OFFER_TREE_PROPS' => array(
                                0 => "-",
                            ),
                            'SHOW_DISCOUNT_PERCENT' => "N",
                            'SHOW_OLD_PRICE' => "N",
                            "MESS_BTN_BUY" => "Купить",
                            "MESS_BTN_ADD_TO_BASKET" => "В корзину",
                            "MESS_BTN_DETAIL" => "Подробнее",
                            "MESS_NOT_AVAILABLE" => "",

                            'TEMPLATE_THEME' => '',
                            "ADD_SECTIONS_CHAIN" => "N",
                            'ADD_TO_BASKET_ACTION' => '',
                            'SHOW_CLOSE_POPUP' => "N",
                        ),
                        $component
                    );
                }
            ?>
        </div>
    </div>
    <div class="description">
        <?$APPLICATION->IncludeFile('/local/include/brands_seo_'.$_REQUEST["ELEMENT_CODE"].'.php', array(), array("MODE" => "html", "NAME" => "Описание бренда", "TEMPLATE" => ""));?>
    </div>
</div>

<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.