Last active
July 29, 2019 13:52
-
-
Save dvdmierden/59f3e9d4c1e7588b8ab9e04a0061be36 to your computer and use it in GitHub Desktop.
Reorder Magento categories in database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// step 1, create temporary table | |
// get attribute from eav_attribute table, entity_type_id = 3 for category | |
CREATE TABLE _category_order | |
SELECT | |
e.entity_id AS 'entity_id', | |
ce.value AS 'name', | |
e.position AS 'current_position' | |
'1' AS 'new_position' | |
FROM | |
catalog_category_entity e | |
LEFT JOIN | |
catalog_category_entity_varchar ce | |
ON | |
e.entity_id = ce.entity_id | |
AND | |
ce.attribute_id = 41 | |
ORDER BY | |
ce.value; | |
// set proper order | |
SET @x = 0; | |
UPDATE _category_order SET new_position = (@x:=@x+1) ORDER BY name ASC | |
// update Magento table | |
UPDATE | |
catalog_category_entity e | |
LEFT JOIN | |
_category_order co | |
ON | |
e.entity_id = co.entity_id | |
SET | |
e.position = co.new_position; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment