juanccub Posted September 19 Share Posted September 19 Hello everyone! I am writing to you because I have a problem with my PrestaShop for which I can't find a solution. I have several hundred products on my site, and many of them have a "custom value" assigned to a specific attribute "bracelet material." I would like to remove all the custom values of this attribute, but doing it product by product in the backoffice would take me months. Is there a way to automate this, to remove all the custom values of this attribute? Perhaps with a module or an SQL query? Thank you in advance for your help! Link to comment Share on other sites More sharing options...
ps8modules Posted September 21 Share Posted September 21 Hi. There is no need for any special features and I am surprised that Prestashop does not already have such a feature built in. Just edit the file: ./controllers/admin/AdminFeaturesController.php 1. find the renderView() function and edit it like this: public function renderView() { if ($id = (int) Tools::getValue('id_feature')) { $this->setTypeValue(); $this->list_id = 'feature_value'; $this->lang = true; // Action for list $this->addRowAction('edit'); $this->addRowAction('delete'); if (!Validate::isLoadedObject($obj = new Feature((int) $id))) { $this->errors[] = $this->trans('An error occurred while updating the status for an object.', [], 'Admin.Notifications.Error') . ' <b>' . $this->table . '</b> ' . $this->trans('(cannot load object)', [], 'Admin.Notifications.Error'); return; } $this->feature_name = $obj->name; $this->toolbar_title = $this->feature_name[$this->context->employee->id_lang]; $this->fields_list = [ 'id_feature_value' => [ 'title' => $this->trans('ID', [], 'Admin.Global'), 'align' => 'center', 'class' => 'fixed-width-xs', ], 'value' => [ 'title' => $this->trans('Value', [], 'Admin.Global'), ], /* ADDED PS8MODULES */ 'custom' => [ 'title' => $this->trans('Custom', [], 'Admin.Global'), 'align' => 'center', 'class' => 'fixed-width-xs', 'type' => 'bool', 'filter_key' => 'custom' ], ]; $this->_where = sprintf('AND `id_feature` = %d', (int) $id); self::$currentIndex = self::$currentIndex . '&id_feature=' . (int) $id . '&viewfeature'; $this->processFilter(); return parent::renderList(); } } 2. find the function getList(.....) and edit it like this: public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) { if ($this->table == 'feature_value') { $this->_where .= ' AND (a.custom = 0 OR a.custom IS NULL OR a.custom = 1)'; } parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop); if ($this->table == 'feature') { $nb_items = count($this->_list); for ($i = 0; $i < $nb_items; ++$i) { $item = &$this->_list[$i]; $query = new DbQuery(); $query->select('COUNT(fv.id_feature_value) as count_values'); $query->from('feature_value', 'fv'); $query->where('fv.id_feature =' . (int) $item['id_feature']); $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); $item['value'] = (int) $res; unset($query); } } } 3. save the edited file 4. clear Cache 1 Link to comment Share on other sites More sharing options...
juanccub Posted September 22 Author Share Posted September 22 On 9/21/2024 at 8:51 AM, ps8modules said: Thank you very much, it works perfectly! Hi. There is no need for any special features and I am surprised that Prestashop does not already have such a feature built in. Just edit the file: ./controllers/admin/AdminFeaturesController.php 1. find the renderView() function and edit it like this: public function renderView() { if ($id = (int) Tools::getValue('id_feature')) { $this->setTypeValue(); $this->list_id = 'feature_value'; $this->lang = true; // Action for list $this->addRowAction('edit'); $this->addRowAction('delete'); if (!Validate::isLoadedObject($obj = new Feature((int) $id))) { $this->errors[] = $this->trans('An error occurred while updating the status for an object.', [], 'Admin.Notifications.Error') . ' <b>' . $this->table . '</b> ' . $this->trans('(cannot load object)', [], 'Admin.Notifications.Error'); return; } $this->feature_name = $obj->name; $this->toolbar_title = $this->feature_name[$this->context->employee->id_lang]; $this->fields_list = [ 'id_feature_value' => [ 'title' => $this->trans('ID', [], 'Admin.Global'), 'align' => 'center', 'class' => 'fixed-width-xs', ], 'value' => [ 'title' => $this->trans('Value', [], 'Admin.Global'), ], /* ADDED PS8MODULES */ 'custom' => [ 'title' => $this->trans('Custom', [], 'Admin.Global'), 'align' => 'center', 'class' => 'fixed-width-xs', 'type' => 'bool', 'filter_key' => 'custom' ], ]; $this->_where = sprintf('AND `id_feature` = %d', (int) $id); self::$currentIndex = self::$currentIndex . '&id_feature=' . (int) $id . '&viewfeature'; $this->processFilter(); return parent::renderList(); } } 2. find the function getList(.....) and edit it like this: public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) { if ($this->table == 'feature_value') { $this->_where .= ' AND (a.custom = 0 OR a.custom IS NULL OR a.custom = 1)'; } parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop); if ($this->table == 'feature') { $nb_items = count($this->_list); for ($i = 0; $i < $nb_items; ++$i) { $item = &$this->_list[$i]; $query = new DbQuery(); $query->select('COUNT(fv.id_feature_value) as count_values'); $query->from('feature_value', 'fv'); $query->where('fv.id_feature =' . (int) $item['id_feature']); $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); $item['value'] = (int) $res; unset($query); } } } 3. save the edited file 4. clear Cache 1 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