且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-30 09:35:04

$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.