anjuMV Posted February 16, 2024 Share Posted February 16, 2024 to achieve enable or disable category shop-wise, i have added a new 'active' column in category_shop table. after that in front office category page shows an error Column 'active' in where clause is ambiguous. how can i fix this ? Link to comment Share on other sites More sharing options...
Mediacom87 Posted February 16, 2024 Share Posted February 16, 2024 Hi, If you wish to add data linked to a native table, you must do so in another table, associating the two tables. Next, you need to analyze the structure of the columns called up in the SQL query, and if the active column exists in several tables when it is called up, you need to specify the table concerned. Link to comment Share on other sites More sharing options...
anjuMV Posted February 16, 2024 Author Share Posted February 16, 2024 @Mediacom87 public function getSubCategories($idLang, $active = true) { $sqlGroupsWhere = ''; $sqlGroupsJoin = ''; if (Group::isFeatureActive()) { $sqlGroupsJoin = 'LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`)'; $groups = FrontController::getCurrentCustomerGroups(); $sqlGroupsWhere = 'AND cg.`id_group` ' . (count($groups) ? 'IN (' . implode(',', $groups) . ')' : '=' . (int) Configuration::get('PS_UNIDENTIFIED_GROUP')); } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.*, category_shop.*, cl.`id_lang`, cl.`name`, cl.`description`, cl.`link_rewrite`, cl.`meta_title`, cl.`meta_keywords`, cl.`meta_description` FROM `' . _DB_PREFIX_ . 'category` c ' . Shop::addSqlAssociation('category', 'c') . ' LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . (int) $idLang . ' ' . Shop::addSqlRestrictionOnLang('cl') . ') ' . $sqlGroupsJoin . ' WHERE `id_parent` = ' . (int) $this->id . ' ' . ($active ? 'AND category_shop.`active` = 1' : '') . ' ' . $sqlGroupsWhere . ' GROUP BY c.`id_category` ORDER BY `level_depth` ASC, category_shop.`position` ASC'); foreach ($result as &$row) { $row['id_image'] = Tools::file_exists_cache($this->image_dir . $row['id_category'] . '.jpg') ? (int) $row['id_category'] : Language::getIsoById($idLang) . '-default'; $row['legend'] = 'no picture'; } return $result; } i modified ($active ? 'AND `active` = 1' : '') to ($active ? 'AND category_shop.`active` = 1' : ''). is that enough ? or which are the functions that i can override from Category class ? Link to comment Share on other sites More sharing options...
Mediacom87 Posted February 16, 2024 Share Posted February 16, 2024 il y a 14 minutes, anjuMV a dit : @Mediacom87 public function getSubCategories($idLang, $active = true) { $sqlGroupsWhere = ''; $sqlGroupsJoin = ''; if (Group::isFeatureActive()) { $sqlGroupsJoin = 'LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`)'; $groups = FrontController::getCurrentCustomerGroups(); $sqlGroupsWhere = 'AND cg.`id_group` ' . (count($groups) ? 'IN (' . implode(',', $groups) . ')' : '=' . (int) Configuration::get('PS_UNIDENTIFIED_GROUP')); } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.*, category_shop.*, cl.`id_lang`, cl.`name`, cl.`description`, cl.`link_rewrite`, cl.`meta_title`, cl.`meta_keywords`, cl.`meta_description` FROM `' . _DB_PREFIX_ . 'category` c ' . Shop::addSqlAssociation('category', 'c') . ' LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . (int) $idLang . ' ' . Shop::addSqlRestrictionOnLang('cl') . ') ' . $sqlGroupsJoin . ' WHERE `id_parent` = ' . (int) $this->id . ' ' . ($active ? 'AND category_shop.`active` = 1' : '') . ' ' . $sqlGroupsWhere . ' GROUP BY c.`id_category` ORDER BY `level_depth` ASC, category_shop.`position` ASC'); foreach ($result as &$row) { $row['id_image'] = Tools::file_exists_cache($this->image_dir . $row['id_category'] . '.jpg') ? (int) $row['id_category'] : Language::getIsoById($idLang) . '-default'; $row['legend'] = 'no picture'; } return $result; } i modified ($active ? 'AND `active` = 1' : '') to ($active ? 'AND category_shop.`active` = 1' : ''). is that enough ? or which are the functions that i can override from Category class ? I don't know, you're the one who knows whether it works or not, and above all where your data comes from, which version of PrestaShop you're working on and which file you're working on. You seem to be working directly on a core file, so this is another bad idea. Link to comment Share on other sites More sharing options...
anjuMV Posted February 16, 2024 Author Share Posted February 16, 2024 @Mediacom87 in prestashop 1.7. i am overriding Category controller functions. the above code is in override/classes/Category.php Link to comment Share on other sites More sharing options...
Mediacom87 Posted February 16, 2024 Share Posted February 16, 2024 il y a 24 minutes, anjuMV a dit : @Mediacom87 in prestashop 1.7. i am overriding Category controller functions. the above code is in override/classes/Category.php So, did you change something and test it, and it gives you a new error message, or didn't you test it? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now