Проблема, возникающая при создании атрибута для пользовательского расширения в версии сообщества Magento 1.9.2


Я разрабатываю расширение и поддерживаю пользовательские атрибуты для своего расширения.

Мой установщик и установочный файл работают правильно, и мой атрибут atrribute вставляется в таблицу атрибутов eav_attribute, но единственная проблема, с которой я сталкиваюсь, заключается в том, что в моем значении атрибута custom_abc_eav_attribute некоторые поля не вставляются.

Вот мой setup.php файл

class Custom_ABC_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
{
  public function getDefaultEntities()
  {
    $entities = array();
    $entities['custom_abc_user'] = array(
        'entity_model'                  => 'custom_abc/user',
        'attribute_model'               => 'custom_abc/resource_eav_attribute',
        'table'                         => 'custom_abc/user',
        'additional_attribute_table'    => 'custom_abc/eav_attribute',
        'entity_attribute_collection'   => 'custom_abc/user_attribute_collection',
        'attributes'                    => array(
                'user_name' => array(
                    'group'          => 'General',
                    'type'           => 'varchar',
                    'backend'        => '',
                    'frontend'       => '',
                    'label'          => 'Name',
                    'input'          => 'text',
                    'source'         => '',
                    'global'         => Custom_ABC_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
                    'required'       => '1',
                    'user_defined'   => false,
                    'default'        => '',
                    'unique'         => false,
                    'position'       => '10',
                    'note'           => '',
                    'visible'        => '1',
                    'wysiwyg_enabled'=> '0',
                ),
                'user_status' => array(
                    'group'          => 'General',
                    'type'           => 'int',
                    'backend'        => '',
                    'frontend'       => '',
                    'label'          => 'User Status',
                    'input'          => 'select',
                    'source'         => 'eav/entity_attribute_source_boolean',
                    'global'         => Custom_ABC_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
                    'required'       => '1',
                    'user_defined'   => true,
                    'default'        => '',
                    'unique'         => false,
                    'position'       => '20',
                    'note'           => '',
                    'visible'        => '1',
                    'wysiwyg_enabled'=> '0',
                ),
            )
     );

    return $entities;
  }
}

Вот мой установочный файл install-0.1.0.php

$this->startSetup();
$table = $this->getConnection()
->newTable($this->getTable('custom_abc/user'))
->addColumn(
    'entity_id',
    Varien_Db_Ddl_Table::TYPE_INTEGER,
    null,
    array(
        'identity'  => true,
        'unsigned'  => true,
        'nullable'  => false,
        'primary'   => true,
    ),
    'Entity ID'
)
->addColumn(
    'entity_type_id',
    Varien_Db_Ddl_Table::TYPE_SMALLINT,
    null,
    array(
        'unsigned'  => true,
        'nullable'  => false,
        'default'   => '0',
    ),
    'Entity Type ID'
)
->addColumn(
    'attribute_set_id',
    Varien_Db_Ddl_Table::TYPE_SMALLINT,
    null,
    array(
        'unsigned'  => true,
        'nullable'  => false,
        'default'   => '0',
    ),
    'Attribute Set ID'
)

->addColumn(
    'created_at',
    Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
    null, array(),
    'Creation Time'
)
->addColumn(
    'updated_at',
    Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
    null,
    array(),
    'Update Time'
)
->addIndex(
    $this->getIdxName(
        'custom_abc/user',
        array('entity_type_id')
    ),
    array('entity_type_id')
)
->addIndex(
    $this->getIdxName(
        'custom_abc/user',
        array('attribute_set_id')
    ),
    array('attribute_set_id')
)
->addForeignKey(
    $this->getFkName(
        'custom_abc/user',
        'attribute_set_id',
        'eav/attribute_set',
        'attribute_set_id'
    ),
    'attribute_set_id',
    $this->getTable('eav/attribute_set'),
    'attribute_set_id',
    Varien_Db_Ddl_Table::ACTION_CASCADE,
    Varien_Db_Ddl_Table::ACTION_CASCADE
)
->addForeignKey(
    $this->getFkName(
        'custom_abc/user',
        'entity_type_id',
        'eav/entity_type',
        'entity_type_id'
    ),
    'entity_type_id',
    $this->getTable('eav/entity_type'),
    'entity_type_id',
    Varien_Db_Ddl_Table::ACTION_CASCADE,
    Varien_Db_Ddl_Table::ACTION_CASCADE
)
->setComment('User Table');
$this->getConnection()->createTable($table);

$userEav = array();
$userEav['int'] = array(
'type'      => Varien_Db_Ddl_Table::TYPE_INTEGER,
'length'    => null,
'comment'   => 'User Datetime Attribute Backend Table'
);

$userEav['varchar'] = array(
'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
'length'    => 255,
'comment'   => 'User Varchar Attribute Backend Table'
);

$userEav['text'] = array(
'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
'length'    => '64k',
'comment'   => 'User Text Attribute Backend Table'
);

$userEav['datetime'] = array(
'type'      => Varien_Db_Ddl_Table::TYPE_DATETIME,
'length'    => null,
'comment'   => 'User Datetime Attribute Backend Table'
);

$userEav['decimal'] = array(
'type'      => Varien_Db_Ddl_Table::TYPE_DECIMAL,
'length'    => '12,4',
'comment'   => 'user Datetime Attribute Backend Table'
);

