diff --git a/install-dev/php/add_attribute_position.php b/install-dev/php/add_attribute_position.php new file mode 100755 index 000000000..f23e439df --- /dev/null +++ b/install-dev/php/add_attribute_position.php @@ -0,0 +1,51 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 6844 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +function add_attribute_position() +{ + $groups = Db::getInstance()->ExecuteS(' + SELECT `id_attribute_group` + FROM `'._DB_PREFIX_.'attribute`'); + if (sizeof($groups) && is_array($groups)) + foreach ($groups as $group) + { + $attributes = Db::getInstance()->ExecuteS(' + SELECT * + FROM `'._DB_PREFIX_.'attribute` + WHERE `id_attribute_group` = '. (int)($group['id_attribute_group'])); + $i = 0; + if (sizeof($attributes) && is_array($attributes)) + foreach ($attributes as $attribute) + { + Db::getInstance()->Execute(' + UPDATE `'._DB_PREFIX_.'attribute` + SET `position` = '.$i++.' + WHERE `id_attribute` = '.(int)$attribute['id_attribute'].' + AND `id_attribute_group` = '.(int)$attribute['id_attribute_group']); + } + } +} \ No newline at end of file