Back to Top

Alphabetical Sorting in Magento

Updated 15 February 2011

If you are dealing with magento category i am very sure that you’ll face this problem .Magento category fetching is not an issue its a child play but sorting thse categories is little tricky , so here the is SQL part by which you can sort the categories in alphabetical order

SET @i=0;
SET @j=0;
DROP TABLE IF EXISTS AAA_NEW_POSITION;
CREATE TABLE AAA_NEW_POSITION
SELECT e.entity_id AS 'entity_id',
vn.value AS 'name',
e.position AS 'old_position', @i:=@i+1 AS 'new_position'
FROM
catalog_category_entity e
LEFT JOIN catalog_category_entity_varchar vn
ON e.entity_id = vn.entity_id AND
vn.attribute_id = 33
ORDER BY vn.value;

ALTER TABLE AAA_NEW_POSITION ORDER BY name;
UPDATE AAA_NEW_POSITION SET new_position= @j:=@j+1 ORDER BY name;

UPDATE
catalog_category_entity e
LEFT JOIN AAA_NEW_POSITION np
ON e.entity_id = np.entity_id
SET
e.position = np.new_position;DROP TABLE IF EXISTS AAA_NEW_POSITION;

Searching for an experienced
Magento Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home