foreach ($UserEav as $type => $options) {
$table = $this->getConnection()
    ->newTable($this->getTable(array('custom_abc/user', $type)))
    ->addColumn(
        'value_id',
        Varien_Db_Ddl_Table::TYPE_INTEGER,
        null,
        array(
            'identity'  => true,
            'nullable'  => false,
            'primary'   => true,
        ),
        'Value ID'
    )
    ->addColumn(
        'entity_type_id',
        Varien_Db_Ddl_Table::TYPE_SMALLINT,
        null,
        array(
            'unsigned'  => true,
            'nullable'  => false,
            'default'   => '0',
        ),
        'Entity Type ID'
    )
    ->addColumn(
        'attribute_id',
        Varien_Db_Ddl_Table::TYPE_SMALLINT,
        null,
        array(
            'unsigned'  => true,
            'nullable'  => false,
            'default'   => '0',
        ),
        'Attribute ID'
    )
    ->addColumn(
        'store_id',
        Varien_Db_Ddl_Table::TYPE_SMALLINT,
        null,
        array(
            'unsigned'  => true,
            'nullable'  => false,
            'default'   => '0',
        ),
        'Store ID'
    )
    ->addColumn(
        'entity_id',
        Varien_Db_Ddl_Table::TYPE_INTEGER,
        null,
        array(
            'unsigned'  => true,
            'nullable'  => false,
            'default'   => '0',
        ),
        'Entity ID'
    )
    ->addColumn(
        'value',
        $options['type'],
        $options['length'], array(),
        'Value'
    )
    ->addIndex(
        $this->getIdxName(
            array('custom_abc/user', $type),
            array('entity_id', 'attribute_id', 'store_id'),
            Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
        ),
        array('entity_id', 'attribute_id', 'store_id'),
        array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
    )
    ->addIndex(
        $this->getIdxName(
            array('custom_abc/user', $type),
            array('store_id')
        ),
        array('store_id')
    )
    ->addIndex(
        $this->getIdxName(
            array('custom_abc/user', $type),
            array('entity_id')
        ),
        array('entity_id')
    )
    ->addIndex(
        $this->getIdxName(
            array('custom_abc/user', $type),
            array('attribute_id')
        ),
        array('attribute_id')
    )
    ->addForeignKey(
        $this->getFkName(
            array('custom_abc/user', $type),
            'attribute_id',
            'eav/attribute',
            'attribute_id'
        ),
        'attribute_id',
        $this->getTable('eav/attribute'),
        'attribute_id',
        Varien_Db_Ddl_Table::ACTION_CASCADE,
        Varien_Db_Ddl_Table::ACTION_CASCADE
    )
    ->addForeignKey(
        $this->getFkName(
            array('custom_abc/user', $type),
            'entity_id',
            'custom_abc/user',
            'entity_id'
        ),
        'entity_id',
        $this->getTable('custom_abc/user'),
        'entity_id',
        Varien_Db_Ddl_Table::ACTION_CASCADE,
        Varien_Db_Ddl_Table::ACTION_CASCADE
    )
    ->addForeignKey(
        $this->getFkName(
            array('custom_abc/user', $type),
            'store_id',
            'core/store',
            'store_id'
        ),
        'store_id',
        $this->getTable('core/store'),
        'store_id',
        Varien_Db_Ddl_Table::ACTION_CASCADE,
        Varien_Db_Ddl_Table::ACTION_CASCADE
    )
    ->setComment($options['comment']);
$this->getConnection()->createTable($table);
}
$table = $this->getConnection()
->newTable($this->getTable('custom_abc/eav_attribute'))
->addColumn(
    'attribute_id',
    Varien_Db_Ddl_Table::TYPE_INTEGER,
    null,
    array(
        'identity'  => true,
        'nullable'  => false,
        'primary'   => true,
    ),
    'Attribute ID'
)
->addColumn(
    'is_global',
    Varien_Db_Ddl_Table::TYPE_INTEGER,
    null,
    array(),
    'Attribute scope'
)
->addColumn(
    'position',
    Varien_Db_Ddl_Table::TYPE_INTEGER,
    null,
    array(),
    'Attribute position'
)
->addColumn(
    'is_wysiwyg_enabled',
    Varien_Db_Ddl_Table::TYPE_INTEGER,
    null,
    array(),
    'Attribute uses WYSIWYG'
)
->addColumn(
    'is_visible',
    Varien_Db_Ddl_Table::TYPE_INTEGER,
    null,
    array(),
    'Attribute is visible'
)
->setComment('ABC attribute table');
$this->getConnection()->createTable($table);

$this->installEntities();

$this->endSetup();

Он не выдает никакой ошибки, и это как это сохраняется в базе данных

Скриншот таблицы атрибутов eav_attribute enter image description here

Скриншот таблицы атрибутов custom_abc_eav_attribute enter image description here

Таким образом, основная проблема заключается в том, что позиция is_wysiwyg_enabled, is_visible вставляет нулевое значение.

Любая помощь будет заметна

Author: PRashant PUrohit, 2016-03-31

1 answers

Я получил решение, в основном я пропустил функцию _prepareValues() в setup.php

protected function _prepareValues($attr)
{
    $data = parent::_prepareValues($attr);
    $data = array_merge($data, array(
        'frontend_input_renderer'       => $this->_getValue($attr, 'input_renderer'),
        'is_global'                     => $this->_getValue(
            $attr,
            'global',
            Custom_ABC_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
        ),
        'is_visible'                    => $this->_getValue($attr, 'visible', 1),
        'is_wysiwyg_enabled'            => $this->_getValue($attr, 'wysiwyg_enabled', 0),
        'position'                      => $this->_getValue($attr, 'position', 0)
    ));
    return $data;
}
 0
Author: PRashant PUrohit, 2016-04-04 10:02:43