当前位置: 首页>>代码示例>>PHP>>正文


PHP Mage_Eav_Model_Entity_Setup::addAttributeOption方法代码示例

本文整理汇总了PHP中Mage_Eav_Model_Entity_Setup::addAttributeOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Eav_Model_Entity_Setup::addAttributeOption方法的具体用法?PHP Mage_Eav_Model_Entity_Setup::addAttributeOption怎么用?PHP Mage_Eav_Model_Entity_Setup::addAttributeOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mage_Eav_Model_Entity_Setup的用法示例。


在下文中一共展示了Mage_Eav_Model_Entity_Setup::addAttributeOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createAttribute

 public function createAttribute($object)
 {
     $attributeId = Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product', $object['attribute_code']);
     if ($attributeId) {
         Mage::getModel('eav/entity_attribute')->load($attributeId)->delete();
     }
     $model = Mage::getModel('catalog/resource_eav_attribute');
     $data = array('attribute_code' => $object['attribute_code'], 'attribute_model' => $object['attribute_model'], 'backend_model' => $object['backend_model'], 'backend_type' => $object['backend_type'], 'backend_table' => $object['backend_table'], 'frontend_model' => $object['frontend_model'], 'frontend_input' => $object['frontend_input'], 'frontend_label' => $object['frontend_label'], 'frontend_class' => $object['frontend_class'], 'source_model' => $object['source_model'], 'is_required' => $object['is_required'], 'is_user_defined' => $object['is_user_defined'], 'default_value' => $object['default_value'], 'is_unique' => $object['is_unique'], 'note' => $object['note'], 'frontend_input_renderer' => $object['frontend_input_renderer'], 'is_global' => $object['is_global'], 'is_visible' => $object['is_visible'], 'is_searchable' => $object['is_searchable'], 'is_filterable' => $object['is_filterable'], 'is_comparable' => $object['is_comparable'], 'is_visible_on_front' => $object['is_visible_on_front'], 'is_html_allowed_on_front' => $object['is_html_allowed_on_front'], 'is_used_for_price_rules' => $object['is_used_for_price_rules'], 'is_filterable_in_search' => $object['is_filterable_in_search'], 'used_in_product_listing' => $object['used_in_product_listing'], 'used_for_sort_by' => $object['used_for_sort_by'], 'is_configurable' => $object['is_configurable'], 'apply_to' => $object['apply_to'], 'is_visible_in_advanced_search' => $object['is_visible_in_advanced_search'], 'position' => $object['position'], 'is_wysiwyg_enabled' => $object['is_wysiwyg_enabled'], 'is_used_for_promo_rules' => $object['is_used_for_promo_rules']);
     $model->addData($data);
     $model->setEntityTypeId($this->typeId);
     try {
         $model->save();
         echo $model->getAttributeCode() . " ..........................ok. ID: " . $model->getId() . "\n";
         $model->setSourceModel($object['source_model']);
         // TODO: check why need it, and how fix it for right set source_model
         $model->save();
     } catch (Exception $ex) {
         echo "Error: " . $ex->getMessage() . "\n";
     }
     //add attribute options
     if (empty($object['options'])) {
         echo "Model " . $model->getAttributeCode() . " saved ..........................ok. \n";
         return;
     }
     $option['attribute_id'] = $model->getId();
     foreach ($object['options'] as $opt) {
         $option['value']['option'][0] = $opt;
         //mage::d($option); //die;
         $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
         $setup->addAttributeOption($option);
     }
     echo "Model " . $model->getAttributeCode() . " saved. options added ..........................ok. \n";
 }
开发者ID:CherylMuniz,项目名称:fashion,代码行数:33,代码来源:lensattrs_a.php

