/** * Get Each parent category of this category until the root category * * @param integer $id_lang Language ID * @return array Corresponding categories */ public function _getParentsCategories($id_current = NULL) { $context = Context::getContext()->cloneContext(); $context->shop = clone $context->shop; $id_lang = $context->language->id; $categories = null; if (count(Category::getCategoriesWithoutParent()) > 1 && Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && count(Shop::getShops(true, null, true)) != 1) { $context->shop->id_category = Category::getTopCategory()->id; } elseif (!$context->shop->id) { $context->shop = new Shop(Configuration::get('PS_SHOP_DEFAULT')); } $id_shop = $context->shop->id; while (true) { $sql = ' SELECT c.*, cl.* FROM `' . _DB_PREFIX_ . 'category` c LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl') . ')'; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (c.`id_category` = cs.`id_category` AND cs.`id_shop` = ' . (int) $id_shop . ')'; } $sql .= ' WHERE c.`id_category` = ' . (int) $id_current; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' AND cs.`id_shop` = ' . (int) $context->shop->id; } $root_category = Category::getRootCategory(); if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP && (!Tools::isSubmit('id_category') || (int) Tools::getValue('id_category') == (int) $root_category->id || (int) $root_category->id == (int) $context->shop->id_category)) { $sql .= ' AND c.`id_parent` != 0'; } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if (isset($result[0])) { $categories[] = $result[0]; } else { if (!$categories) { $categories = array(); } } if (!$result || $result[0]['id_category'] == $context->shop->id_category) { return $categories; } $id_current = $result[0]['id_parent']; } }
public function initToolbar() { if (empty($this->display)) { if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE')) { $this->toolbar_btn['new-url'] = array('href' => self::$currentIndex . '&add' . $this->table . 'root&token=' . $this->token, 'desc' => $this->l('Add new root category')); } $this->toolbar_btn['new'] = array('href' => self::$currentIndex . '&add' . $this->table . '&token=' . $this->token, 'desc' => $this->l('Add new')); $this->toolbar_btn['import'] = array('href' => $this->context->link->getAdminLink('AdminImport', true) . '&import_type=' . $this->table, 'desc' => $this->l('Import')); } // be able to edit the Home category if (count(Category::getCategoriesWithoutParent()) == 1 && !Tools::isSubmit('id_category') && ($this->display == 'view' || empty($this->display))) { $this->toolbar_btn['edit'] = array('href' => self::$currentIndex . '&update' . $this->table . '&id_category=' . (int) $this->_category->id . '&token=' . $this->token, 'desc' => $this->l('Edit')); } if (Tools::getValue('id_category') && !Tools::isSubmit('updatecategory')) { $this->toolbar_btn['edit'] = array('href' => self::$currentIndex . '&update' . $this->table . '&id_category=' . (int) Tools::getValue('id_category') . '&token=' . $this->token, 'desc' => $this->l('Edit')); } if ($this->display == 'view') { $this->toolbar_btn['new'] = array('href' => self::$currentIndex . '&add' . $this->table . '&id_parent=' . (int) Tools::getValue('id_category') . '&token=' . $this->token, 'desc' => $this->l('Add new')); } parent::initToolbar(); if ($this->_category->id == Category::getTopCategory()->id && isset($this->toolbar_btn['new'])) { unset($this->toolbar_btn['new']); } // after adding a category if (empty($this->display)) { $id_category = Tools::isSubmit('id_category') ? '&id_parent=' . (int) Tools::getValue('id_category') : ''; $this->toolbar_btn['new'] = array('href' => self::$currentIndex . '&add' . $this->table . '&token=' . $this->token . $id_category, 'desc' => $this->l('Add new')); if (Tools::isSubmit('id_category')) { $back = Tools::safeOutput(Tools::getValue('back', '')); if (empty($back)) { $back = self::$currentIndex . '&token=' . $this->token; } $this->toolbar_btn['back'] = array('href' => $back, 'desc' => $this->l('Back to list')); } } }
public function initToolbar() { if (empty($this->display)) { $this->toolbar_btn['new'] = array('href' => self::$currentIndex . '&add' . $this->table . '&token=' . $this->token, 'desc' => $this->trans('Add New', array(), 'Admin.Actions')); if ($this->can_import) { $this->toolbar_btn['import'] = array('href' => $this->context->link->getAdminLink('AdminImport', true) . '&import_type=categories', 'desc' => $this->trans('Import', array(), 'Admin.Actions')); } } // be able to edit the Home category if (count(Category::getCategoriesWithoutParent()) == 1 && !Tools::isSubmit('id_category') && ($this->display == 'view' || empty($this->display))) { $this->toolbar_btn['edit'] = array('href' => self::$currentIndex . '&update' . $this->table . '&id_category=' . (int) $this->_category->id . '&token=' . $this->token, 'desc' => $this->trans('Edit', array(), 'Admin.Actions')); } if (Tools::getValue('id_category') && !Tools::isSubmit('updatecategory')) { $this->toolbar_btn['edit'] = array('href' => self::$currentIndex . '&update' . $this->table . '&id_category=' . (int) Tools::getValue('id_category') . '&token=' . $this->token, 'desc' => $this->trans('Edit', array(), 'Admin.Actions')); } if ($this->display == 'view') { $this->toolbar_btn['new'] = array('href' => self::$currentIndex . '&add' . $this->table . '&id_parent=' . (int) Tools::getValue('id_category') . '&token=' . $this->token, 'desc' => $this->trans('Add New', array(), 'Admin.Actions')); } parent::initToolbar(); if ($this->_category->id == (int) Configuration::get('PS_ROOT_CATEGORY') && isset($this->toolbar_btn['new'])) { unset($this->toolbar_btn['new']); } // after adding a category if (empty($this->display)) { $id_category = Tools::isSubmit('id_category') ? '&id_parent=' . (int) Tools::getValue('id_category') : ''; $this->toolbar_btn['new'] = array('href' => self::$currentIndex . '&add' . $this->table . '&token=' . $this->token . $id_category, 'desc' => $this->trans('Add New', array(), 'Admin.Actions')); if (Tools::isSubmit('id_category')) { $back = Tools::safeOutput(Tools::getValue('back', '')); if (empty($back)) { $back = self::$currentIndex . '&token=' . $this->token; } $this->toolbar_btn['back'] = array('href' => $back, 'desc' => $this->trans('Back to list', array(), 'Admin.Actions')); } } if (!$this->lite_display && isset($this->toolbar_btn['back']['href']) && $this->_category->level_depth > 1 && $this->_category->id_parent && $this->_category->id_parent != (int) Configuration::get('PS_ROOT_CATEGORY')) { $this->toolbar_btn['back']['href'] .= '&id_category=' . (int) $this->_category->id_parent; } }