コード例 #1
0
ファイル: Builder.php プロジェクト: Vitafy/M2E
 private function saveAttribute()
 {
     if ($this->attributeObj->getId()) {
         return array('result' => true, 'obj' => $this->attributeObj);
     }
     if (!$this->validate()) {
         return array('result' => false, 'error' => 'Attribute builder. Validation failed.');
     }
     $this->attributeObj = Mage::getModel('catalog/resource_eav_attribute');
     $data = $this->params;
     $data['attribute_code'] = $this->code;
     $data['frontend_label'] = array(Mage_Core_Model_App::ADMIN_STORE_ID => $this->primaryLabel);
     $data['frontend_input'] = $this->inputType;
     $data['entity_type_id'] = $this->entityTypeId;
     $data['is_user_defined'] = 1;
     $data['source_model'] = Mage::helper('catalog/product')->getAttributeSourceModelByInputType($this->inputType);
     $data['backend_model'] = Mage::helper('catalog/product')->getAttributeBackendModelByInputType($this->inputType);
     $data['backend_type'] = $this->attributeObj->getBackendTypeByInput($this->inputType);
     !isset($data['is_global']) && ($data['is_global'] = self::SCOPE_STORE);
     !isset($data['is_configurable']) && ($data['is_configurable'] = 0);
     !isset($data['is_filterable']) && ($data['is_filterable'] = 0);
     !isset($data['is_filterable_in_search']) && ($data['is_filterable_in_search'] = 0);
     !isset($data['apply_to']) && ($data['apply_to'] = array());
     $this->prepareOptions($data);
     $this->prepareDefault($data);
     $this->attributeObj->addData($data);
     try {
         $this->attributeObj->save();
     } catch (Exception $e) {
         return array('result' => false, 'error' => $e->getMessage());
     }
     return array('result' => true, 'obj' => $this->attributeObj);
 }
コード例 #2
0
ファイル: Builder.php プロジェクト: aligent/M2E
 private function saveAttribute()
 {
     if ($this->attributeObj->getId()) {
         return array('result' => true, 'obj' => $this->attributeObj, 'code' => $this->attributeObj->getAttributeCode());
     }
     if (!$this->validate()) {
         return array('result' => false, 'error' => 'Attribute builder. Validation failed.');
     }
     $data = $this->params;
     $data['attribute_code'] = $this->code;
     $data['frontend_label'] = array(Mage_Core_Model_App::ADMIN_STORE_ID => $this->primaryLabel);
     $data['frontend_input'] = $this->inputType;
     $data['source_model'] = Mage::helper('catalog/product')->getAttributeSourceModelByInputType($this->inputType);
     $data['backend_model'] = Mage::helper('catalog/product')->getAttributeBackendModelByInputType($this->inputType);
     !isset($data['is_global']) && ($data['is_global'] = self::SCOPE_STORE);
     !isset($data['is_configurable']) && ($data['is_configurable'] = 0);
     !isset($data['is_filterable']) && ($data['is_filterable'] = 0);
     !isset($data['is_filterable_in_search']) && ($data['is_filterable_in_search'] = 0);
     $this->attributeObj = Mage::getModel('catalog/resource_eav_attribute');
     if (is_null($this->attributeObj->getIsUserDefined()) || $this->attributeObj->getIsUserDefined() != 0) {
         $data['backend_type'] = $this->attributeObj->getBackendTypeByInput($this->inputType);
     }
     // default value
     if (empty($data['default_value'])) {
         unset($data['default_value']);
     }
     // ---------------------------------------
     !isset($data['apply_to']) && ($data['apply_to'] = array());
     // prepare options
     foreach ($this->options as $optionValue) {
         $code = 'option_' . substr(sha1($optionValue), 0, 6);
         $data['option']['value'][$code] = array(Mage_Core_Model_App::ADMIN_STORE_ID => $optionValue);
     }
     // ---------------------------------------
     $this->attributeObj->addData($data);
     $this->attributeObj->setEntityTypeId($this->entityTypeId);
     $this->attributeObj->setIsUserDefined(1);
     try {
         $this->attributeObj->save();
     } catch (Exception $e) {
         return array('result' => false, 'error' => $e->getMessage());
     }
     return array('result' => true, 'obj' => $this->attributeObj, 'code' => $this->attributeObj->getAttributeCode());
 }
コード例 #3
0
<?php

$installer = $this;
/* @var $installer Mage_Sales_Model_Mysql4_Setup */
$installer->startSetup();
$resource = Mage::getResourceModel('sales/order_collection');
if (!method_exists($resource, 'getEntity')) {
    $table = $this->getTable('sales_flat_order');
    $query = 'ALTER TABLE `' . $table . '` ADD COLUMN `onestepcheckout_customercomment` TEXT CHARACTER SET utf8 DEFAULT NULL';
    $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
    $connection->query($query);
} else {
    // Get ID of the entity model 'sales/order'.
    $sql = 'SELECT entity_type_id FROM ' . $this->getTable('eav_entity_type') . ' WHERE entity_type_code="order"';
    $row = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchRow($sql);
    // Create EAV-attribute for the order comment.
    $c = array('entity_type_id' => $row['entity_type_id'], 'attribute_code' => 'onestepcheckout_customercomment', 'backend_type' => 'text', 'frontend_input' => 'textarea', 'is_global' => '1', 'is_visible' => '1', 'is_required' => '0', 'is_user_defined' => '0', 'frontend_label' => 'Customer Comment');
    $attribute = new Mage_Eav_Model_Entity_Attribute();
    $attribute->loadByCode($c['entity_type_id'], $c['attribute_code'])->setStoreId(0)->addData($c);
    $attribute->save();
}
$installer->endSetup();
コード例 #4
0
ファイル: Product.php プロジェクト: vberzsin/shop
 /**
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param string $optionLabel
  */
 protected function _createAttributeOption($attribute, $optionLabel)
 {
     $option = array('value' => array(array('0' => $optionLabel)), 'order' => array(0), 'delete' => array(''));
     $attribute->setOption($option);
     $attribute->save();
     $this->_attributeOptions[$attribute->getAttributeCode()][] = $optionLabel;
     $this->_initTypeModels();
 }