Beispiel #1
0
 public function testSetDeleteConfigData()
 {
     $select = $this->_model->getConnection()->select()->from($this->_model->getTable('core_config_data'), 'value')->where('path=?', 'my/test/path');
     $this->_model->setConfigData('my/test/path', 'test_value');
     $this->assertEquals('test_value', $this->_model->getConnection()->fetchOne($select));
     $this->_model->deleteConfigData('my/test/path', 'test');
     $this->assertNotEmpty($this->_model->getConnection()->fetchRow($select));
     $this->_model->deleteConfigData('my/test/path');
     $this->assertEmpty($this->_model->getConnection()->fetchRow($select));
 }
Beispiel #2
0
 protected function setUp()
 {
     $installer = new Mage_Core_Model_Resource_Setup(Mage_Core_Model_Resource_Setup::DEFAULT_SETUP_CONNECTION);
     $this->_connection = $installer->getConnection();
     $this->_tableName = $installer->getTable('table_two_column_idx');
     $this->_oneColumnIdxName = $installer->getIdxName($this->_tableName, array('column1'));
     $this->_twoColumnIdxName = $installer->getIdxName($this->_tableName, array('column1', 'column2'));
     $table = $this->_connection->newTable($this->_tableName)->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), 'Id')->addColumn('column1', Varien_Db_Ddl_Table::TYPE_INTEGER)->addColumn('column2', Varien_Db_Ddl_Table::TYPE_INTEGER)->addIndex($this->_oneColumnIdxName, array('column1'))->addIndex($this->_twoColumnIdxName, array('column1', 'column2'));
     $this->_connection->createTable($table);
 }
Beispiel #3
0
 /**
  * Replace unique key
  * 
  * @param Mage_Core_Model_Resource_Setup $setup
  * @param string $tableName
  * @param string $keyName
  * @param array $keyAttributes
  * @return Innoexts_InnoCore_Helper_Database
  */
 public function replaceUniqueKey($setup, $tableName, $keyName, $keyAttributes)
 {
     $connection = $setup->getConnection();
     $versionHelper = $this->getVersionHelper();
     $table = $setup->getTable($tableName);
     if ($versionHelper->isGe1600()) {
         $indexTypeUnique = Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE;
         $indexes = $connection->getIndexList($table);
         foreach ($indexes as $index) {
             if ($index['INDEX_TYPE'] == $indexTypeUnique) {
                 $connection->dropIndex($table, $index['KEY_NAME']);
             }
         }
         $keyName = $setup->getIdxName($tableName, $keyAttributes, $indexTypeUnique);
         $connection->addIndex($table, $keyName, $keyAttributes, $indexTypeUnique);
     } else {
         $connection->addKey($table, $keyName, $keyAttributes, 'unique');
     }
     return $this;
 }
 public function saveAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
         $entityTypeId = $setup->getEntityTypeId('customer');
         $attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
         $attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
         $attributeObject = Mage::getModel('customer/attribute');
         $attributeId = $this->getRequest()->getParam('id');
         $helper = Mage::helper('customerattribute');
         $attributeType = $attributeObject->load($attributeId)->getFrontendInput();
         if ($attributeId != null) {
             $data['frontend_input'] = $attributeType;
         }
         $data['validate_rules'] = $helper->getAttributeValidateRules1($data['frontend_input'], $data);
         if ($data['is_custom'] == 1 || $attributeId == 0) {
             if ($data['status'] == 1) {
                 if (in_array(1, $data['display_on_frontend'])) {
                     $data['used_in_forms'][] = 'customer_account_create';
                 }
                 if (in_array(2, $data['display_on_frontend'])) {
                     $data['used_in_forms'][] = 'customer_account_edit';
                 }
                 if ((in_array(3, $data['display_on_frontend']) || in_array(4, $data['display_on_frontend'])) && $attributeType != 'file' && $attributeType != 'image') {
                     $data['used_in_forms'][] = 'checkout_register';
                 }
                 if (in_array(1, $data['display_on_backend'])) {
                     $data['used_in_forms'][] = 'customer_Grid';
                 }
                 if (in_array(2, $data['display_on_backend'])) {
                     $data['used_in_forms'][] = 'order_grid';
                 }
                 if (in_array(3, $data['display_on_backend']) && $attributeType != 'file' && $attributeType != 'image') {
                     $data['used_in_forms'][] = 'adminhtml_checkout';
                 }
                 $data['used_in_forms'][] = 'tabCustomerattribute';
             } else {
                 $data['used_in_forms'][] = array();
             }
         }
         try {
             $data1 = array('status' => $data['status'], 'show_on_create_account' => (int) in_array(1, $data['display_on_frontend']), 'show_on_account_edit' => (int) in_array(2, $data['display_on_frontend']), 'show_on_checkout_register_customer' => (int) in_array(3, $data['display_on_frontend']), 'show_on_checkout_register_guest' => (int) in_array(4, $data['display_on_frontend']), 'show_on_grid_customer' => (int) in_array(1, $data['display_on_backend']), 'show_on_grid_order' => (int) in_array(2, $data['display_on_backend']), 'show_on_admin_checkout' => (int) in_array(3, $data['display_on_backend']), 'customer_group' => implode(", ", $data['customer_group']), 'store_id' => implode(", ", $data['store_view']));
             if ($attributeType == 'file' || $attributeType == 'image') {
                 $data1['show_on_checkout_register_customer'] = 0;
                 $data1['show_on_checkout_register_guest'] = 0;
                 $data1['show_on_admin_checkout'] = 0;
             }
             $model = Mage::getModel('customerattribute/customerattribute');
             if ($attributeId) {
                 $models = Mage::getModel('customerattribute/customerattribute')->getCollection()->addFieldToFilter('attribute_id', $attributeId)->getFirstItem();
                 $data1['attribute_id'] = $attributeId;
                 $attributeObject->load($attributeId)->addData($data);
                 $attributeObject->setId($attributeId)->save();
                 $model->load($models->getId())->setData($data1);
                 $model->setId($models->getId())->save();
                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('customerattribute')->__('The customer attribute has been saved.'));
             } else {
                 $data['attribute_code'] = str_replace(' ', '', $data['attribute_code']);
                 $data['attribute_code'] = strtolower($data['attribute_code']);
                 $defaultValueField = $helper->getAttributeDefaultValueByInput($data['frontend_input']);
                 if ($defaultValueField) {
                     $scopeKeyPrefix = $this->getRequest()->getParam('website') ? 'scope_' : '';
                     $data[$scopeKeyPrefix . 'default_value'] = $helper->stripTags($this->getRequest()->getParam($scopeKeyPrefix . $defaultValueField));
                 }
                 $data['entity_type_id'] = $entityTypeId;
                 $data['attribute_group_id'] = $attributeGroupId;
                 $data['attribute_set_id'] = $attributeSetId;
                 $data['backend_type'] = $helper->getAttributeBackendTypeByInputType($data['frontend_input']);
                 $data['backend_model'] = $helper->getAttributeBackendModelByInputType($data['frontend_input']);
                 $data['source_model'] = $helper->getAttributeSourceModelByInputType($data['frontend_input']);
                 $data['is_system'] = 0;
                 $data['is_user_defined'] = 1;
                 if ($data['frontend_input'] == 'date') {
                     $data['input_filter'] = 'date';
                 }
                 $attributeObject->setData($data);
                 $attributeId = $attributeObject->save()->getId();
                 $data1['is_custom'] = 1;
                 $data1['attribute_id'] = $attributeId;
                 $model->setData($data1)->save();
                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('customerattribute')->__('The customer customer attribute has been saved.'));
                 // Addcolumn to orderattribute table create by Hoatq
                 $table = new Mage_Core_Model_Resource_Setup();
                 $table->getConnection()->addColumn($table->getTable('orderattribute'), 'customer_' . $data['attribute_code'], 'varchar(255)');
             }
         } catch (Exception $e) {
             if (!$attributeId) {
                 $attributeCode = $data['attribute_code'];
                 $attributeObject = $this->_initAttribute()->loadByCode($this->_getEntityType()->getId(), $attributeCode);
                 if ($attributeObject->getId()) {
                     $this->_getSession()->addError(Mage::helper('customerattribute')->__('Attribute with the same code already exists'));
                 }
             } else {
                 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('customerattribute')->__('Unable to find item to save'));
             }
         }
         if ($this->getRequest()->getParam('back', false)) {
             $this->_redirect('*/*/edit', array('id' => $attributeId, '_current' => true));
             return;
         } else {
             $this->_redirect('*/*/');
             return;
         }
     } else {
         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('customerattribute')->__('Unable to find item to save'));
     }
     $this->_redirect('*/*/');
     return;
 }
Beispiel #5
0
 /**
  * Set order number prefix
  *
  * @param Mage_Core_Model_Resource_Setup $setupModel
  * @param string $orderIncrementPrefix
  */
 protected function _setOrderIncrementPrefix(Mage_Core_Model_Resource_Setup $setupModel, $orderIncrementPrefix)
 {
     $select = $setupModel->getConnection()->select()->from($setupModel->getTable('eav_entity_type'), 'entity_type_id')->where('entity_type_code=?', 'order');
     $data = array('entity_type_id' => $setupModel->getConnection()->fetchOne($select), 'store_id' => '1', 'increment_prefix' => $orderIncrementPrefix);
     $setupModel->getConnection()->insert($setupModel->getTable('eav_entity_store'), $data);
 }
Beispiel #6
0
<?php

$installer = new Mage_Core_Model_Resource_Setup();
$installer->getConnection()->addColumn($installer->getTable('newsletter_subscriber'), 'subscriber_firstname', 'varchar(50) AFTER subscriber_confirm_code');
$installer->getConnection()->addColumn($installer->getTable('newsletter_subscriber'), 'subscriber_lastname', 'varchar(50) AFTER subscriber_firstname');
    $_productsCollection->delete();
} catch (Exception $_e) {
    Mage::logException($_e);
}
/**************/

/** Drop tables */
$_tablesArray = array(
    'payperrentals' => array('excludeddates', 'mailinglog', 'ordertodates', 'rentalqueue', 'reservationorders', 'reservationprices', 'reservationquotes', 'sendreturn', 'serialnumbers', 'serialnumbersdetails'),
    'rshipping' => array('products', 'rshipping')
);
$_setupModel = new Mage_Core_Model_Resource_Setup('core_setup');
foreach ($_tablesArray as $_modelPrefix => $_tableArray) {
    foreach ($_tableArray as $_table) {
        try {
            $_setupModel->getConnection()->dropTable($_setupModel->getTable($_modelPrefix . '/' . $_table));
        } catch (Exception $_e) {
            Mage::logException($_e);
        }
    }
}
/**************/
/** Drop added columns */
$_columnsArray = array(
    'sales/quote' => array(
        'start_datetime',
        'end_datetime',
        'return_datetime',
        'send_datetime',
        'estimate_send',
        'estimate_return',