Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function changeCats() {
- CModule::IncludeModule('catalog');
- $cats = array();
- $allowed = array();
- $bs = new CIBlockSection;
- $arFilter = Array('IBLOCK_ID'=> IBLOCK_CATALOG);
- $db_list = CIBlockSection::GetList(Array(), $arFilter, true);
- while($ar_result = $db_list->Fetch())
- {
- $cats[$ar_result['DEPTH_LEVEL']][] = $ar_result;
- }
- for ($i = count($cats); $i > 0; $i--) {
- foreach ($cats[$i] as $ar_result){
- $checked = 0;
- $has_products = 0;
- $arSelect = Array("ID", "CATALOG_GROUP_2");
- $arFilter = Array(
- "IBLOCK_ID"=> IBLOCK_CATALOG,
- "ACTIVE"=>"Y",
- "SECTION_ID" => $ar_result['ID'],
- '!CATALOG_QUANTITY' => 0
- );
- $res = CIBlockElement::GetList(Array(), $arFilter, false, Array(false), $arSelect);
- while($ar_fields = $res->GetNext())
- {
- if ($has_products == 0){
- $has_products = 1;
- }
- if ($ar_fields['CATALOG_PRICE_2'] > 0){
- $checked = 1;
- }
- }
- if ($checked == 0 && $has_products == 1 && !$allowed[$ar_result['ID']]) {
- $arFields = Array(
- "UF_NOT_AVAILABLE" => 1
- );
- // echo '<br/>Скрыт раздел: '.$ar_result['NAME'].'--'.$ar_result['ID'];
- } else if ($has_products == 0 && !$allowed[$ar_result['ID']]) {
- $arFields = Array(
- "UF_NOT_AVAILABLE" => 1
- );
- // echo '<br/>Скрыт раздел: '.$ar_result['NAME'].'--'.$ar_result['ID'];
- } else {
- $allowed[$ar_result['IBLOCK_SECTION_ID']] = 'Y';
- $arFields = Array(
- "UF_NOT_AVAILABLE" => 0
- );
- }
- $bs->Update($ar_result['ID'], $arFields);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement