2

hi I want to create extesnion...and for that I need to create attribute which should have following front end properties....

Use in Quick Search ----> true
Use in Advanced Search ---> true
Comparable on Front-end ---> true
Used in Product Listing --- >true 
Visible on Product View Page on Front-end --- > true
Allow HTML Tags on Frontend --->true
Use for Promo Rule Conditions --->true
Use In Search Results Layered Navigation-->true
Use In Layered Navigation --> true

this is following properties of my attributes which is needed for me but its not working with this code...

$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();   

$setup->addAttribute('catalog_product', 'test_attribute1', array(
    'type'              => 'varchar',
    'backend'           => '',
    'frontend'          => '',
    'label'             => 'test',
    'input'             => 'select',
    'class'             => '',
    'source'            => 'catalog/product_attribute_source_layout',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => true,
    'user_defined'      => true,
    'default'           => '',
    'searchable'        => true,
    'filterable'        => true,
    'comparable'        => true,
    'visible_on_front'  => true,
    'unique'            => false,
    'group'             => 'General'

));
$installer->endSetup();

How this will be possible by custom script........

3
  • Can you include what errors are you facing when you used the above code ?
    – Prateek
    Commented Oct 8, 2015 at 10:25
  • @Prateek attribute is created but all front end property is no.....
    – Deepak Rai
    Commented Oct 8, 2015 at 10:30
  • For that, you are missing some properties in your addAttribute call. Take a look at _prepareValues() method in Mage_Catalog_Model_Resource_Setup class. It lists all the allowed properties.
    – Prateek
    Commented Oct 8, 2015 at 10:42

1 Answer 1

0

I have faced this issue several times. Seems like missing one of the attribute creates the attribute but left it in an unstable state.

I suggest you modify the following script from this post to fit your needs: Upgrade script - Create new select attribute with options

$installer = $this;
$setup = new Mage_Catalog_Model_Resource_Setup('core_setup');
$installer->startSetup();   

$attr1 = array (
  'attribute_model' => NULL,
  'backend' => '',
  'type' => 'int',
  'table' => '',
  'frontend' => '',
  'input' => 'select',
  'label' => 'Brands',
  'frontend_class' => '',
  'source'=> 'brands/attribute_source_brands',
  'required' => '1',
  'user_defined' => '1',
  'default' => '',
  'unique' => '0',
  'note' => '',
  'input_renderer' => NULL,
  'global' => '1',
  'visible' => '1',
  'searchable' => '1',
  'filterable' => '1',
  'comparable' => '1',
  'visible_on_front' => '1',
  'is_html_allowed_on_front' => '1',
  'is_used_for_price_rules' => '1',
  'filterable_in_search' => '1',
  'used_in_product_listing' => '1',
  'used_for_sort_by' => '0',
  'is_configurable' => '0',
  'visible_in_advanced_search' => '1',
  'position' => '1',
  'wysiwyg_enabled' => '0',
  'used_for_promo_rules' => '1');
$setup->addAttribute('catalog_product','brands',$attr1);

$installer->endSetup();
4
  • very helpful....................
    – Deepak Rai
    Commented Oct 8, 2015 at 11:15
  • Didn't it help ? Commented Oct 8, 2015 at 11:19
  • very good....helpful without any question.........
    – Deepak Rai
    Commented Oct 8, 2015 at 11:30
  • Ok, feel free to mark your question as answered if it helped. Good day Commented Oct 8, 2015 at 11:31

Your Answer

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

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