示例2: catalogProductPrepareSave

 public function catalogProductPrepareSave($event)
 {
     $productData = $event->getRequest()->getPost('product');
     if ($productData) {
         foreach (Mage::helper('davidjordan_lazyloadingoption')->getAttributeCodes() as $attributeCode) {
             if (empty($productData[$attributeCode])) {
                 $post = $event->getRequest()->getPost();
                 if (!empty($post['product']["{$attributeCode}_visible_input"])) {
                     $label = $post['product']["{$attributeCode}_visible_input"];
                     $attributeModel = Mage::getModel('catalog/resource_eav_attribute')->loadByCode(4, $attributeCode);
                     $foundVal = array_reduce($attributeModel->getSource()->getAllOptions(false), function ($acc, $val) use($label) {
                         return $acc ?: ($val['label'] == $label ? $val['value'] : $acc);
                     }, "");
                     if ($foundVal) {
                         $productData[$attributeCode] = $foundVal;
                     } else {
                         $setup = new Mage_Eav_Model_Entity_Setup('core_write');
                         $setup->addAttributeOption(array('attribute_id' => $attributeModel->getId(), 'values' => array($label)));
                         $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
                         $optionValueId = $connection->lastInsertId();
                         $optionId = $connection->fetchOne("SELECT option_id FROM " . $setup->getTable('eav/attribute_option_value') . " WHERE value_id = ?", $optionValueId);
                         $productData[$attributeCode] = $optionId;
                     }
                     $event->getProduct()->setData($attributeCode, $productData[$attributeCode]);
                 } elseif ($origData = $event->getProduct()->getOrigData($attributeCode)) {
                     $event->getProduct()->setData($attributeCode, $origData);
                 }
             }
         }
     }
 }
开发者ID:suspiciousfellow,项目名称:Lazyloadingoption,代码行数:31,代码来源:Observer.php

示例3: addoptions

 /**
  * Create attribute options
  *
  * @param string $attributeId
  * @param array $attributeOptions
  * @return int
  */
 public function addoptions($attributeId, $attributeOptions)
 {
     $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
     foreach ($attributeOptions as $label) {
         $option = array();
         $option['attribute_id'] = $attributeId;
         $option['value'] = array(array(0 => $label));
         $setup->addAttributeOption($option);
     }
     return true;
 }
开发者ID:adrianoaguiar,项目名称:magja-catalog-ext,代码行数:18,代码来源:Api.php

示例4: deletarAtributo

 public function deletarAtributo($id_opcao)
 {
     $attribute_code = Mage::getStoreConfig('cores/config/codigo_cor');
     $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attribute_code);
     $options = $attribute->getSource()->getAllOptions();
     $option_id = $id_opcao;
     $options['delete'][$option_id] = true;
     $options['value'][$option_id] = true;
     $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
     $setup->addAttributeOption($options);
 }
开发者ID:xiaoguizhidao,项目名称:emporiodopara,代码行数:11,代码来源:Cores.php

示例5: array

 *
 * @category    Pan
 * @package     Pan_Updater
 * @copyright   Copyright (c) 2014 August Ash, Inc. (http://www.augustash.com)
 * @author      Josh Johnson (August Ash)
 */
/** @var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();
/**
 * -----------------------------------
 * Add default attribute options for Gift Card Type (wts_gc_type)
 * -----------------------------------
 */
// Get the eav attribute model
$attrModel = Mage::getModel('catalog/resource_eav_attribute');
// Load the particular attribute by attribute_code
$attrCode = 'wts_gc_type';
$attr = $attrModel->loadByCode('catalog_product', $attrCode);
$attrId = $attr->getAttributeId();
$storeId = 0;
// default admin store
$optionsToAdd = array('email', 'print', 'offline');
// syntax to add attribute options to existing attribute
$option = array('attribute_id' => $attrId, 'value' => array());
foreach ($optionsToAdd as $optionVal) {
    $option['value'][$optionVal] = array($optionVal);
}
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttributeOption($option);
$installer->endSetup();
开发者ID:AleksNesh,项目名称:pandora,代码行数:31,代码来源:upgrade-0.1.0-0.2.0.php

示例6: array

<?php

error_reporting(E_ALL);
require_once 'app/Mage.php';
umask(0);
echo "<pre>";
/* not Mage::run(); */
Mage::app();
$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
$row = 1;
$fields = array();
if (($handle = fopen("sizeofoneunit.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $fields[] = trim($data[1]);
    }
    fclose($handle);
}
print_r(array_unique($fields));
$color = array_values(array_unique($fields));
//print_r($color);exit;
$iProductEntityTypeId = Mage::getModel('catalog/product')->getResource()->getTypeId();
$aOption = array();
$aOption['attribute_id'] = $installer->getAttributeId($iProductEntityTypeId, 'sizeofoneunit');
for ($iCount = 0; $iCount < sizeof($color); $iCount++) {
    $aOption['value']['option' . $iCount][0] = $color[$iCount];
}
$installer->addAttributeOption($aOption);
$installer->endSetup();
开发者ID:mSupply,项目名称:runnable_test_repo,代码行数:29,代码来源:sizeofoneunit.php

示例7: createOptions

 public function createOptions($newOptions)
 {
     $cache = Mage::app()->getCache();
     $installer = new Mage_Eav_Model_Entity_Setup('core_setup');
     $attributeApi = Mage::getModel('catalog/product_attribute_api');
     $helperCatalog = Mage::helper('catalog');
     $installer->startSetup();
     $attributesList = array();
     foreach ($newOptions as $attribute_id => $options) {
         $newOption = array();
         $newOption['attribute_id'] = $attribute_id;
         $attributesList[] = $attribute_id;
         $newOption['value'] = array();
         for ($i = 0; $i < sizeof($options); $i++) {
             $label = $helperCatalog->stripTags($options[$i]);
             $cachedValue = $cache->load($attribute_id . '_' . strtolower($label));
             if ($cachedValue != 1) {
                 $newOption['value']['option' . $i][0] = $label;
                 $cache->save("1", $attribute_id . '_' . strtolower($label), array('LINNLIVE_EXTENSION_ATTRIBUTES'), 300);
             }
         }
         if (sizeof($newOption['value'])) {
             $installer->addAttributeOption($newOption);
         }
     }
     $installer->endSetup();
     Mage::app()->cleanCache(array(Mage_Core_Model_Translate::CACHE_TAG));
     $currentOptions = array();
     $attributeApi = Mage::getModel('catalog/product_attribute_api');
     foreach ($attributesList as $attribute_id) {
         $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attribute_id);
         foreach ($attribute->getSource()->getAllOptions(true, true) as $option) {
             $label = strtolower($option['label']);
             $optionId = $option['value'];
             if (!isset($currentOptions[$attribute_id][$label])) {
                 $currentOptions[$attribute_id][$label] = $optionId;
             }
             $currentOptionId = $currentOptions[$attribute_id][$label];
             if ($optionId > $currentOptionId) {
                 $attributeApi->removeOption($attribute_id, $optionId);
             }
             if ($currentOptionId > $optionId) {
                 $attributeApi->removeOption($attribute_id, $currentOptionId);
                 $currentOptions[$attribute_id][$label] = $optionId;
             }
         }
     }
     return $currentOptions;
 }
开发者ID:xiaoguizhidao,项目名称:mydigibits,代码行数:49,代码来源:Data.php

示例8: _maintainAttributeOptions

 /**
  * Assigns options to an attribute
  *
  * The attribute should be a select/multiselect
  *
  * @param $attribute
  * @param $options
  */
 private function _maintainAttributeOptions($attribute, $options)
 {
     $currentOptions = $attribute->getSource()->getAllOptions();
     $currentOptionFormat = array();
     foreach ($currentOptions as $option) {
         if ($option['label'] != '') {
             $currentOptionFormat[] = $option['label'];
         }
     }
     $optionsToAdd = array_diff($options, $currentOptionFormat);
     $optionsToRemove = array_diff($currentOptionFormat, $options);
     // Create new attributes
     foreach ($optionsToAdd as $option) {
         // Check if the option already exists
         if (!$attribute->getSource()->getOptionId($option)) {
             $attribute->setData('option', array('value' => array('option' => array($option))));
             $attribute->save();
             $this->log($this->__("Created attribute option %s for %s", $option, $attribute->getAttributeCode()));
         }
     }
     // Remove old attributes
     foreach ($optionsToRemove as $option) {
         $optionId = $attribute->getSource()->getOptionId($option);
         $toDelete['delete'][$optionId] = true;
         $toDelete['value'][$optionId] = true;
         $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
         $setup->addAttributeOption($toDelete);
         $this->log($this->__("Deleted attribute option %s for %s", $option, $attribute->getAttributeCode()));
     }
 }
开发者ID:ThomasNegeli,项目名称:magento-configurator,代码行数:38,代码来源:Attributes.php

示例9: SaveAction

 /**
  * Enregistre les modifs faite sur le manufacturer
  *
  */
 public function SaveAction()
 {
     //Charge le manufacturer
     $Manufacturer = Mage::getModel('Purchase/Manufacturer')->load($this->getRequest()->getParam('man_id'));
     //Enregistre les modifs
     $Manufacturer->setman_name($this->getRequest()->getParam('man_name'));
     $Manufacturer->setman_contact($this->getRequest()->getParam('man_contact'));
     $Manufacturer->setman_address1($this->getRequest()->getParam('man_address1'));
     $Manufacturer->setman_address2($this->getRequest()->getParam('man_address2'));
     $Manufacturer->setman_zipcode($this->getRequest()->getParam('man_zipcode'));
     $Manufacturer->setman_city($this->getRequest()->getParam('man_city'));
     $Manufacturer->setman_country($this->getRequest()->getParam('man_country'));
     $Manufacturer->setman_tel($this->getRequest()->getParam('man_tel'));
     $Manufacturer->setman_fax($this->getRequest()->getParam('man_fax'));
     $Manufacturer->setman_email($this->getRequest()->getParam('man_email'));
     $Manufacturer->setman_website($this->getRequest()->getParam('man_website'));
     $Manufacturer->setman_comments($this->getRequest()->getParam('man_comments'));
     $Manufacturer->setman_attribute_option_id($this->getRequest()->getParam('man_attribute_option_id'));
     //Si on doit créer le manufacturer magento
     if ($this->getRequest()->getParam('create_magento_manufacturer') == '1') {
         //cree l'option
         $option['attribute_id'] = mage::getModel('Purchase/Constant')->GetProductManufacturerAttributeId();
         $option['value'][0][0] = $Manufacturer->getman_name();
         $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
         $setup->addAttributeOption($option);
         //recupere son id
         $OptionId = null;
         $sql = "\n\t\t\t\tSELECT \n\t\t\t\t\t" . mage::getModel('Purchase/Constant')->getTablePrefix() . "eav_attribute_option_value.option_id id, " . mage::getModel('Purchase/Constant')->getTablePrefix() . "eav_attribute_option_value.value name\n\t\t\t\tfrom \n\t\t\t\t\t" . mage::getModel('Purchase/Constant')->getTablePrefix() . "eav_attribute_option,\n\t\t\t\t\t" . mage::getModel('Purchase/Constant')->getTablePrefix() . "eav_attribute_option_value\n\t\t\t\twhere \n\t\t\t\t\t" . mage::getModel('Purchase/Constant')->getTablePrefix() . "eav_attribute_option.attribute_id = " . mage::getModel('Purchase/Constant')->GetProductManufacturerAttributeId() . "\n\t\t\t\t\tand " . mage::getModel('Purchase/Constant')->getTablePrefix() . "eav_attribute_option.option_id = " . mage::getModel('Purchase/Constant')->getTablePrefix() . "eav_attribute_option_value.option_id \n\t\t\t\t\torder by " . mage::getModel('Purchase/Constant')->getTablePrefix() . "eav_attribute_option_value.value\n\t\t\t\t";
         //execute la requete
         $data = mage::getResourceModel('sales/order_item_collection')->getConnection()->fetchAll($sql);
         for ($i = 0; $i < count($data); $i++) {
             if ($data[$i]['name'] == $Manufacturer->getman_name()) {
                 $OptionId = $data[$i]['id'];
             }
         }
         //l'associe
         $Manufacturer->setman_attribute_option_id($OptionId);
     }
     $Manufacturer->save();
     //confirme
     Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Manufacturer Saved'));
     //Redirige vers la fiche créée
     $this->_redirect('Purchase/Manufacturers/Edit/man_id/' . $Manufacturer->getId());
 }
开发者ID:TrygveSkogsholm,项目名称:Magento-Patch,代码行数:48,代码来源:ManufacturersController.php

示例10: deletetagAction

 public function deletetagAction()
 {
     $user_id = Mage::getSingleton('customer/session')->getId();
     $userid = $user_id ? $user_id : 0;
     $tagname = Mage::app()->getRequest()->getParam('tag');
     $product_id = Mage::app()->getRequest()->getParam('productid');
     $model = Mage::getModel('catalog/product')->load($product_id);
     $attr = $model->getResource()->getAttribute("tag_custom");
     if ($attr->usesSource()) {
         $tagvalue = $attr->getSource()->getOptionId($tagname);
     }
     $attribute_code = 'tag_custom';
     $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attribute_code);
     $options = $attribute->getSource()->getAllOptions();
     $options['delete'][$tagvalue] = true;
     $options['value'][$tagvalue] = true;
     $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
     $setup->addAttributeOption($options);
     return true;
 }
开发者ID:sandajith,项目名称:mccconcierge,代码行数:20,代码来源:PopupController_backup.php

示例11: array

<?php

require_once "lib/Magento.php";
// Deleting attribute options by GUID
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$attribute = Mage::getSingleton("eav/config")->getAttribute("catalog_product", "brand");
//debug($attribute->getSource()->getAllOptions());die;
//Values have to be deleted one at a time
// Eav Setup.php
$updates = array();
foreach ($attribute->getSource()->getAllOptions() as $option) {
    if ($option['value'] != "") {
        $optionsDelete['delete'][$option['value']] = true;
        $optionsDelete['value'][$option['value']] = true;
    }
}
debug($optionsDelete);
$setup->addAttributeOption($optionsDelete);
开发者ID:ahsanmage,项目名称:vr,代码行数:18,代码来源:delete_attribute_options.php

示例12: removeOptions

 /**
  * Deletes the given option of the attribute
  *
  * @param   string  $code       Attribute code
  * @param   string|array    $reference      The reference to delete or multiple
  */
 public function removeOptions($code, $references)
 {
     $optionsDel = array();
     $options = Mage::helper('liip/attribute')->getOptions($code);
     foreach ($options as $key => $option) {
         if (in_array($option->getReference(), (array) $references)) {
             $optionsDel['delete'][$option->option_id] = true;
             $optionsDel['value'][$option->option_id] = true;
         }
     }
     $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
     $setup->addAttributeOption($optionsDel);
 }
开发者ID:liip,项目名称:liip-magento-shared,代码行数:19,代码来源:Attribute.php

示例13: createAttributeOption

 public function createAttributeOption($attributeId, $option_label)
 {
     $attribute = Mage::getModel('catalog/product')->setStoreId(0)->getResource()->getAttribute($attributeId);
     if (!$attribute->getId()) {
         $this->_fault('attribute_does_not_exist');
     }
     foreach ($attribute->getSource()->getAllOptions(true) as $option) {
         if (strcmp($option_label, $option['label']) == 0) {
             $this->_fault('attribute_option_already_exists');
         }
     }
     $option = array();
     $option['attribute_id'] = $attributeId;
     $option['value']['new_option'][0] = $option_label;
     $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
     $setup->addAttributeOption($option);
     // Since the addAtributeOption does not return a value, we will have to parse out the new option by name and return it's id.
     $attribute->save();
     $collection = Mage::getResourceModel('eav/entity_attribute_option_collection')->addFieldToFilter('attribute_id', $attributeId)->join('attribute_option_value', 'main_table.option_id=attribute_option_value.option_id')->addFieldToFilter('value', $option_label);
     $new_option = $collection->getFirstItem();
     return $new_option->getId();
 }
开发者ID:macosxvn,项目名称:techheroes,代码行数:22,代码来源:Api.php

示例14: loadAttributes

 public function loadAttributes()
 {
     $optionText = file_get_contents('../var/import/attributes.txt');
     $attrArray = unserialize($optionText);
     //mage::d($attrArray);
     //die;
     //$model = Mage::getModel('catalog/resource_eav_attribute')->load(143)->delete(); die;
     foreach ($attrArray as $attr) {
         try {
             $attr->getSource()->getAllOptions(false);
         } catch (Exception $e) {
             echo "yes";
             die;
             continue;
         }
         $model = Mage::getModel('catalog/resource_eav_attribute');
         //mage::ms($model); die;
         // if attribute_code already exists, renew it only.
         if ($attributeId = Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product', $attr->getAttributeCode())) {
             $model = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
             #$model = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId)->delete();
             //delete old attribute options. TODO: apply API for it.
             $query = "DELETE ao FROM eav_attribute_option ao JOIN eav_attribute ea ON ao.attribute_id = ea.attribute_id AND ea.attribute_id ={$attributeId}";
             $this->query($query);
         }
         $data = array('attribute_code' => $attr->getAttributeCode(), 'attribute_model' => $attr->getData('attribute_model'), 'backend_model' => $attr->getData('backend_model'), 'backend_type' => $attr->getData('backend_type'), 'backend_table' => $attr->getData('backend_table'), 'frontend_model' => $attr->getData('frontend_model'), 'frontend_input' => $attr->getData('frontend_input'), 'frontend_label' => $attr->getData('frontend_label'), 'frontend_class' => $attr->getData('frontend_class'), 'source_model' => $attr->getData('source_model'), 'is_required' => $attr->getData('is_required'), 'is_user_defined' => $attr->getData('is_user_defined'), 'default_value' => $attr->getData('default_value'), 'is_unique' => $attr->getData('is_unique'), 'note' => $attr->getData('note'), 'frontend_input_renderer' => $attr->getData('frontend_input_renderer'), 'is_global' => $attr->getData('is_global'), 'is_visible' => $attr->getData('is_visible'), 'is_searchable' => $attr->getData('is_searchable'), 'is_filterable' => $attr->getData('is_filterable'), 'is_comparable' => $attr->getData('is_comparable'), 'is_visible_on_front' => $attr->getData('is_visible_on_front'), 'is_html_allowed_on_front' => $attr->getData('is_html_allowed_on_front'), 'is_used_for_price_rules' => $attr->getData('is_used_for_price_rules'), 'is_filterable_in_search' => $attr->getData('is_filterable_in_search'), 'used_in_product_listing' => $attr->getData('used_in_product_listing'), 'used_for_sort_by' => $attr->getData('used_for_sort_by'), 'is_configurable' => $attr->getData('is_configurable'), 'apply_to' => $attr->getData('apply_to'), 'is_visible_in_advanced_search' => $attr->getData('is_visible_in_advanced_search'), 'position' => $attr->getData('position'), 'is_wysiwyg_enabled' => $attr->getData('is_wysiwyg_enabled'), 'is_used_for_promo_rules' => $attr->getData('is_used_for_promo_rules'));
         if (!$attributeId) {
             $model->addData($data);
             $model->setEntityTypeId(Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId());
         } else {
             $model->setDataChanges($data);
         }
         // set groups and sets
         $connection = Mage::getModel('core/resource')->getConnection('core_read');
         $select = $connection->select()->from(array('oasm' => 'oberig_attribute_set_mapping'), array('attribute_group_name', 'sort_order'))->joinInner(array('eas' => 'eav_attribute_set'), 'oasm.attribute_set_name = eas.attribute_set_name  AND entity_type_id = 4', 'attribute_set_id')->joinInner(array('eag' => 'eav_attribute_group'), 'eag.attribute_set_id = eas.attribute_set_id AND eag.attribute_group_name = oasm.attribute_group_name', 'attribute_group_id')->where('attribute_code=?', $attr->getAttributeCode());
         echo $select->__toString() . "\n";
         $result = $connection->query($select)->fetchAll();
         echo "-------------------------------------------------\n";
         mage::D($result);
         echo "-------------------------------------------------\n";
         foreach ($result as $res) {
             if ($attributeId) {
                 $model = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
             }
             $model->setAttributeSetId($res['attribute_set_id']);
             $model->setAttributeGroupId($res['attribute_group_id']);
             $model->setSortOrder($res['sort_order']);
             if ($attributeId) {
                 try {
                     $model->save();
                 } catch (Exception $ex) {
                     echo "Error: " . $ex->getMessage() . "\n";
                 }
             }
         }
         //end set groups and sets
         //if( $attr->getAttributeCode() == 'lenstint' )
         //{
         try {
             if (!$attributeId) {
                 $model->save();
                 echo $attr->getAttributeCode() . " ..........................ok. ID: " . $model->getId() . "\n";
             }
             $option['attribute_id'] = $model->getId();
             $all_opts = $attr->getSource()->getAllOptions(false);
         } catch (Exception $ex) {
             echo "Error: " . $ex->getMessage() . "\n";
         }
         //add attribute options
         foreach ($all_opts as $opt) {
             $option['value']['option'][0] = $opt['label'];
             mage::d($option);
             //die;
             $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
             $setup->addAttributeOption($option);
         }
         echo "Model " . $model->getAttributeCode() . " saved. options added ..........................ok. \n";
         //$model = Mage::getModel('catalog/resource_eav_attribute')->load($model->getId())->delete(); //die;
         //}
     }
     // set tax class options TODO: API
     $this->query("insert ignore into tax_class select * from {$this->oldDB}.tax_class");
     //die;
 }
