【发布时间】:2012-10-25 12:20:37
【问题描述】:
我使用以下代码向我的 Magento 安装添加了一个自定义类别属性:
<?php
// initialize magento environment for 'default' store
require_once 'app/Mage.php';
Mage::app('default');
echo "initialising";
echo runAdd();
echo "finishing";
function runAdd()
{
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
// below code will add text attribute
$setup->addAttribute('catalog_category', 'test_field', array(
'group' => 'General',
'input' => 'text',
'type' => 'varchar',
'label' => 'a new text field',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
}
我在实际检索我在后端设置的值时遇到了很大的困难。我已经尝试了以下所有变体:
$_category = Mage::getModel('catalog/category')->load(1000);
$data = $_category->getData();
$atts= $_category->getAttributes();
var_dump($data );
var_dump($atts);
等等,但是卡住了。
有人知道我将如何检索这些数据吗?
【问题讨论】:
-
你检查过属性是否真的被添加了吗?
-
@FlorinelChis 它出现在后端管理员中,并在保存和更改类别后仍然存在,因此我认为它已正确添加。他们是否是一种特殊的验证方法,你会知道除此之外?
-
使用 ID 1000 保存该类别并重新编制索引后问题仍然存在?
-
@Rodgers 和 Hammertim 可能是您忘记在后端创建属性期间给前端可见“true”。
-
@FlorinelChis 如果您的意思是通过重新索引来刷新缓存,那么不幸的是没有区别。
标签: php magento magento-1.5