Magento:应该在以下代码中使用哪个表?

时间:2012-01-30 20:28:28

标签: magento

我读过这篇文章http://inchoo.net/ecommerce/magento/how-to-add-new-custom-category-attribute-in-magento/comment-page-1/

安装程序中有部分代码:

//this will set data of your custom attribute for root category
Mage::getModel('catalog/category')
    ->load(1)
    ->setImportedCatId(0)
    ->setInitialSetupFlag(true)
    ->save();

//this will set data of your custom attribute for default category
Mage::getModel('catalog/category')
    ->load(2)
    ->setImportedCatId(0)
    ->setInitialSetupFlag(true)
    ->save();

这里有两个问题:

功能加载有一个参数。这是身份证。 应该使用哪个表?

这里的setImportedCatId是什么?它是setter,但我没有说明它是什么。

1 个答案:

答案 0 :(得分:5)

Magento类别仍然使用EAV表结构,因此您感兴趣的表是

catalog_category_entity

但是,您将无法在此处看到类别名称。类别对象的大多数数据都保留为

catalog_category_entity_varchar

通过catalog_category_entity索引回entity_id表。

我在现代源代码树周围徘徊,看起来数据属性imported_cat_id(这是setter可能设置的内容),但基于Magento系统中其他地方使用的模式,我的猜测是某些版本的Magento在类别保存树中有代码imported_cat_id,如果已设置,则新类别数据将基于旧类别。换句话说,它允许您快速复制类别并保存其所有元数据。通过将其设置为0,Inchoo代码告诉Magento这是一个新类别。

这只是猜测,但这不是我担心的事情。