开发者ID:CherylMuniz,项目名称:fashion,代码行数:84,代码来源:attributes.php

示例15: _beforeSave

 /**
  * When saving the product, assign a subscription plan attribute option.
  * This is used with configurable products.
  */
 protected function _beforeSave()
 {
     $allowProductTypes = array();
     foreach (Mage::helper('catalog/product_configuration')->getConfigurableAllowedTypes() as $type) {
         $allowProductTypes[] = $type->getName();
     }
     if (in_array($this->getTypeId(), $allowProductTypes)) {
         $helperAttribute = Mage::getModel('catalog/resource_eav_attribute')->loadByCode('catalog_product', 'subscription_plan');
         if (!$this->isSubscription()) {
             $optionValue = 'None';
         } else {
             $optionValue = $this->getPlanDescription();
         }
         if (!($optionId = $this->getAttributeOptionId($helperAttribute, $optionValue))) {
             $option['attribute_id'] = $helperAttribute->getAttributeId();
             $option['value']['option_name'][0] = $optionValue;
             $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
             $setup->addAttributeOption($option);
             $optionId = $this->getAttributeOptionId($helperAttribute, $optionValue);
         }
         $this->setSubscriptionPlan($optionId);
     }
     parent::_beforeSave();
 }
开发者ID:xiaoguizhidao,项目名称:extensiongsd,代码行数:28,代码来源:Product.php


注:本文中的Mage_Eav_Model_Entity_Setup::addAttributeOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。