Ejemplo n.º 1
0
 public function renderDetails($tpl = null)
 {
     $app = JFactory::getApplication();
     $category_id = $app->input->get('category_id');
     if (!isset($this->context) || empty($this->context)) {
         $this->context = JeproshopContext::getContext();
     }
     if (!JeproshopShopModelShop::isFeaturePublished() && count(JeproshopCategoryModelCategory::getCategoriesWithoutParent()) > 1 && $category_id) {
         $categories_tree = array(get_object_vars($this->context->controller->category->getTopCategory()));
     } else {
         $categories_tree = $this->context->controller->category->getParentsCategories();
         $end = end($categories_tree);
         if (isset($categories_tree) && !JeproshopShopModelShop::isFeaturePublished() && (isset($end) && $end->parent_id != 0)) {
             $categories_tree = array_merge($categories_tree, array(get_object_vars($this->context->controller->category->getTopCategory())));
         }
     }
     $count_categories_without_parent = count(JeproshopCategoryModelCategory::getCategoriesWithoutParent());
     if (empty($categories_tree) && ($this->context->controller->category->category_id != 1 || $category_id) && (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP && !JeproshopShopModelShop::isFeaturePublished() && $count_categories_without_parent > 1)) {
         $categories_tree = array(array('name' => $this->context->controller->category->name[$this->context->language->lang_id]));
     }
     $categories_tree = array_reverse($categories_tree);
     $this->assignRef('categories_tree', $categories_tree);
     $this->assignRef('categories_tree_current_id', $this->context->controller->category->category_id);
     $categoryModel = new JeproshopCategoryModelCategory();
     $categories = $categoryModel->getCategoriesList();
     $pagination = $categoryModel->getPagination();
     $this->assignRef('pagination', $pagination);
     $this->assignRef('categories', $categories);
     $this->setLayout('default');
     $this->addToolBar();
     $this->sideBar = JHtmlSideBar::render();
     parent::display($tpl);
 }
Ejemplo n.º 2
0
 public function initialize()
 {
     $app = JFactory::getApplication();
     $context = JeproshopContext::getContext();
     parent::initialize();
     $category_id = $app->input->get('category_id');
     $task = $app->input->get('task');
     if ($category_id && $task != 'delete') {
         $this->category = new JeproshopCategoryModelCategory($category_id);
     } else {
         if (JeproshopShopModelShop::isFeaturePublished() && JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) {
             $this->category = new JeproshopCategoryModelCategory($context->shop->category_id);
         } elseif (count(JeproshopCategoryModelCategory::getCategoriesWithoutParent()) > 1 && JeproshopSettingModelSetting::getValue('multishop_feature_active') && count(JeproshopShopModelShop::getShops(true, null, true)) != 1) {
             $this->category = JeproshopCategoryModelCategory::getTopCategory();
         } else {
             $this->category = new JeproshopCategoryModelCategory(JeproshopSettingModelSetting::getValue('root_category'));
         }
     }
     if (JeproshopTools::isLoadedObject($this->category, 'category_id') && !$this->category->isAssociatedToShop() && JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) {
         $app->redirect('index.php?option=com_jeproshop&view=category&task=edit&category_id=' . (int) $context->shop->getCategoryId() . '&' . JeproshopTools::getCategoryToken() . '=1');
     }
 }
Ejemplo n.º 3
0
 /**
  * Get Each parent category of this category until the root category
  *
  * @param integer $lang_id Language ID
  * @return array Corresponding categories
  */
 public function getParentsCategories($lang_id = null)
 {
     $context = JeproshopContext::getContext()->cloneContext();
     $context->shop = clone $context->shop;
     $category_id = JFactory::getApplication()->input->get('category_id');
     if (is_null($lang_id)) {
         $lang_id = $context->language->lang_id;
     }
     $categories = null;
     $current_id = $this->category_id;
     if (count(JeproshopCategoryModelCategory::getCategoriesWithoutParent()) > 1 && JeproshopSettingModelSetting::getValue('multishop_feature_active') && count(JeproshopShopModelShop::getShops(true, null, true)) != 1) {
         $context->shop->category_id = JeproshopCategoryModelCategory::getTopCategory()->category_id;
     } elseif (!$context->shop->shop_id) {
         $context->shop = new JeproshopShopModelShop(JeproshopSettingModelSetting::getValue('default_shop'));
     }
     $shop_id = $context->shop->shop_id;
     $db = JFactory::getDBO();
     while (true) {
         $query = "SELECT category.*, category_lang.* FROM " . $db->quoteName('#__jeproshop_category') . " AS category LEFT JOIN " . $db->quoteName('#__jeproshop_category_lang') . " AS category_lang ON (category.";
         $query .= $db->quoteName('category_id') . " = category_lang." . $db->quoteName('category_id') . " AND " . $db->quoteName('lang_id') . " = " . (int) $lang_id . JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang') . ")";
         if (JeproshopShopModelShop::isFeaturePublished() && JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) {
             $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_category_shop') . " AS category_shop ON (category." . $db->quoteName('category_id') . " = category_shop.";
             $query .= $db->quoteName('category_id') . " AND category_shop." . $db->quoteName('shop_id') . " = " . (int) $shop_id . ")";
         }
         $query .= " WHERE category." . $db->quoteName('category_id') . " = " . (int) $current_id;
         if (JeproshopShopModelShop::isFeaturePublished() && JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) {
             $query .= " AND category_shop." . $db->quoteName('shop_id') . " = " . (int) $context->shop->shop_id;
         }
         $root_category = JeproshopCategoryModelCategory::getRootCategory();
         if (JeproshopShopModelShop::isFeaturePublished() && JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP && (!$category_id || (int) $category_id == (int) $root_category->category_id || (int) $root_category->category_id == (int) $context->shop->category_id)) {
             $query .= " AND category." . $db->quoteName('parent_id') . " != 0";
         }
         $db->setQuery($query);
         $result = $db->loadObject();
         if ($result) {
             $categories[] = $result;
         } elseif (!$categories) {
             $categories = array();
         }
         if (!$result || $result->category_id == $context->shop->category_id) {
             return $categories;
         }
         $current_id = $result->parent_id;
     }
 }