通过安装程序脚本删除Magento中的自定义属性

Zab*_*abs 3 magento magento-1.7

我在安装程序脚本中有以下代码,现在需要通过安装程序脚本删除is_school属性,我的代码是否正确?

// 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"       => ""
));
Run Code Online (Sandbox Code Playgroud)

我想要删除属性的方法 - 这看起来是否正确?

$installer->startSetup();
$installer->removeAttribute('customer', 'is_school');
$installer->endSetup();
Run Code Online (Sandbox Code Playgroud)

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

Key*_*hah 8

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$custAttr = 'is_school'; 

 $setup->removeAttribute('customer', $custAttr);
 $setup->endSetup();
Run Code Online (Sandbox Code Playgroud)

请检查 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;
}
Run Code Online (Sandbox Code Playgroud)

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