Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SET @position = 0;
- SET @last_parent = 0;
- SET @last_level = 0;
- DROP TABLE IF EXISTS `cce_new_position`;
- CREATE TEMPORARY TABLE `cce_new_position`
- SELECT
- `new`.`entity_id` AS `entity_id`,
- `new`.`parent_id` AS `parent_id`,
- @last_parent := CAST(`new`.`parent_id` AS UNSIGNED) AS `new_parent_id`,
- `new`.`name` AS `name`,
- `new`.`level` AS `level`,
- @last_level := CAST(`new`.`level` AS UNSIGNED) AS `new_level`,
- `new`.`position` AS `position`,
- @position := (IF((@last_parent != `new`.`parent_id`) OR (@last_level != `new`.`level`), 0, @position) + 1) AS `new_position`
- FROM (
- SELECT
- `e`.`entity_id` AS `entity_id`,
- `e`.`parent_id` AS `parent_id`,
- TRIM(`v`.`value`) AS `name`,
- `e`.`position` AS `position`,
- `e`.`level` AS `level`,
- `e`.`path` AS `path`
- FROM `catalog_category_entity` AS `e`
- LEFT JOIN `catalog_category_entity_varchar` AS `v` ON `e`.`entity_id` = `v`.`entity_id` AND `v`.`attribute_id` = 33
- -- WHERE (`e`.`entity_id` != 1 AND `e`.`entity_id` != 4)
- ORDER BY `level`, `parent_id`, `name` ASC
- ) AS `new`;
- -- Review Changes
- SELECT * FROM `cce_new_position`;
- -- Commit Changes
- UPDATE
- `catalog_category_entity` AS `e`
- LEFT JOIN `cce_new_position` AS `np` ON `e`.`entity_id` = `np`.`entity_id`
- SET
- `e`.`position` = `np`.`new_position`;
- DROP TABLE IF EXISTS `cce_new_position`;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement