2

I am maintaining custom attributes for my extension.

My installer and setup files are working properly and my atrributes are getting inserted in eav_attribute table but the only problem I am facing is that in my custom_abc_eav_attribute table, while the values of some fields are not getting inserted.

here is my setup.php file

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;
  }
}

Here is my installer file 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();

It is not throwing any error and this is how it is saving in database

Screenshot of eav_attribute table enter image description here

Screenshot of custom_abc_eav_attribute table enter image description here

so the main issue is that position, is_wysiwyg_enabled, is_visible is inserting null value.

Any help will be appreciable

0
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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.