Example #1
0
 /**
  *
  * @param int $parent_id
  * @param int $lang_id
  * @param bool $published
  * @param bool $shop_id
  * @return array
  */
 public static function getChildren($parent_id, $lang_id, $published = true, $shop_id = false)
 {
     if (!JeproshopTools::isBool($published)) {
         die(JError::_());
     }
     $cache_id = 'Category::getChildren_' . (int) $parent_id . '_' . (int) $lang_id . '-' . (bool) $published . '_' . (int) $shop_id;
     if (!JeproshopCache::isStored($cache_id)) {
         $db = JFactory::getDBO();
         $query = "SELECT category." . $db->quoteName('category_id') . ", category_lang." . $db->quoteName('name') . ", category_lang." . $db->quoteName('link_rewrite');
         $query .= ", category_shop." . $db->quoteName('shop_id') . " FROM " . $db->quoteName('#__jeproshop_category') . " AS category LEFT JOIN " . $db->quoteName('#__jeproshop_category_lang');
         $query .= " AS category_lang ON (category." . $db->quoteName('category_id') . " = category_lang." . $db->quoteName('category_id') . JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang');
         $query .= ") " . JeproshopShopModelShop::addSqlAssociation('category') . " WHERE " . $db->quoteName('lang_id') . " = " . (int) $lang_id . " AND category." . $db->quoteName('parent_id');
         $query .= " = " . (int) $parent_id . ($published ? " AND " . $db->quoteName('published') . " = 1" : "") . " GROUP BY category." . $db->quoteName('category_id') . " ORDER BY category_shop.";
         $query .= $db->quoteName('position') . " ASC";
         $db->setQuery($query);
         $result = $db->loadObjectList();
         JeproshopCache::store($cache_id, $result);
     }
     return JeproshopCache::retrieve($cache_id);
 }
