Last active
May 12, 2020 14:51
-
-
Save syammohanmp/f3c54c84e7514d913e34 to your computer and use it in GitHub Desktop.
Create Custom Product Attribute with Source Model in Magento 1.9.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$installer = $this; | |
$installer->startSetup(); | |
$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); | |
$setup->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'vendor', array( | |
'group' => 'General', | |
'type' => 'int', | |
'backend' => '', | |
'frontend' => '', | |
'label' => 'Vendor', | |
'input' => 'select', | |
'class' => '', | |
'source' => 'mymodule/product_attribute_source_vendor', | |
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, | |
'visible' => true, | |
'required' => false, | |
'user_defined' => false, | |
'searchable' => false, | |
'filterable' => false, | |
'comparable' => false, | |
'visible_on_front' => false, | |
'unique' => false, | |
'apply_to' => 'simple,configurable,bundle,grouped', | |
'is_configurable' => false, | |
)); | |
$installer->endSetup(); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Mynamespace_Mymodule_Model_Product_Attribute_Source_Vendor extends Mage_Eav_Model_Entity_Attribute_Source_Abstract { | |
public function getAllOptions() { | |
// $options[] = array('value' => 0, 'label' => 'Select Vendor'); | |
$collection = Mage::getModel('mymodule/vendor')->getCollection(); | |
; | |
$options[] = array('value'=>0,'label'=>'Select Vendor'); | |
foreach ($collection as $vendor){ | |
$options[] = array('value' => $vendor->getId(), 'label' => $vendor->getName()); | |
} | |
return $options; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment