{extends 'template:1'} {block 'title'} {$_modx->setPlaceholder('placetitle', ($_modx->resource.longtitle ?: 'Штатные магнитолы для ' ~ $_modx->resource.pagetitle ~ ' на Android купить в ' ~ $city_rp ~ ' по низкой цене в интернет-магазине D-AUDIO'))} {'placetitle' | placeholder} {/block} {block 'description'} {set $description = 'Купить штатную магнитолу для ' ~ $_modx->resource.pagetitle ~ ' с CarPlay, Android Auto и навигатором можно в компании D-AUDIO. Установка в день покупки. Гарантия. Доставка по РФ. Звоните: ' ~ $_modx->config.phone } {/block} {block 'ldJsonSchema'} {set $seoTitle = ('placetitle' | placeholder)} {if $total?} {set $seoTitle = $seoTitle ~ ' (Товаров: ' ~ $total ~ ')'} {/if} {'!itemListCatalogSchema' | snippet : [ 'title' => $seoTitle, 'description' => ($_modx->resource.description ?: $description) ]} {/block} {block 'content'} {* === РЕФАКТОРИНГ ЛОГИКИ РАЗДЕЛОВ === *} {* 1. Указываем ID базовых разделов (от которых идет отсчет марок) *} {set $root_ids = [13435, 27091, 27126, 27128]} {* 2. Проверяем, находимся ли мы сейчас прямо в одном из базовых разделов *} {set $is_root = in_array($_modx->resource.id, $root_ids)} {* 3. Поднимаемся по дереву, чтобы определить ID Марки *} {set $brand_id = 0} {set $is_brand_page = false} {if !$is_root} {* Получаем родителей до 5-го уровня вверх *} {set $p1 = $_modx->resource.parent} {set $p2 = $p1 ? ($p1 | resource : 'parent') : 0} {set $p3 = $p2 ? ($p2 | resource : 'parent') : 0} {set $p4 = $p3 ? ($p3 | resource : 'parent') : 0} {set $p5 = $p4 ? ($p4 | resource : 'parent') : 0} {* Ищем, кто из родителей является корневым, чтобы понять где Марка *} {if in_array($p1, $root_ids)} {set $brand_id = $_modx->resource.id} {* Мы находимся в самой Марке *} {set $is_brand_page = true} {elseif in_array($p2, $root_ids)} {set $brand_id = $p1} {elseif in_array($p3, $root_ids)} {set $brand_id = $p2} {elseif in_array($p4, $root_ids)} {set $brand_id = $p3} {elseif in_array($p5, $root_ids)} {set $brand_id = $p4} {/if} {/if} {* =================================== *}
{* Вывод Моделей для текущей Марки (если мы находимся внутри Марки или глубже) *} {if $brand_id > 0}
{'pdoResources' | snippet : [ 'parents' => $brand_id, 'depth' => 0, 'limit' => 0, 'tvPrefix' => '', 'razdel' => $is_brand_page ? true : false, 'sortby' => 'pagetitle', 'sortdir' => 'ASC', 'includeTVs' => 'avatar', 'tpl' => 'category__single', 'templates' => 5 ]}
{/if} {* Вывод Марок (если мы находимся на главной странице Каталога или на странице China) *} {if $is_root}
{'pdoResources' | snippet : [ 'parents' => $_modx->resource.id, 'depth' => 0, 'limit' => 0, 'tvPrefix' => '', 'sortby' => 'pagetitle', 'sortdir' => 'ASC', 'includeTVs' => 'avatar', 'tpl' => 'category__single__brands', 'templates' => 5 ]}
{/if}
{set $where = [ 'template' => 3, 'Data.image IS NOT NULL' ]} {if $_modx->config.showZero != 1} {set $where['Data.price:>'] = 0} {/if} {* 1. ФОРМИРУЕМ БРОНЕБОЙНЫЙ КЛЮЧ КЭША *} {var $get = ($.get | toJSON) | md5} {set $categoryId = $_modx->resource.id} {* 2. ОПРЕДЕЛЯЕМ ТИП ЦЕНЫ И СТАВИМ ГЛОБАЛЬНЫЙ ПЛЕЙСХОЛДЕР *} {if $_modx->user.id && ($_modx->user.id | ismember : 'OptPrice')} {set $priceType = 'opt'} {* Сохраняем в память системы, что это оптовик (0 запросов к БД в будущем) *} {set $null = $_modx->setPlaceholder('isOptUser', 1)} {else} {set $priceType = 'retail'} {set $null = $_modx->setPlaceholder('isOptUser', 0)} {/if} {* Собираем итоговый путь к файлу кэша *} {set $cacheKey = 'msearch2/html_cache/category_' ~ $categoryId ~ '/' ~ $priceType ~ '_' ~ $get} {* 3. ПРОВЕРЯЕМ КЭШ *} {if !$filter = $_modx->cacheManager->get($cacheKey)} {* Если кэша нет - запускаем mFilter2 *} {set $filter = $_modx->runSnippet('!mFilter2', [ 'element' => 'msProducts', 'class' => 'msProduct', 'parents' => $categoryId, 'checkPermissions' => 0, 'showHidden' => 0, 'showUnpublished' => 0, 'processTVs' => 0, 'suggestions' => 1, 'values_delimeter'=>';', 'limit' => 36, 'maxLimit' => 100, 'filters' => 'ms|price:number', 'showLog' => 0, 'sortby' => [ "pagetitle LIKE 'Штатная магнитола%'" => 'DESC', 'Data.price' => 'ASC' ], 'where' => $where, 'aliases'=>' ms|vendor==vendor, msopoption|size==size, ms|price==price ', 'tvPrefix' => '', 'tpls' => 'tpl.msProducts.row.fx_model_intovar_ms2option', 'ajaxMode' => '', 'paginator' => 'pdoPage', 'tplPageWrapper' => '@INLINE ', 'tplPage' => '@INLINE
  • ', 'tplPageActive' => '@INLINE
  • ', 'tplPageSkip' => '@INLINE
  • ...
  • ', 'includeThumbs' => 'normal', 'tplOuter' => 'tpl.mFilter2.outer.fx_model', 'tplFilter.outer.size' => 'tpl.mFilter2.filter.outer', 'tplFilter.row.size' => 'tpl.mFilter2.filter.size', 'tplFilter.outer.vendor' => 'tpl.mFilter2.filter.outer', 'tplFilter.row.vendor' => 'tpl.mFilter2.filter.checkbox.brand', 'tplFilter.outer.price' => 'tpl.mFilter2.filter.slider', 'tplFilter.row.price' => 'tpl.mFilter2.filter.number' ])} {* 4. СОХРАНЯЕМ В КЭШ (На 24 часа) *} {* Забираем собранные ID из плейсхолдера *} {set $jsonIds = $_modx->getPlaceholder('current_catalog_ids')} {* Кэшируем HTML *} {set $null = $_modx->cacheManager->set($cacheKey, $filter, 86400)} {* Рядом кэшируем массив ID, добавив суффикс _ids к ключу *} {set $null = $_modx->cacheManager->set($cacheKey ~ '_ids', $jsonIds, 86400)} {else} {* ЕСЛИ HTML ВЗЯТ ИЗ КЭША *} {* Достаем сохраненный массив ID из кэша *} {set $jsonIds = $_modx->cacheManager->get($cacheKey ~ '_ids')} {* И принудительно восстанавливаем плейсхолдер для сниппета микроразметки *} {set $null = $_modx->setPlaceholder('current_catalog_ids', $jsonIds)} {/if} {* 5. ПОДКЛЮЧАЕМ СКРИПТЫ *} {'!mFilterJS' | snippet} {* 6. ВЫВОДИТСЯ ГОТОВЫЙ HTML *} {if $_modx->resource.id != 13435} {$filter} {/if}
    {if $_modx->resource.content}
    {$_modx->resource.content}
    {/if} {/block} {*
    *}