/** * 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; } }
public function renderEditForm($tpl = null) { $this->loadObject(true); $app = JFactory::getApplication(); if (!isset($this->context)) { $this->context = JeproshopContext::getContext(); } $shop_id = JeproshopContext::getContext()->shop->shop_id; $selected_categories = array(isset($this->context->controller->category->parent_id) && $this->context->controller->category->isParentCategoryAvailable($shop_id) ? (int) $this->context->controller->category->parent_id : $app->input->get('parent_id', JeproshopCategoryModelCategory::getRootCategory()->category_id)); $unidentified = new JeproshopGroupModelGroup(JeproshopSettingModelSetting::getValue('unidentified_group')); $guest = new JeproshopGroupModelGroup(JeproshopSettingModelSetting::getValue('guest_group')); $default = new JeproshopGroupModelGroup(JeproshopSettingModelSetting::getValue('customer_group')); $unidentified_group_information = '<b>' . $unidentified->name[$this->context->language->lang_id] . '</b> ' . JText::_('COM_JEPROSHOP_ALL_PEOPLE_WITHOUT_A_VALID_CUSTOMER_ACCOUNT_MESSAGE'); $guest_group_information = '<b>' . $guest->name[$this->context->language->lang_id] . '</b> ' . JText::_('COM_JEPROSHOP_CUSTOMER_WHO_PLACED_AN_ORDER_WITH_THE_GUEST_CHECKOUT_MESSAGE'); $default_group_information = '<b>' . $default->name[$this->context->language->lang_id] . '</b> ' . JText::_('COM_JEPROSHOP_ALL_PEOPLE_WHO_HAVE_CREATED_AN_CREATED_AN_ACCOUNT_ON_THIS_SITE_MESSAGE'); $this->assignRef('unidentified_group_information', $unidentified_group_information); $this->assignRef('guest_group_information', $guest_group_information); $this->assignRef('default_group_information', $default_group_information); $image = COM_JEPROSHOP_CATEGORY_IMAGE_DIR . $this->context->controller->category->category_id . '.jpg'; $image_url = JeproshopImageManager::thumbnail($image, 'category_' . $this->context->controller->category->category_id . '.jpg', 350, 'jpg', true, true); $imageSize = file_exists($image) ? filesize($image) / 1000 : false; $shared_category = JeproshopTools::isLoadedObject($this->context->controller->category, 'category_id') && $this->context->controller->category->hasMultishopEntries(); $this->assignRef('shared_category', $shared_category); $allow_accented_chars_url = (int) JeproshopSettingModelSetting::getValue('allow_accented_chars_url'); $this->assignRef('allow_accented_chars_url', $allow_accented_chars_url); //$this->assignRef('selected_categories', $selected_categories); $categories_tree = new JeproshopCategoriesTree('jform_categories_tree', JText::_('COM_JEPROSHOP_CATEGORIES_LABEL'), null, $this->context->language->lang_id); $categories_tree->setTreeTemplate('associated_categories')->setSelectedCategories($selected_categories)->setUseCheckBox(true)->setInputName('parent_id'); $categories_data = $categories_tree->render(); $this->assignRef('categories_tree', $categories_data); $image = JeproshopImageManager::thumbnail(COM_JEPROSHOP_CATEGORY_IMAGE_DIR . '/' . $this->context->controller->category->category_id . '.jpg', 'category_' . (int) $this->context->controller->category->category_id . '.jpg', 350, 'jpg', true); $this->assignRef('image', $image ? $image : false); $size = $image ? filesize(COM_JEPROSHOP_CATEGORY_IMAGE_DIR . '/' . $this->context->controller->category->category_id . 'jpg') / 1000 : false; $this->assignRef('size', $size); $category_group_ids = $this->context->controller->category->getGroups(); $groups = JeproshopGroupModelGroup::getGroups($this->context->language->lang_id); //if empty $carrier_groups_ids : object creation : we set the default groups if (empty($category_group_ids)) { $preSelected = array(JeproshopSettingModelSetting::getValue('unidentified_group'), JeproshopSettingModelSetting::getValue('guest_group'), JeproshopSettingModelSetting::getValue('customer_group')); $category_group_ids = array_merge($category_group_ids, $preSelected); } foreach ($groups as $group) { $groupBox = $app->input->get('group_box_' . $group->group_id, in_array($group->group_id, $category_group_ids)); $this->assignRef('group_box_' . $group->group_id, $groupBox); } $is_root_category = (bool) $app->input->get('is_root_category'); $this->assignRef('is_root_category', $is_root_category); $helper = new JeproshopHelper(); $this->assignRef('helper', $helper); $this->assignRef('groups', $groups); $this->addToolBar(); $this->sideBar = JHtmlSideBar::render(); parent::display($tpl); }
private function initAssociationsForm() { $app = JFactory::getApplication(); /** prepare category tree **/ $root = JeproshopCategoryModelCategory::getRootCategory(); $default_category_id = $this->context->cookie->products_filter_category_id ? $this->context->cookie->products_filter_category_id : JeproshopContext::getContext()->shop->category_id; $categoryBox = $app->input->get('category_box', array($default_category_id)); if (!$this->product->product_id || !$this->product->isAssociatedToShop()) { $selected_category = JeproshopCategoryModelCategory::getCategoryInformations($categoryBox, $this->context->controller->default_form_language); } else { if ($categoryBox) { $selected_category = JeproshopCategoryModelCategory::getCategoryInformations($categoryBox); } else { $selected_category = JeproshopProductModelProduct::getProductCategoriesFull($this->product->product_id, $this->context->controller->default_form_language); } } // Multishop block $feature_shop_active = JeproshopShopModelShop::isFeaturePublished(); $this->assignRef('feature_shop_published', $feature_shop_active); /** Accessories **/ $accessories = JeproshopProductModelProduct::getAccessoriesLight($this->context->language->lang_id, $this->product->product_id); $postAccessories = $app->input->get('input_accessories'); if ($postAccessories) { $postAccessoriesTab = explode('-', $postAccessories); foreach ($postAccessoriesTab as $accessory_id) { $accessory = JeproshopProductModelProduct::getAccessoryById($accessory_id); if (!$this->hasThisAccessory($accessory_id, $accessories) && $accessory) { $accessories[] = $accessory; } } } $this->assignRef('accessories', $accessories); $this->product->manufacturer_name = JeproshopManufacturerModelManufacturer::getNameById($this->product->manufacturer_id); $categories = array(); foreach ($selected_category as $key => $category) { $categories[] = $key; } $manufacturers = JeproshopManufacturerModelManufacturer::getManufacturers($this->context->language->lang_id); $categories_tree = new JeproshopCategoriesTree('associated_categories_tree', JText::_('COM_JEPROSHOP_ASSOCIATED_CATEGORIES_LABEL')); $categories_tree->setTreeLayout('associated_categories')->setRootCategory((int) $root->category_id)->setUseCheckBox(true)->setSelectedCategories($categories); $this->assignRef('manufacturers', $manufacturers); $selected_category_ids = implode(',', array_keys($selected_category)); $this->assignRef('selected_category_ids', $selected_category_ids); $this->assignRef('selected_category', $selected_category); $categoryId = $this->product->getDefaultCategoryId(); $this->assignRef('default_category_id', $categoryId); $category_tree = $categories_tree->render(); $this->assignRef('category_tree', $category_tree); $is_shop_context = JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP; $this->assignRef('is_shop_context', $is_shop_context); }