通过安装程序脚本在Magento中删除自定义属性 [英] Removing a custom attribute in Magento via an installer script

查看:53
本文介绍了通过安装程序脚本在Magento中删除自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在安装脚本&现在需要通过安装程序脚本删除is_school属性,我的代码正确吗?

I have the following code in an installer script & need to now remove the is_school attribute via the installer script, is my code correct?

// code within existing installer script (this works fine)
$installer->addAttribute("customer", "is_school",  array(
"type"     => "int",
"backend"  => "",
"label"    => "Is School?",
"input"    => "int",
"source"   => "",
"visible"  => false,
"required" => false,
"default" => "",
"frontend" => "",
"unique"     => false,
"note"       => ""
));

我打算删除属性的方法-看起来正确吗?

My intended approach to remove the attribute - does this look correct?

$installer->startSetup();
$installer->removeAttribute('customer', 'is_school');
$installer->endSetup();

删除属性时还有其他要求吗?

Is there anything else required when removing attributes?

推荐答案

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$custAttr = 'is_school'; 

 $setup->removeAttribute('customer', $custAttr);
 $setup->endSetup();

请检查class Mage_Eav_Model_Entity_Setup extends Mage_Core_Model_Resource_Setup

public function removeAttribute($entityTypeId, $code)
{
    $mainTable  = $this->getTable('eav/attribute');
    $attribute  = $this->getAttribute($entityTypeId, $code);
    if ($attribute) {
        $this->deleteTableRow('eav/attribute', 'attribute_id', $attribute['attribute_id']);
        if (isset($this->_setupCache[$mainTable][$attribute['entity_type_id']][$attribute['attribute_code']])) {
            unset($this->_setupCache[$mainTable][$attribute['entity_type_id']][$attribute['attribute_code']]);
        }
    }
    return $this;
}

它有两个参数-第一个是entity code,第二个是attribute code.

It takes two arguments - the first is the entity code, and the second is the attribute code.

这篇关于通过安装程序脚本在Magento中删除自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