0

In my Magento ce 1.9.2.1 website, I have created many product custom attributes by setup-upgrade scripts like below:

<?php
$installer = new Mage_Eav_Model_Entity_Setup('core_setup');

$installer->startSetup();

$installer->addAttributeGroup('catalog_product', 'Business Directory', 'Business Directory', 1000);

$attribute_set_id = $installer->getAttributeSetId('catalog_product', 'Business Directory');

$attribute_group_id = $installer->getAttributeGroupId('catalog_product', $attribute_set_id, 'Business Directory');

$installer->addAttribute('catalog_product', 'city', array(
    'label'             => 'City',
    'type'              => 'varchar',
    'attribute_set'     => 'Business Directory',
    'input'             => 'select',
    'default'           => '',
    'backend'           => 'eav/entity_attribute_backend_array',
    'frontend'          => '',
    'source'            => '',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'user_defined'      => true,
    'searchable'        => false,
    'filterable'        => '1',
    'comparable'        => false,
    'visible_on_front'  => false,
    'visible_in_advanced_search' => false,
    'unique'            => false,
    'option'     => array (
                        0 => array("Please Select City...")
                    ),
));

$installer->updateAttribute('catalog_product', 'city', 'is_filterable', 1);

$attribute_id = $installer->getAttributeId('catalog_product', 'city');

$installer->addAttributeToSet($entityTypeId = 'catalog_product', $attribute_set_id, $attribute_group_id, $attribute_id);

$installer->addAttribute('catalog_product', 'postcode', array(
    'label'             => 'Postcode',
    'type'              => 'varchar',
    'attribute_set'     => 'Business Directory',
    'input'             => 'select',
    'default'           => '',
    'backend'           => 'eav/entity_attribute_backend_array',
    'frontend'          => '',
    'source'            => '',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'user_defined'      => true,
    'searchable'        => false,
    'filterable'        => '1',
    'comparable'        => false,
    'visible_on_front'  => false,
    'visible_in_advanced_search' => false,
    'unique'            => false,
    'option'     => array (
                        0 => array("Please Select Postcode...")
                    ),
));

$installer->updateAttribute('catalog_product', 'postcode', 'is_filterable', 1);

$attribute_id = $installer->getAttributeId('catalog_product', 'postcode');

$installer->addAttributeToSet($entityTypeId = 'catalog_product', $attribute_set_id, $attribute_group_id, $attribute_id);

$installer->endSetup();

unset($installer);

As you can see, both the attributes are select(dropdown) and both have no values initially when they are created(this is my custom key criteria, empty attributes dropdown only).

But when I populate them programmatically from frontend form, their values doesn't show up in Admin >> Catalog >> Attributes in their forms. They still show no options in admin, why ?

2 Answers 2

0

Replace

'option'     => array (
    0 => array("Please Select City...")
),

to

'option'     => array (
    'values' => array(
        0 => array("Please Select City...")
     )
),
5
  • Btw, you also should replace 'type' => 'varchar' to 'type' => 'int'
    – Igor
    Jan 6, 2016 at 17:37
  • Did that but still it doesn't add new options or updates existing ones in backend from frontend form.
    – Vicky Dev
    Jan 7, 2016 at 6:37
  • You cannot add attribute options from frontend. If "Please Select City..." didn't appear as attribute's value, then you should remove that install script and run it again
    – Igor
    Jan 7, 2016 at 10:35
  • I ran it three times already, but no luck adding from frontend.
    – Vicky Dev
    Jan 7, 2016 at 10:40
  • You are trying to add new value (which previously never existed in attribute's options), right? If so, it is wrong. You can't add new value from frontend. You can just set one of already existing values to one of products
    – Igor
    Jan 7, 2016 at 11:36
0

You have to assign product attribute in group

$setup->addAttribute('catalog_product', "price_status", array(
'group' => 'Group Name', //you can also use "General"
'type'       => 'int',
'input'      => 'select',
'label'      => 'Allow check price ?',
'visible' => 1,  
'sort_order' => 10,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 0,
'is_configurable' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'backend' => 'eav/entity_attribute_backend_array',
'option' => array (
    'values' => array(
        0 => 'No',
        1 => 'Yes',
    )
),

May be it will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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