Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $attributeModel = Mage::getModel('eav/entity_attribute')->getCollection()->addFieldToFilter('frontend_label', 'Color');
- $attributeCode = $attributeModel->getData('attribute_code') [0]['attribute_code'];
- $attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', $attributeCode);
- $data = [
- 'option' => [
- 'value' => [
- 0 => [
- 0 => 'Red', // Admin
- 1 => 'default', // Default store view
- // position ???
- // is_default ???
- ],
- 1 => [ 0 => 'Blue', 1 => 'default', 2 => 0 ],
- 2 => [ 0 => 'Green', 1 => 'default', 2 => 0 ],
- ],
- ],
- ];
- $attributeModel->addData($data)->save();
- print_r($attributeModel->getData());
- die;
- <global>
- ....
- ....
- <resources>
- <yourmodule_yournamespace_setup>
- <setup>
- <module>YourModule_YourNamespace</module>
- <class>YourModule_YourNamespace_Model_Resource_Setup</class>
- </setup>
- </yourmodule_yournamespace_setup>
- </resources>
- </global>
- class YourModule_YourNamespace_Model_Resource_Setup extends Mage_Catalog_Model_Resource_Setup
- {
- /**
- * Create Product attributes for select list
- *
- * @param string $attribute_code
- * @param array $optionsArray
- */
- public function addAttributeOptions($attribute_code, array $optionsArray)
- {
- $tableOptions = $this->getTable('eav_attribute_option');
- $tableOptionValues = $this->getTable('eav_attribute_option_value');
- $attributeId = (int) $this->getAttribute('catalog_product', $attribute_code, 'attribute_id');
- foreach ($optionsArray as $sortOrder => $label) {
- // add option
- $data = array(
- 'attribute_id' => $attributeId,
- 'sort_order' => $sortOrder,
- );
- $this->getConnection()->insert($tableOptions, $data);
- // add option label
- $optionId = (int) $this->getConnection()->lastInsertId($tableOptions, 'option_id');
- $data = array(
- 'option_id' => $optionId,
- 'store_id' => 0,
- 'value' => $label,
- );
- $this->getConnection()->insert($tableOptionValues, $data);
- }
- }
- }
- $data = array('value1','value2','value3');
- $installer->addAttributeOptions('<attribute_code>', $data);
- <?php
- error_reporting(E_ALL);
- require_once 'app/Mage.php';
- umask(0);
- echo "<pre>";
- /* not Mage::run(); */
- Mage::app();
- try
- {
- $installer = new Mage_Eav_Model_Entity_Setup('core_setup');
- $installer->startSetup();
- $color = array('Red','Green','Blue','Pink','Yellow','orange');
- $iProductEntityTypeId = Mage::getModel('catalog/product')->getResource()->getTypeId();
- $aOption = array();
- $aOption['attribute_id'] = $installer->getAttributeId($iProductEntityTypeId, 'color');
- for($iCount=0;$iCount<sizeof($color);$iCount++){
- $aOption['value']['option'.$iCount][0] = $color[$iCount];
- }
- $installer->addAttributeOption($aOption);
- $installer->endSetup();
- ?>
- function ambassUpdate($ambassName, $attr_id){
- $installer = new Mage_Eav_Model_Entity_Setup('core_setup');
- $installer->startSetup();
- $aOption = array();
- $aOption['attribute_id'] = $attr_id;
- for($iCount=1;$iCount<sizeof($ambassName);$iCount++){
- //for($iCount=1;$iCount<4;$iCount++){
- $aOption['value']['option'.$iCount][0] = $ambassName[$iCount];
- $aOption['order']['option'.$iCount] = $iCount + 10;
- }
- $installer->addAttributeOption($aOption);
- $installer->endSetup();
- return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement