<?php /* * Получаем данные каталога */ if($this instanceof Modxsite){ $modxsite = & $this; } else{ $modxsite = & $this->modxsite; } $modxsite->loadProcessor('web.getdata', 'shopmodx'); class modWebCatalogGetdataProcessor extends ShopmodxWebGetDataProcessor{ public $defaultSortField = 'good.id'; public $defaultSortDirection = 'DESC'; public function initialize() { $this->setDefaultProperties(array( 'limit' => 12, )); if(!empty($_REQUEST['page']) AND $page = (int)$_REQUEST['page'] AND $page > 1 AND $this->getProperty('limit', 0)){ $this->setProperty('start', ($page-1) * $this->getProperty('limit')); } return parent::initialize(); } public function prepareQueryBeforeCount(xPDOQuery $c) { $c = parent::prepareQueryBeforeCount($c); $c->innerJoin('ModGoods', 'good', "good.gid={$this->classKey}.id"); return $c; } protected function prepareCountQuery(xPDOQuery &$query) { $query = parent::prepareCountQuery($query); $type = $this->getProperty('type', 'all'); if($type != 'all'){ switch($type){ // Новинки case 'novelty': $query->innerJoin('modTemplateVarResource', 'novelty', "novelty.contentid={$this->classKey}.id AND novelty.tmplvarid=11 AND novelty.value='1'"); break; // Хиты продаж case 'top': $query->innerJoin('modTemplateVarResource', 'top', "top.contentid={$this->classKey}.id AND top.tmplvarid=6 AND top.value='1'"); break; // Скоро в продаже case 'soon': $query->innerJoin('modTemplateVarResource', 'soon', "soon.contentid={$this->classKey}.id AND soon.tmplvarid=12 AND soon.value='1'"); break; default:; } } $query->where(array( 'published' => 1, 'deleted' => 0, 'hidemenu' => 0, )); return $query; } public function setSelection(xPDOQuery $c) { $c = parent::setSelection($c); $c->select(array( 'good.*', )); return $c; } public function outputArray(array $array, $count = false) { $this->modx->setPlaceholder('total', $count); $this->modx->runSnippet('getPage@getPage', array( 'limit' => $this->getProperty('limit'), )); return parent::outputArray($array, $count); } } return 'modWebCatalogGetdataProcessor';
<?php /* * Получаем данные каталога */ require_once dirname(dirname(__FILE__)).'/getdata.class.php'; class modWebCatalogCategoryGetdataProcessor extends modWebCatalogGetdataProcessor{ protected $sectionsIDs = array(); // Разделы public function beforeQuery() { $can = parent::beforeQuery(); if($can !== true){ return $can; } $this->getSectionsIDs($this->getSectionsCondition()); if(!$this->sectionsIDs){ return "Не были получены разделы"; } return true; } protected function getSectionsCondition(){ return array( 'id' => $this->modx->resource->get('id'), ); } // Получаем ID-шники разделов protected function getSectionsIDs($where){ if(!$where){ return; } $query = $this->modx->newQuery('modResource'); $query->select(array( "DISTINCT {$this->classKey}.id", )); $query->where(array( 'deleted' => 0, 'published' => 1, 'isfolder' => 1, 'hidemenu' => 0, 'template' => 2, )); $query->where($where); if($query->prepare() && $query->stmt->execute() && $rows = $query->stmt->fetchAll(PDO::FETCH_ASSOC)){ $result = array(); foreach($rows as $row){ $result[] = $row['id']; } $this->sectionsIDs = array_unique(array_merge($this->sectionsIDs, $result)); return $this->getSectionsIDs(array( "parent:IN" => $result, )); } return; } public function prepareCountQuery(xPDOQuery &$query) { $query = parent::prepareCountQuery($query); $query->where(array( "{$this->classKey}.parent:IN" => $this->sectionsIDs, )); return $query; } } return 'modWebCatalogCategoryGetdataProcessor';
<ins class="row show-grid"> <div class="r [[+tv.novice_good:gt=`0`:then=`novice`]] [[+tv.top_buyed:gt=`0`:then=`top_buyed`]] [[+remains:equalto=`0`:then=`[[+tv.expected_qty:gt=`0`:then=`expected_qty`]]`]]"> <div class="label [[+tv.novice_good:gt=`0`:then=`novice`]] [[+tv.top_buyed:gt=`0`:then=`top_buyed`]] [[+remains:equalto=`0`:then=`[[+tv.expected_qty:gt=`0`:then=`expected_qty`]]`]]"></div> <div class="picture"> <img src="[[!If? &subject=`[[+img]]` &operator=`!empty` &then=`[[+img:phpthumbof=`w=170`]]` &else=`/assets/hamster/css/images/no_photo.png`]]" /> </div> <div class="info"> <a href="[[~[[+id]]]]" class="title">[[+pagetitle]]</a> <span class="sku">Арт. [[+article]]</span><br /> <div class="buy"><span class="price">[[+price]] <span class="currency">[[+currency:default=`Р`]]</span></span> <a href='#' class="addToCartLink" data-gid="[[+id]]">[[+tv.expected_qty:gt=`0`:then=`Заказать`:else=`В корзину`]] </a> </div> <div class="descr">[[+introtext]]</div> </div> </div> </ins>
<ins class="row show-grid"> {assign var=block_class value=""} {if !empty($product.tvs.novice_good.value) && $product.tvs.novice_good.value == 1} {assign var=block_class value="{$block_class} novice"} {/if} {if !empty($product.tvs.top_buyed.value) && $product.tvs.top_buyed.value == 1} {assign var=block_class value="{$block_class} top_buyed"} {/if} {if !empty($product.tvs.expected_qty.value) && $product.tvs.expected_qty.value == 1} {assign var=block_class value="{$block_class} expected_qty"} {assign var=basket_label value="В корзину"} {else} {assign var=basket_label value="Заказать"} {/if} <div class="r {$block_class}"> <div class="label {$block_class}"></div> <div class="picture"> <img src="{if !empty($product.img)}{snippet name="phpthumbof" params="input=`{$product.img}`&options=`w=170`"}{else}/assets/hamster/css/images/no_photo.png{/if}" /> </div> <div class="info"> <a href="{link id=$product.object_id}" class="title">{$product.pagetitle}</a> <span class="sku">Арт. {$product.article}</span><br /> <div class="buy"><span class="price">{$product.price} <span class="currency">Р</span></span> <a href='#' class="addToCartLink" data-gid="{$product.object_id}">{$basket_label}</a> </div> <div class="descr">{$product.introtext}</div> </div> </div> </ins>
<?php class modWebSidebarMenuIndexProcessor extends modObjectGetListProcessor{ protected $IDs = array(); public function initialize() { $this->setDefaultProperties(array( 'startId' => $this->modx->getOption('shopmodx.catalog_id', null, 0), 'depth' => 3, 'levelClass' => 'level', 'outerTpl' => 'inc/menu/catalog/outer.tpl', 'rowTpl' => 'inc/menu/catalog/row.tpl', 'sortby' => 'pagetitle', 'sortdir' => 'ASC', )); return parent::initialize(); } public function process() { $output = ''; // get current doc id if($pid = $this->modx->resource->parent){ $this->IDs[] = $this->modx->resource->id; while($doc = $this->modx->getObject('modResource', $pid)){ $this->IDs[] = $doc->id; $pid = $doc->parent; } } if(!$items = $this->getMenu()){ return $this->failure(''); } $output = $this->fetchMenu($items); return $this->success($output); } protected function fetchMenu(array $items, $level=0){ $level++; $outer = ''; $rows = ''; $levelClass = $this->getProperty('levelClass'); foreach($items as $item){ $this->count++; $wraper = ''; $cls = array(); if($levelClass){ $cls[] = "{$levelClass}{$level}"; } if(in_array($item['id'], $this->IDs)){ $cls[] = 'active'; } $item['cls'] = $cls; if(!empty($item['childs'])){ $wraper = $this->fetchMenu($item['childs'], $level); } $this->modx->smarty->assign('wraper', $wraper); $this->modx->smarty->assign('item', array( 'link' => $item['uri'], 'title' => $item['menutitle'] ? $item['menutitle'] : $item['pagetitle'], 'cls' => implode(" ", $item['cls']), )); $rows .= $this->modx->smarty->fetch($this->getProperty('rowTpl')); } $this->modx->smarty->assign('wraper', $rows); $output = $this->modx->smarty->fetch($this->getProperty('outerTpl')); return $output; } public function getMenu(){ $key = "{$modx->context->key}/catalog_menu"; if(!$items = $this->modx->cacheManager->get($key)){ $startId = $this->getProperty('startId', 0); $depth = $this->getProperty('depth', 1); if($items = $this->_getMenu($startId, $depth)){ $this->modx->cacheManager->set($key, $items); } } return $items; } protected function _getMenu($id, $depth){ $depth--; $items = array(); $q = $this->modx->newQuery('modResource', array( 'parent' => $id, 'deleted' => 0, 'published' => 1, 'hidemenu' => 0, 'template' => 2, )); $q->select(array( 'id', 'parent', 'uri', 'alias', 'pagetitle', 'menutitle', )); if($sortby = $this->getProperty('sortby')){ $q->sortby($sortby, $this->getProperty('sortdir', 'ASC')); } if($q->prepare() && $q->stmt->execute()){ while($row = $q->stmt->fetch(PDO::FETCH_ASSOC)){ $row['childs'] = array(); if($depth>0){ $row['childs'] = $this->_getMenu($row['id'], $depth); } $items[$row['id']] = $row; } } return $items; } } return 'modWebSidebarMenuIndexProcessor';
{processor ns=modxsite action="web/sidebar/menu/index" assign=menu} {$menu.message}
При этом я абсолютно уверен, что не потребуется ни бухгалтер, ни юрист, ибо они-то как раз и будут наполнять этот билинг купив его.