Problem
I'm having a strange issue with my url_key
field reverting to NULL
on my catalog_category_flat_store_1
table following a reindex, but only on categories that I have created since enabling the Flat Category index.
As a result, when I attempt to fetch the category via url_key
as so:
$category = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToFilter('url_key', 'my-url-key')
->getFirstItem();
$category->load($category->getId());
I am unable to do so. If I go back and re-save the category, the url_key is added back to the flat table and I'm able to retrieve the category.
Has anyone else had this problem or am I missing something regarding the way flat tables operate?
What I've Found/Tried
Because the value would initially save and then disappear, I examined the catalog_category_entity files. Here's what I found:
- The
url_key
value is saving properly incatalog_category_entity_url_key
- However, neither the
url_key
nor theurl_path
attributes are saving incatalog_category_entity_varchar
as they were with categories that I created before enabling Flat tables. - If I manually add the
url_key
tocatalog_category_entity_varchar
, values are preserved and copied tocatalog_category_flat_store_1
as expected when reindexing.
I have tried disabling the flat tables and while the url_key
value is still not saved to catalog_category_entity_varchar, I am able to category via the url_key using my code above.
FWIW, I'm using Enterprise 1.13.
Update
I used MAGMI to import my products/categories; because CE uses varchar
attributes rather than a separate table as the newer versions of enterprise do, this may be a non-issue. I created a fresh install of Enterprise and added the categories manually. I'm noticing that the url_key
and url_path
fields are not copied over to the flat tables anyway.
Best Answer
In Magento Enterprise 1.13 (or 1.12) url_key attribute was moved to its own table catalog_category_entiry_url_key (similarly product url_key attribute has its own table catalog_product_entiry_url_key). Also in 1.13 indexers were changed and are now run by the cronjob instead of manually. The problem is that indexer only takes values from catalog_category_entity_(varchar|int|decimal|text|datetime) and not catalog_category_entiry_url_key. Quick fix is to create a new module and rewrite
enterprise_catalog/index_action_category_flat_refresh
model with:and in the class add
url_key
to$attributesType
arrayThis will add url_key to flat tables during reindex but it probably won't work with MAGMI import module.