public function delete() { if (parent::delete()) { $ret = true; $attributes = $this->getAttributes(); foreach ($attributes as $attribute) { $attr = new Attribute((int) $attribute['id_attribute']); $ret &= $attr->delete(); } return $ret; } }
public function postProcess() { if (!Combination::isFeatureActive()) { return; } if (!Tools::getValue($this->identifier) && Tools::getValue('id_attribute') && !Tools::getValue('attributeOrderby')) { // Override var of Controller $this->table = 'attribute'; $this->className = 'Attribute'; $this->identifier = 'id_attribute'; } // If it's an attribute, load object Attribute() if (Tools::getValue('updateattribute') || Tools::isSubmit('deleteattribute') || Tools::isSubmit('submitAddattribute')) { if ($this->tabAccess['edit'] !== '1') { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } else { if (!($object = new Attribute((int) Tools::getValue($this->identifier)))) { $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } } if (Tools::getValue('position') !== false && Tools::getValue('id_attribute')) { $_POST['id_attribute_group'] = $object->id_attribute_group; if (!$object->updatePosition((int) Tools::getValue('way'), (int) Tools::getValue('position'))) { $this->errors[] = Tools::displayError('Failed to update the position.'); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=5&token=' . Tools::getAdminTokenLite('AdminAttributesGroups') . '#details_details_' . $object->id_attribute_group); } } else { if (Tools::isSubmit('deleteattribute') && Tools::getValue('id_attribute')) { if (!$object->delete()) { $this->errors[] = Tools::displayError('Failed to delete the attribute.'); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=1&token=' . Tools::getAdminTokenLite('AdminAttributesGroups')); } } else { if (Tools::isSubmit('submitAddattribute')) { Hook::exec('actionObjectAttributeAddBefore'); $this->action = 'save'; $id_attribute = (int) Tools::getValue('id_attribute'); // Adding last position to the attribute if not exist if ($id_attribute <= 0) { $sql = 'SELECT `position`+1 FROM `' . _DB_PREFIX_ . 'attribute` WHERE `id_attribute_group` = ' . (int) Tools::getValue('id_attribute_group') . ' ORDER BY position DESC'; // set the position of the new group attribute in $_POST for postProcess() method $_POST['position'] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } $_POST['id_parent'] = 0; $this->processSave($this->token); } } } } else { if (Tools::getValue('submitDel' . $this->table)) { if ($this->tabAccess['delete'] === '1') { if (isset($_POST[$this->table . 'Box'])) { $object = new $this->className(); if ($object->deleteSelection($_POST[$this->table . 'Box'])) { Tools::redirectAdmin(self::$currentIndex . '&conf=2' . '&token=' . $this->token); } $this->errors[] = Tools::displayError('An error occurred while deleting this selection.'); } else { $this->errors[] = Tools::displayError('You must select at least one element to delete.'); } } else { $this->errors[] = Tools::displayError('You do not have permission to delete this.'); } // clean position after delete AttributeGroup::cleanPositions(); } else { if (Tools::isSubmit('submitAdd' . $this->table)) { Hook::exec('actionObjectAttributeGroupAddBefore'); $id_attribute_group = (int) Tools::getValue('id_attribute_group'); // Adding last position to the attribute if not exist if ($id_attribute_group <= 0) { $sql = 'SELECT `position`+1 FROM `' . _DB_PREFIX_ . 'attribute_group` ORDER BY position DESC'; // set the position of the new group attribute in $_POST for postProcess() method $_POST['position'] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } // clean \n\r characters foreach ($_POST as $key => $value) { if (preg_match('/^name_/Ui', $key)) { $_POST[$key] = str_replace('\\n', '', str_replace('\\r', '', $value)); } } parent::postProcess(); } else { parent::postProcess(); } } } }