本文整理汇总了PHP中Category::getNestedCategories方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::getNestedCategories方法的具体用法?PHP Category::getNestedCategories怎么用?PHP Category::getNestedCategories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Category
的用法示例。
在下文中一共展示了Category::getNestedCategories方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getData
public function getData()
{
if (!isset($this->_data)) {
$this->setData(Category::getNestedCategories($this->getRootCategory(), $this->getLang(), false, null, $this->useShopRestriction()));
}
return $this->_data;
}
示例2: renderForm
public function renderForm()
{
$fields_form = array('form' => array('legend' => array('title' => $this->l('Homepage categories'), 'icon' => ''), 'input' => array(array('type' => 'cat_choice', 'label' => '', 'name' => 'cats')), 'submit' => array('name' => 'submitBlockhomecats', 'title' => $this->l('Save'))));
$lang = $this->context->language;
if ($selectedCats = Configuration::get('MOD_BLOCKHOMECATS_CATS')) {
$selectedCats = explode(',', $selectedCats);
foreach ($selectedCats as $index => $id_category) {
$selectedCats[$index] = new Category($id_category, $this->context->language->id);
}
} else {
$selectedCats = null;
}
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->module = $this;
$helper->identifier = 'id_blocklink';
$helper->submit_action = 'submit';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->fields_value = array('text' => 'text');
$categories = Category::getNestedCategories(2, $this->context->language->id, false);
$helper->tpl_vars = array('allCats' => $this->getAllCats(current($categories)), 'selectedCats' => $selectedCats);
return $helper->generateForm(array($fields_form));
}
示例3: getData
public function getData()
{
if (!isset($this->_data)) {
$categories = Category::getNestedCategories();
$products = $this->getProductsDB();
$categories = $this->populateCategoriesWithProducts($categories, $products);
$this->setData($categories);
}
return $this->_data;
}
示例4: getData
public function getData()
{
if (!isset($this->_data)) {
$shop = $this->getShop();
$lang = $this->getLang();
$root_category = (int) $this->getRootCategory();
if ($this->_full_tree) {
$this->setData(Category::getNestedCategories($root_category, $lang, false, null, $this->useShopRestriction()));
$this->setDataSearch(Category::getAllCategoriesName($root_category, $lang, false, null, $this->useShopRestriction()));
} elseif ($this->_children_only) {
if (empty($root_category)) {
$root_category = Category::getRootCategory()->id;
}
$categories[$root_category] = Category::getChildren($root_category, $lang, false, $shop->id);
$children = $this->fillTree($categories, $root_category);
$this->setData($children);
} else {
if (empty($root_category)) {
$root_category = Category::getRootCategory()->id;
}
$new_selected_categories = array();
$selected_categories = $this->getSelectedCategories();
$categories[$root_category] = Category::getChildren($root_category, $lang, false, $shop->id);
foreach ($selected_categories as $selected_category) {
$category = new Category($selected_category, $lang, $shop->id);
$new_selected_categories[] = $selected_category;
$parents = $category->getParentsCategories($lang);
foreach ($parents as $value) {
$new_selected_categories[] = $value['id_category'];
}
}
$new_selected_categories = array_unique($new_selected_categories);
foreach ($new_selected_categories as $selected_category) {
$current_category = Category::getChildren($selected_category, $lang, false, $shop->id);
if (!empty($current_category)) {
$categories[$selected_category] = $current_category;
}
}
$tree = Category::getCategoryInformations(array($root_category), $lang);
$children = $this->fillTree($categories, $root_category);
if (!empty($children)) {
$tree[$root_category]['children'] = $children;
}
$this->setData($tree);
$this->setDataSearch(Category::getAllCategoriesName($root_category, $lang, false, null, $this->useShopRestriction()));
}
}
return $this->_data;
}
示例5: makeMenu
protected function makeMenu()
{
$menu_items = $this->getMenuItems();
$id_lang = (int) $this->context->language->id;
$id_shop = (int) Shop::getContextShopID();
foreach ($menu_items as $item) {
if (!$item) {
continue;
}
preg_match($this->pattern, $item, $value);
$id = (int) substr($item, strlen($value[1]), strlen($item));
switch (substr($item, 0, strlen($value[1]))) {
case 'CAT':
$this->_menu .= $this->generateCategoriesMenu(Category::getNestedCategories($id, $id_lang, false, $this->user_groups));
break;
case 'PRD':
$selected = $this->page_name == 'product' && Tools::getValue('id_product') == $id ? ' class="sfHover"' : '';
$product = new Product((int) $id, true, (int) $id_lang);
if (!is_null($product->id)) {
$this->_menu .= '<li' . $selected . '><a href="' . Tools::HtmlEntitiesUTF8($product->getLink()) . '" title="' . $product->name . '">' . $product->name . '</a></li>' . PHP_EOL;
}
break;
case 'CMS':
$selected = $this->page_name == 'cms' && Tools::getValue('id_cms') == $id ? ' class="sfHover"' : '';
$cms = CMS::getLinks((int) $id_lang, array($id));
if (count($cms)) {
$this->_menu .= '<li' . $selected . '><a href="' . Tools::HtmlEntitiesUTF8($cms[0]['link']) . '" title="' . Tools::safeOutput($cms[0]['meta_title']) . '">' . Tools::safeOutput($cms[0]['meta_title']) . '</a></li>' . PHP_EOL;
}
break;
case 'CMS_CAT':
$category = new CMSCategory((int) $id, (int) $id_lang);
if (count($category)) {
$this->_menu .= '<li><a href="' . Tools::HtmlEntitiesUTF8($category->getLink()) . '" title="' . $category->name . '">' . $category->name . '</a>';
$this->getCMSMenuItems($category->id);
$this->_menu .= '</li>' . PHP_EOL;
}
break;
// Case to handle the option to show all Manufacturers
// Case to handle the option to show all Manufacturers
case 'ALLMAN':
$link = new Link();
$this->_menu .= '<li><a href="' . $link->getPageLink('manufacturer') . '" title="' . $this->l('All manufacturers') . '">' . $this->l('All manufacturers') . '</a><ul>' . PHP_EOL;
$manufacturers = Manufacturer::getManufacturers();
foreach ($manufacturers as $key => $manufacturer) {
$this->_menu .= '<li><a href="' . $link->getManufacturerLink((int) $manufacturer['id_manufacturer'], $manufacturer['link_rewrite']) . '" title="' . Tools::safeOutput($manufacturer['name']) . '">' . Tools::safeOutput($manufacturer['name']) . '</a></li>' . PHP_EOL;
}
$this->_menu .= '</ul>';
break;
case 'MAN':
$selected = $this->page_name == 'manufacturer' && Tools::getValue('id_manufacturer') == $id ? ' class="sfHover"' : '';
$manufacturer = new Manufacturer((int) $id, (int) $id_lang);
if (!is_null($manufacturer->id)) {
if (intval(Configuration::get('PS_REWRITING_SETTINGS'))) {
$manufacturer->link_rewrite = Tools::link_rewrite($manufacturer->name);
} else {
$manufacturer->link_rewrite = 0;
}
$link = new Link();
$this->_menu .= '<li' . $selected . '><a href="' . Tools::HtmlEntitiesUTF8($link->getManufacturerLink((int) $id, $manufacturer->link_rewrite)) . '" title="' . Tools::safeOutput($manufacturer->name) . '">' . Tools::safeOutput($manufacturer->name) . '</a></li>' . PHP_EOL;
}
break;
// Case to handle the option to show all Suppliers
// Case to handle the option to show all Suppliers
case 'ALLSUP':
$link = new Link();
$this->_menu .= '<li><a href="' . $link->getPageLink('supplier') . '" title="' . $this->l('All suppliers') . '">' . $this->l('All suppliers') . '</a><ul>' . PHP_EOL;
$suppliers = Supplier::getSuppliers();
foreach ($suppliers as $key => $supplier) {
$this->_menu .= '<li><a href="' . $link->getSupplierLink((int) $supplier['id_supplier'], $supplier['link_rewrite']) . '" title="' . Tools::safeOutput($supplier['name']) . '">' . Tools::safeOutput($supplier['name']) . '</a></li>' . PHP_EOL;
}
$this->_menu .= '</ul>';
break;
case 'SUP':
$selected = $this->page_name == 'supplier' && Tools::getValue('id_supplier') == $id ? ' class="sfHover"' : '';
$supplier = new Supplier((int) $id, (int) $id_lang);
if (!is_null($supplier->id)) {
$link = new Link();
$this->_menu .= '<li' . $selected . '><a href="' . Tools::HtmlEntitiesUTF8($link->getSupplierLink((int) $id, $supplier->link_rewrite)) . '" title="' . $supplier->name . '">' . $supplier->name . '</a></li>' . PHP_EOL;
}
break;
case 'SHOP':
$selected = $this->page_name == 'index' && $this->context->shop->id == $id ? ' class="sfHover"' : '';
$shop = new Shop((int) $id);
if (Validate::isLoadedObject($shop)) {
$link = new Link();
$this->_menu .= '<li' . $selected . '><a href="' . Tools::HtmlEntitiesUTF8($shop->getBaseURL()) . '" title="' . $shop->name . '">' . $shop->name . '</a></li>' . PHP_EOL;
}
break;
case 'LNK':
$link = MenuTopLinks::get((int) $id, (int) $id_lang, (int) $id_shop);
if (count($link)) {
if (!isset($link[0]['label']) || $link[0]['label'] == '') {
$default_language = Configuration::get('PS_LANG_DEFAULT');
$link = MenuTopLinks::get($link[0]['id_linksmenutop'], $default_language, (int) Shop::getContextShopID());
}
$this->_menu .= '<li><a href="' . Tools::HtmlEntitiesUTF8($link[0]['link']) . '"' . ($link[0]['new_window'] ? ' onclick="return !window.open(this.href);"' : '') . ' title="' . Tools::safeOutput($link[0]['label']) . '">' . Tools::safeOutput($link[0]['label']) . '</a></li>' . PHP_EOL;
}
break;
}
}
//.........这里部分代码省略.........
示例6: displayTop
public function displayTop()
{
//if (!$this->isCached('blocktopmenu2.tpl', $this->getCacheId()))
//{
$this->user_groups = $this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP'));
$categoryMain = current(Category::getNestedCategories(146, $this->context->language->id, true, $this->user_groups));
//$this->loadCategories(146);
// $categoryComplects = new Category(129, $this->context->language->id);
// $categoryWholesale = new Category(148, $this->context->language->id);
// $cmsopt = new CMS(11, $this->context->language->id);
$categoryComplects = current(Category::getNestedCategories(129, $this->context->language->id, true, $this->user_groups));
$categoryComplectsDecor = current(Category::getNestedCategories(198, $this->context->language->id, true, $this->user_groups));
$categoryFurniture = current(Category::getNestedCategories(7, $this->context->language->id, true, $this->user_groups));
//$this->loadCategories(7);
$shop_id = (int) $this->context->shop->id;
$shop_group_id = Shop::getGroupFromShop($shop_id);
$item_day_id = Db::getInstance()->getValue("SELECT id_product FROM " . _DB_PREFIX_ . "product WHERE item_for_day=1 AND active=1 ORDER BY RAND()");
if ($item_day_id) {
require_once dirname(dirname(__FILE__)) . '/productcomments/ProductComment.php';
$prodict_day = new Product($item_day_id, true, $this->context->language->id, $this->context->shop->id);
$average = ProductComment::getAverageGrade($prodict_day->id);
$cover = Product::getCover((int) $prodict_day->id, $this->context);
$this->context->smarty->assign(array('priceDisplayPrecisionDay' => _PS_PRICE_DISPLAY_PRECISION_, 'have_image_day' => isset($cover['id_image']) && (int) $cover['id_image'] ? true : false, 'cover_day' => $cover, 'categoryComplects' => $categoryComplects, 'categoryComplectsDecor' => $categoryComplectsDecor, 'averageTotalDay' => round($average['grade']), 'ratingsDay' => ProductComment::getRatings((int) $prodict_day->id), 'nbCommentsDay' => (int) ProductComment::getCommentNumber((int) $prodict_day->id)));
} else {
$prodict_day = null;
}
$this->context->smarty->assign(array('prodict_day' => $prodict_day, 'prodict_day_url' => is_object($prodict_day) ? $this->context->link->getProductLink($prodict_day) : null, 'search' => Configuration::get('MOD_blocktopmenu2_SEARCH', null, $shop_group_id, $shop_id), 'categoryMain' => $categoryMain, 'categoryComplects' => $categoryComplects, 'categoryComplectsDecor' => $categoryComplectsDecor, 'categoryWholesale' => new Category(148, $this->context->language->id), 'cmsopt' => new CMS(11, $this->context->language->id), 'categoryFurniture' => $categoryFurniture));
// echo '<pre>'; var_dump($this->context->smarty->getTemplateVars('categoryMain')); echo '</pre>'; die();
//}
return $this->display(__FILE__, 'blocktopmenu2.tpl', $this->getCacheId());
}
示例7: makeMenu
protected function makeMenu()
{
$root_node = $this->makeNode(['label' => null, 'type' => 'root', 'children' => []]);
$menu_items = $this->getMenuItems();
$id_lang = (int) $this->context->language->id;
$id_shop = (int) Shop::getContextShopID();
foreach ($menu_items as $item) {
if (!$item) {
continue;
}
preg_match($this->pattern, $item, $value);
$id = (int) substr($item, strlen($value[1]), strlen($item));
switch (substr($item, 0, strlen($value[1]))) {
case 'CAT':
$categories = $this->generateCategoriesMenu(Category::getNestedCategories($id, $id_lang, false, $this->user_groups));
$root_node['children'] = array_merge($root_node['children'], $categories);
break;
case 'PRD':
$product = new Product((int) $id, true, (int) $id_lang);
if ($product->id) {
$root_node['children'][] = $this->makeNode(['type' => 'product', 'page_identifier' => 'product-' . $product->id, 'label' => $product->name, 'url' => $product->getLink()]);
}
break;
case 'CMS':
$cms = CMS::getLinks((int) $id_lang, array($id));
if (count($cms)) {
$root_node['children'][] = $this->makeNode(['type' => 'cms-page', 'page_identifier' => 'cms-page-' . $id, 'label' => $cms[0]['meta_title'], 'url' => $cms[0]['link']]);
}
break;
case 'CMS_CAT':
$root_node['children'][] = $this->generateCMSCategoriesMenu((int) $id, (int) $id_lang);
break;
// Case to handle the option to show all Manufacturers
// Case to handle the option to show all Manufacturers
case 'ALLMAN':
$children = array_map(function ($manufacturer) use($id_lang) {
return $this->makeNode(['type' => 'manufacturer', 'page_identifier' => 'manufacturer-' . $manufacturer['id_manufacturer'], 'label' => $manufacturer['name'], 'url' => $this->context->link->getManufacturerLink(new Manufacturer($manufacturer['id_manufacturer'], $id_lang), null, $id_lang)]);
}, Manufacturer::getManufacturers());
$root_node['children'][] = $this->makeNode(['type' => 'manufacturers', 'page_identifier' => 'manufacturers', 'label' => $this->l('All manufacturers'), 'url' => $this->context->link->getPageLink('manufacturer'), 'children' => $children]);
break;
case 'MAN':
$manufacturer = new Manufacturer($id, $id_lang);
if ($manufacturer->id) {
$root_node['children'][] = $this->makeNode(['type' => 'manufacturer', 'page_identifier' => 'manufacturer-' . $manufacturer->id, 'label' => $manufacturer->name, 'url' => $this->context->link->getManufacturerLink($manufacturer, null, $id_lang)]);
}
break;
// Case to handle the option to show all Suppliers
// Case to handle the option to show all Suppliers
case 'ALLSUP':
$children = array_map(function ($supplier) use($id_lang) {
return $this->makeNode(['type' => 'supplier', 'page_identifier' => 'supplier-' . $supplier['id_supplier'], 'label' => $supplier['name'], 'url' => $this->context->link->getSupplierLink(new Supplier($supplier['id_supplier'], $id_lang), null, $id_lang)]);
}, Supplier::getSuppliers());
$root_node['children'][] = $this->makeNode(['type' => 'suppliers', 'page_identifier' => 'suppliers', 'label' => $this->l('All suppliers'), 'url' => $this->context->link->getPageLink('supplier'), 'children' => $children]);
break;
case 'SUP':
$supplier = new Supplier($id, $id_lang);
if ($supplier->id) {
$root_node['children'][] = $this->makeNode(['type' => 'supplier', 'page_identifier' => 'supplier-' . $supplier->id, 'label' => $supplier->name, 'url' => $this->context->link->getSupplierLink($supplier, null, $id_lang)]);
}
break;
case 'SHOP':
$shop = new Shop((int) $id);
if (Validate::isLoadedObject($shop)) {
$root_node['children'][] = $this->makeNode(['type' => 'shop', 'page_identifier' => 'shop-' . $id, 'label' => $shop->name, 'url' => $shop->getBaseURL()]);
}
break;
case 'LNK':
$link = Ps_MenuTopLinks::get($id, $id_lang, $id_shop);
if (!empty($link)) {
if (!isset($link[0]['label']) || $link[0]['label'] == '') {
$default_language = Configuration::get('PS_LANG_DEFAULT');
$link = Ps_MenuTopLinks::get($link[0]['id_linksmenutop'], $default_language, (int) Shop::getContextShopID());
}
$root_node['children'][] = $this->makeNode(['type' => 'link', 'page_identifier' => $link[0]['link'], 'label' => $link[0]['label'], 'url' => $link[0]['link'], 'open_in_new_window' => $link[0]['new_window']]);
}
break;
}
}
return $this->mapTree(function ($node, $depth) {
$node['depth'] = $depth;
return $node;
}, $root_node);
}
示例8: displayCategoriesSelect
private function displayCategoriesSelect($categories, $selected)
{
$this->_html .= '<label>' . $this->l('Category') . '</label>
<div class="margin-form"><select name="id_category">
<option value="">-- ' . $this->l('Choose') . ' --</option>';
if (version_compare(_PS_VERSION_, '1.6.0.0', '>=') && method_exists('Category', 'getNestedCategories')) {
foreach (Category::getNestedCategories(Configuration::get('PS_ROOT_CATEGORY'), $this->_cookie->id_lang) as $idCategory => $categoryInformations) {
if (Configuration::get('PS_ROOT_CATEGORY') != $idCategory) {
$this->_html .= '<option value="' . $idCategory . '"' . ($selected == $idCategory ? ' selected="selected"' : '') . '>' . str_repeat('– ', version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? $categoryInformations['level_depth'] - 1 : $categoryInformations['level_depth']) . $categoryInformations['name'] . '</option>';
}
$this->_getChildrensCategories($categoryInformations, $selected);
}
} else {
if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && method_exists('Category', 'recurseLiteCategTree')) {
$rootCategory = new Category((int) Category::getRootCategory()->id, $this->_cookie->id_lang);
if (Configuration::get('PS_ROOT_CATEGORY') != $rootCategory->id) {
$this->_html .= '<option value="' . $rootCategory->id . '"' . ($selected == $rootCategory->id ? ' selected="selected"' : '') . '>' . $rootCategory->name . '</option>';
}
$this->_getChildrensCategories($rootCategory->recurseLiteCategTree(99999, 0, $this->_cookie->id_lang), $selected, 0);
} else {
$categories_bkup = $categories;
$first_category = array_shift($categories_bkup);
array_unshift($categories_bkup, $first_category);
$first_category_final = array_shift($first_category);
$this->recurseCategory($categories, $first_category_final, version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Category::getRootCategory()->id : 1, $selected);
}
}
$this->_html .= ' </select></div>';
}
示例9: buildCategoryTree
/**
* Builds menu item
*
* @param array $menuItem
* @param int $id_shop
* @param int $id_lang
*
* @return array
*/
protected function buildCategoryTree(array $menuItem, $id_shop, $id_lang)
{
$id_category = (int) $menuItem['entity_id'];
$category = new Category($id_category, $id_lang, $id_shop);
if (!$category->active) {
return false;
}
if ($this->context->customer->isLogged()) {
$groups = $this->context->customer->getGroups();
} else {
$groups = array(Configuration::get('PS_UNIDENTIFIED_GROUP'));
}
$treeMaxDepth = max(0, (int) $menuItem['tree_max_depth']);
// @TODO How is this recursive ??
$categoryTree = Category::getNestedCategories($id_category, $id_lang, true, $groups);
$subItems = array();
if (!empty($categoryTree[$id_category]['children'])) {
foreach ($categoryTree[$id_category]['children'] as $categoryTreeChild) {
$subItems[] = $this->buildCategoryTreeItem($categoryTreeChild, $id_shop, $id_lang, 1, $treeMaxDepth);
}
}
$url = empty($menuItem['url']) ? $this->context->link->getCategoryLink($category) : $menuItem['url'];
return array('name' => empty($menuItem['name']) ? $category->name : $menuItem['name'], 'url' => $url, 'title' => empty($menuItem['title']) ? $category->name : $menuItem['title'], 'icon' => $menuItem['icon'], 'no_follow' => $menuItem['no_follow'], 'id' => $menuItem['id_ct_top_menu_item'], 'entity_id' => 'cat-' . $id_category, 'class' => $menuItem['class'], 'type' => 'category-tree', 'sub_items' => $subItems);
}
示例10: getPrestaProdChildCat
}
return Cache::retrieve($cache_id);
}
public static function getPrestaProdChildCat($cats)
{
foreach ($cats as $cat) {
if ($cat['id_shop'] == Context::getContext()->shop->id) {
self::$prestaprds['category_' . $cat['id_category']] = $cat['name'];
}
if (isset($cat['children']) && !empty($cat['children'])) {
self::getPrestaProdChildCat($cat['children']);
}
}
}
public static function getPrestaProdCat()
{
if (method_exists('Category', 'getNestedCategories')) {
$cats = Category::getNestedCategories(null, (int) Context::getContext()->language->id, true);
} else {
$cats = self::getNestedCategories(null, (int) Context::getContext()->language->id, true);