Skip to content

Instantly share code, notes, and snippets.

@webdawe
Last active September 8, 2016 00:55
Show Gist options
  • Save webdawe/7055537684b58a61a4765705e9e109c1 to your computer and use it in GitHub Desktop.
Save webdawe/7055537684b58a61a4765705e9e109c1 to your computer and use it in GitHub Desktop.
Magento Get Active Category List
#Retrieve Entity Type Ids
SET @categoryEntityTypeId := (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_category');
SET @nameAttributeId := (select attribute_id FROM eav_attribute where attribute_code = 'name' and entity_type_id = @categoryEntityTypeId);
SET @descriptionAttributeId := (select attribute_id FROM eav_attribute where attribute_code = 'description' and entity_type_id = @categoryEntityTypeId);
SET @metaTitleAttributeId := (select attribute_id FROM eav_attribute where attribute_code = 'meta_title' and entity_type_id = @categoryEntityTypeId);
SET @metaDescriptionAttributeId := (select attribute_id FROM eav_attribute where attribute_code = 'meta_description' and entity_type_id = @categoryEntityTypeId);
SET @isActiveAttributeId := (select attribute_id FROM eav_attribute where attribute_code = 'is_active' and entity_type_id = @categoryEntityTypeId);
SELECT DISTINCT c.entity_id as `Category_Id`,
name.value as `Name`,
description.value as `Description`,
meta_title.value as `Meta_Title`,
meta_description.value as `Meta_Description`
FROM catalog_category_entity c
LEFT JOIN catalog_category_entity_varchar name ON name.entity_id = c.entity_id AND name.store_id = 0
LEFT JOIN catalog_category_entity_text description ON description.entity_id = c.entity_id AND description.store_id = 0
LEFT JOIN catalog_category_entity_varchar meta_title ON meta_title.entity_id = c.entity_id AND meta_title.store_id = 0
LEFT JOIN catalog_category_entity_text meta_description ON meta_description.entity_id = c.entity_id AND meta_description.store_id = 0
LEFT JOIN catalog_category_entity_int is_active ON is_active.entity_id = c.entity_id AND is_active.store_id = 0
WHERE
name.attribute_id = @nameAttributeId
AND description.attribute_id = @descriptionAttributeId
AND meta_title.attribute_id = @metaTitleAttributeId
AND meta_description.attribute_id = @metaDescriptionAttributeId
AND is_active.attribute_id = @isActiveAttributeId
AND is_active.value = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment