Beispiel #1
0
 /**
  * Getting items params with params
  * 
  * @param array $params
  * @return array
  */
 public function getItemsParams($params = [])
 {
     $selectOptions = $this->parseOptions($params);
     $items = Ecommerce\Item::getList($selectOptions);
     $items = Ecommerce\Item\Param::getList(['where' => ['item_id', array_keys($items), 'IN'], 'join' => [[Ecommerce\Item\Option::table(), Ecommerce\Item\Option::index() . ' = ' . \Ecommerce\Item\Param::colPrefix() . Ecommerce\Item\Option::index() . ' and ' . \Ecommerce\Item\Option::colPrefix() . 'searchable = 1', 'inner']], 'distinct' => \Ecommerce\Item\Option::index()]);
     return $items;
 }
Beispiel #2
0
 public function itemListAction($category_id = 0)
 {
     //search
     if (!empty($_GET['search'])) {
         if (!empty($_GET['inCatalog'])) {
             $category_id = (int) $_GET['inCatalog'];
         }
         $search = $_GET['search'];
     } else {
         $search = '';
     }
     //sort
     if (!empty($_GET['sort'])) {
         $sort = $_GET['sort'];
     } elseif (!empty($this->ecommerce->config['defaultSort'])) {
         $sort = $this->ecommerce->config['defaultSort'];
     } else {
         $sort = ['name' => 'asc'];
     }
     //category
     $category = null;
     if ($category_id) {
         if (is_numeric($category_id)) {
             $category = \Ecommerce\Category::get($category_id);
         }
         if (!$category) {
             $category = \Ecommerce\Category::get($category_id, 'alias');
         }
         if ($category) {
             $category_id = $category->id;
         } else {
             $category_id = 0;
         }
     } else {
         $category_id = 0;
     }
     $active = $category_id;
     //items pages
     $pages = new \Ui\Pages($_GET, ['count' => $this->ecommerce->getItemsCount(['parent' => $category_id, 'search' => trim($search), 'filters' => !empty($_GET['filters']) ? $_GET['filters'] : []]), 'limit' => 18]);
     //bread
     $bread = [];
     if (!$category || !$category->name) {
         $bread[] = array('text' => 'Каталог');
         $this->view->setTitle('Каталог');
     } else {
         $bread[] = array('text' => 'Каталог', 'href' => '/ecommerce');
         $categoryIds = array_values(array_filter(explode('/', $category->tree_path)));
         foreach ($categoryIds as $id) {
             $cat = Ecommerce\Category::get($id);
             $bread[] = array('text' => $cat->name, 'href' => '/ecommerce/itemList/' . $cat->id);
         }
         $bread[] = array('text' => $category->name);
         $this->view->setTitle($category->name);
     }
     //items
     $items = $this->ecommerce->getItems(['parent' => $category_id, 'start' => $pages->params['start'], 'count' => $pages->params['limit'], 'search' => trim($search), 'sort' => $sort, 'filters' => !empty($_GET['filters']) ? $_GET['filters'] : []]);
     //params
     if (empty(App::$cur->ecommerce->config['filtersInLast'])) {
         $options = \Ecommerce\Item\Option::getList(['where' => ['item_option_searchable', 1]]);
     } else {
         $params = $this->ecommerce->getItemsParams(['parent' => $category_id, 'search' => trim($search), 'filters' => !empty($_GET['filters']) ? $_GET['filters'] : []]);
         $ids = [];
         foreach ($params as $param) {
             $ids[] = $param->item_option_id;
         }
         if ($ids) {
             $options = \Ecommerce\Item\Option::getList(['where' => ['id', $ids, 'IN']]);
         } else {
             $options = [];
         }
     }
     //child categorys
     if ($category) {
         $categorys = $category->catalogs;
     } else {
         $categorys = \Ecommerce\Category::getList(['where' => ['parent_id', 0]]);
     }
     //view content
     $this->view->page(['page' => $category ? $category->resolveTemplate() : 'current', 'content' => $category ? $category->resolveViewer() : (!empty(App::$cur->ecommerce->config['defaultCategoryView']) ? App::$cur->ecommerce->config['defaultCategoryView'] : 'itemList'), 'data' => compact('active', 'category', 'sort', 'search', 'pages', 'items', 'categorys', 'bread', 'options')]);
 }