1

I want to create attribute through script of drop down type. in Drop down i want to display Customer Name of particular group. and also want to create customer group with script how its possible?

Thank you so much..

2
  • Is only one customer per group? Approach: Add attribute with source model, source model get all customer groups and customers and returns them. Commented Apr 9, 2014 at 7:18
  • @FabianBlechschmidt no i wanted to create one customer group. and in product one attribute which is drop-down type which is display Customer Name of above created group type. i got solution as below. By The Way Thank you so much.
    – MageDev
    Commented Apr 9, 2014 at 11:26

1 Answer 1

2

Here First I post How to Create Customer group througt setup-script or programmatically?

$installer = $this;
$installer->startSetup();

$customer_group=Mage::getModel('customer/group');
$customer_group->setCode("Label Of customer Group");
$customer_group->setTaxClassId(3);
$customer_group->save();

$installer->endSetup();

Now, we will see how to create product attribute through setup-script / programmatically?

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

$setup->addAttribute('catalog_product', 'attribute_code', array(
             'group'             => 'ATTIBUTE GROUP NAME', // it will create new tab if you want to create new tab like general,inventory etc... etc...
             'label'             => 'ATTIBUTE LABEL NAME',
             'type'              => 'varchar',
             'input'             => 'select',
             'backend'           => '',
             'frontend'          => '', 
             'source'            => 'MODULENAME/source_option', //Path of Model file Where you will create option
             'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
             'visible'           => true,
             'required'          => true,
             'user_defined'      => true,
             'searchable'        => false,
             'filterable'        => false,
             'comparable'        => false,
             'visible_on_front'  => false,
             'visible_in_advanced_search' => false,
             'unique'            => false,
             'apply_to'          => 'simple,grouped,configurable,virtual,bundle,downloadable'
));

$installer->endSetup();

Now Model File which returns option value for drop-down.

class Name_Modulename_Model_Source_Option extends Mage_Eav_Model_Entity_Attribute_Source_Abstract{

    public function getAllOptions()
    {
        $customerCollection = Mage::getModel('customer/customer')->getCollection()->addAttributeToFilter('group_id', 5);
        // Group_id 5 is cretaed new group for custoerm
        $options = array();
        foreach ($customerCollection as $customer){
            $customer = Mage::getModel('customer/customer')->load($customer->getId());

            $options[] = $customer->getName();
        }
        return $options;
    }
}

If you want to create Static(Fixed option value) for drop-down type product attribute.

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

$setup->addAttribute('catalog_product', 'attribute_code', array(
             'group'             => ''ATTIBUTE GROUP NAME', // it will create new tab if you want to create new tab like general,inventory etc... etc...
             'label'             => 'ATTIBUTE LABEL NAME',
             'type'              => 'varchar',
             'input'             => 'select',
             'backend'           => '',
             'frontend'          => '', 
             'source'            => '',
             'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
             'visible'           => true,
             'required'          => true,
             'user_defined'      => true,
             'searchable'        => false,
             'filterable'        => false,
             'comparable'        => false,
             'option'            => array (
                                            'value' => array('value1' => array('Label1'),
                                                             'value2' => array('Lbel2'),
                                                            )
                                          ),
             'visible_on_front'  => false,
             'visible_in_advanced_search' => false,
             'unique'            => false,
             'apply_to'          => 'simple,grouped,configurable,virtual,bundle,downloadable'

));
1
  • I have created a module to create customercustomer in manufacturer customer group now I want to add this manufacturer customer group as a product attribute to product so that when I create a product from admin there should be an dropdown list from the manufacturer customer group to add the manufacturer of the product. Commented Sep 7, 2016 at 12:13

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.