Example #2
0
 public function updateCategory()
 {
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     $input = JRequest::get('post');
     $category_data = $input['jform'];
     $languages = JeproshopLanguageModelLanguage::getLanguages();
     $context = JeproshopContext::getContext();
     if (!$context->controller->has_errors) {
         $category_id = (int) $app->input->get('category_id');
         /** update category  */
         if (isset($category_id) && !empty($category_id)) {
             //$category = new JeproshopCategoryModelCategory($category_id);
             if (JeproshopTools::isLoadedObject($this, 'category_id')) {
                 if ($this->category_id == $this->parent_id) {
                     $context->controller->has_errors = true;
                     JError::_(500, JText::_('COM_JEPROSHOP_A_CATEGORY_CANNOT_BE_ITS_OWN_PARENT_LABEL'));
                 }
                 if ($this->is_root_category) {
                     $this->parent_id = JeproshopSettingModelSetting::getValue('root_category');
                 }
                 // Update group selection
                 $this->updateGroup($this->groupBox);
                 $this->depth_level = $this->calculateDepthLevel();
                 // If the parent category was changed, we don't want to have 2 categories with the same position
                 if ($this->getDuplicatedPosition()) {
                     if ($category_data['check_box_shop_associated_category']) {
                         foreach ($category_data['check_box_shop_associated_category'] as $associated_category_id => $row) {
                             foreach ($row as $shop_id => $value) {
                                 $this->addPosition(JeproshopCategoryModelCategory::getLastPosition((int) $this->parent_id, (int) $shop_id), (int) $shop_id);
                             }
                         }
                     } else {
                         foreach (JeproshopShopModelShop::getShops(true) as $shop) {
                             $this->addPosition(max(1, JeproshopCategoryModelCategory::getLastPosition((int) $this->parent_id, $shop->shop_id)), $shop->shop_id);
                         }
                     }
                 }
                 $this->cleanPositions((int) $this->parent_id);
                 $this->clearCache();
                 $this->date_upd = date('Y-m-d H:i:s');
                 $shop_list_ids = JeproshopShopModelShop::getContextListShopIds();
                 if (count($this->shop_list_ids) > 0) {
                     $shop_list_ids = $this->shop_list_ids;
                 }
                 if (JeproshopShopModelShop::checkDefaultShopId('category') && !$this->default_shop_id) {
                     $this->default_shop_id = min($shop_list_ids);
                 }
                 $result = true;
                 $query = "UPDATE " . $db->quoteName('#__jeproshop_category') . " SET " . $db->quoteName('n_left') . " = " . (int) $this->n_left . ", ";
                 $query .= $db->quoteName('n_right') . " = " . (int) $this->n_right . ", " . $db->quoteName('depth_level') . " = " . (int) $this->depth_level;
                 $query .= ", " . $db->quoteName('published') . " = " . (int) $category_data['published'] . ", " . $db->quoteName('default_shop_id') . " = " . (int) $this->default_shop_id;
                 $query .= ", " . $db->quoteName('is_root_category') . " = " . (int) $category_data['is_root_category'] . ", " . $db->quoteName('position') . " = ";
                 $query .= (int) $this->position . ", " . $db->quoteName('date_upd') . " = " . $db->quote($this->date_upd) . " WHERE " . $db->quoteName('category_id');
                 $query .= " = " . (int) $this->category_id;
                 $db->setQuery($query);
                 $result &= $db->query();
                 foreach ($shop_list_ids as $shop_id) {
                     $where = " WHERE " . $db->quoteName('category_id') . " = " . (int) $this->category_id . " AND " . $db->quoteName('shop_id') . " = " . (int) $shop_id;
                     $select = "SELECT " . $db->quoteName('category_id') . " FROM " . $db->quoteName('#__jeproshop_category_shop') . $where;
                     $db->setQuery($select);
                     $shop_exist = $db->loadObject()->category_id > 0;
                     if ($shop_exist) {
                         $query = "UPDATE " . $db->quoteName('#__jeproshop_category_shop') . " SET " . $db->quoteName('position') . " = " . (int) $this->position . $where;
                         $db->setQuery($query);
                         $result &= $db->query();
                     } elseif (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) {
                         $query = "INSERT INTO " . $db->quoteName('#__jeproshop_category_shop') . "(" . $db->quoteName('category_id') . ", " . $db->quoteName('shop_id') . ", " . $db->quoteName('position');
                         $query .= ") VALUES (" . (int) $this->category_id . ", " . (int) $shop_id . ", " . (int) $this->position . ")";
                         $db->setQuery($query);
                         $result &= $db->query();
                     }
                     foreach ($languages as $language) {
                         $where = " WHERE " . $db->quoteName('category_id') . " = " . (int) $this->category_id . " AND " . $db->quoteName('shop_id');
                         $where .= " = " . (int) $shop_id . " AND " . $db->quoteName('lang_id') . " = " . (int) $language->lang_id;
                         $select = "SELECT COUNT(*) FROM " . $db->quoteNAme('#__jeproshop_category_lang') . $where;
                         $db->setQuery($select);
                         $lang_exist = $db->loadResult();
                         if ($lang_exist) {
                             $query = "UPDATE " . $db->quoteName('#__jeproshop_category_lang') . " SET " . $db->quoteName('name') . " = " . $db->quote($category_data['name_' . $language->lang_id]) . ", ";
                             $query .= $db->quoteName('description') . " = " . $db->quote($category_data['description_' . $language->lang_id]) . ", " . $db->quoteName('link_rewrite') . " = ";
                             $query .= $db->quote($category_data['link_rewrite_' . $language->lang_id]) . ", " . $db->quoteName('meta_title') . " = " . $db->quote($category_data['meta_title_' . $language->lang_id]);
                             $query .= ", " . $db->quoteName('meta_keywords') . " = " . $db->quote($category_data['meta_keywords_' . $language->lang_id]) . ", " . $db->quoteName('meta_description');
                             $query .= " = " . $db->quote($category_data['meta_description_' . $language->lang_id]) . $where;
                         } else {
                             $query = "INSERT INTO " . $db->quoteName('#__jeproshop_category_lang') . " (" . $db->quoteName('name') . ", " . $db->quoteName('description') . ", " . $db->quoteName('link_rewrite');
                             $query .= ", " . $db->quoteName('meta_title') . ", " . $db->quoteName('meta_keywords') . ", " . $db->quoteName('meta_description') . ") VALUES (" . $db->quote($category_data['name_' . $language->lang_id]);
                             $query .= ", " . $db->quote($category_data['description_' . $language->lang_id]) . ", " . $db->quote($category_data['link_rewrite_' . $language->lang_id]) . ", ";
                             $query .= $db->quote($category_data['meta_title_' . $language->lang_id]) . ", " . $db->quote($category_data['meta_keywords_' . $language->lang_id]) . ", ";
                             $query .= $db->quote($category_data['meta_description_' . $language->lang_id]) . ") " . $where;
                         }
                         $db->setQuery($query);
                         $result &= $db->query();
                     }
                 }
                 if (!isset($this->doNotRegenerateNTree) || !$this->doNotRegenerateNTree) {
                     JeproshopCategoryModelCategory::regenerateEntireNestedtree();
                     $this->recalculateLevelDepth($this->category_id);
                 }
             }
             $message = '';
             $link = 'index.php?option=com_jeproshop&view=category&category_id=' . (int) $this->category_id . '&task=edit' . JeproshopTools::getCategoryToken();
         } else {
             $message = '';
             $link = 'index.php?option=com_jeproshop&view=category&category_id=' . (int) $this->category_id . '&task=edit' . JeproshopTools::getCategoryToken();
         }
         $app->redirect($link, $message);
     }
 }