function sitemap() { $map = []; $zeroItems = \Ecommerce\Item::getList(['where' => ['category_id', 0]]); foreach ($zeroItems as $item) { $map[] = ['name' => $item->name, 'url' => ['loc' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . INJI_DOMAIN_NAME . $item->getHref()]]; } $categorys = \Ecommerce\Category::getList(['where' => ['parent_id', 0]]); $scan = function ($category, $scan) { $map = []; foreach ($category->items as $item) { $map[] = ['name' => $item->name, 'url' => ['loc' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . INJI_DOMAIN_NAME . $item->getHref()]]; } foreach ($category->catalogs as $child) { $map = array_merge($map, $scan($child, $scan)); } return $map; }; foreach ($categorys as $category) { $map = array_merge($map, $scan($category, $scan)); } return $map; }
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')]); }