public function dbCheck() { $dbOk = true; $localError = false; $this->messages[] = "Checking database"; $installer = new Mage_Sales_Model_Mysql4_Setup('sales_setup'); $installer->startSetup(); if (isset($_GET['fix'])) { $fix = $_GET['fix'] == 'true'; } else { $fix = false; } foreach ($this->_getDbFields() as $field) { switch ($field[0]) { case 'eav': try { $sql = "SELECT `attribute_id` FROM `{$installer->getTable('eav_attribute')}` WHERE `attribute_code` ='{$field['2']}'"; $test = $installer->getConnection('core_read')->fetchRow($sql); if (!isset($test['attribute_id']) && !$test['attribute_id'] > 0) { throw new Exception('eav attribute ' . $field[2] . ' is not installed'); } $this->messages[] = "[OK] eav attribute " . $field[2] . " with id " . $test['attribute_id'] . ""; } catch (Exception $e) { if ($fix) { $this->messages[] = "Attempting fix for eav attribute " . $field[2] . ""; try { $installer->addAttribute($field[1], $field[2], $field[3]); $this->messages[] = "[FIX OK] eav attribute " . $field[2] . " fixed"; } catch (Exception $e) { $this->messages[] = "[FAILED] fixing eav attribute " . $field[2] . ""; $dbOk = false; $this->messages[] = $e->getMessage(); $localError = true; } } else { $this->messages[] = "[FAILED] eav attribute " . $field[2] . ""; Mage::getSingleton('core/session')->addWarning('[FAILED] eav attribute ' . $field[2]); $dbOk = false; $this->messages[] = "[ERR] " . $e->getMessage(); $localError = true; } } break; case 'sql-column': try { $test = $installer->run("SELECT `{$field['2']}` FROM `{$installer->getTable($field[1])}` LIMIT 0"); $this->messages[] = "[OK] column " . $field[2] . ""; } catch (Exception $e) { if ($fix) { $this->messages[] = "Attempting fix for column " . $field[2] . ""; try { $test = $installer->run("ALTER TABLE `{$installer->getTable($field[1])}` ADD COLUMN `{$field['2']}` {$field['3']}"); $this->messages[] = "[FIX OK] column " . $field[2] . " fixed"; } catch (Exception $e) { $this->messages[] = "[FAILED] fixing column " . $field[2] . ""; $dbOk = false; $this->messages[] = $e->getMessage(); $localError = true; } } else { $this->messages[] = "[FAILED] column " . $field[2] . ""; $dbOk = false; $this->messages[] = "[ERR] " . $e->getMessage(); $localError = true; } } break; } } $installer->endSetup(); if (empty($localError)) { return true; } else { if ($dbOk == false) { $this->messages[] = "<p>The selftest has found some problems with your database install.\n You can attempt to fix this by appending ?fix=true to the address or clicking this <a href=\"" . htmlentities($_SERVER['PHP_SELF']) . "?fix=true\">link</a>.</p><p style=\"color:red;\"><em>A DATABASE BACKUP IS strongly RECOMMENDED BEFORE ATTEMPTING THIS!</em></p>"; } return false; } }
<?php $installer = $this; $installer->startSetup(); $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); $installer->run("\r\n\t\tDROP TABLE IF EXISTS {$this->getTable('delivery_note')};\r\n\r\n\t\tCREATE TABLE {$this->getTable('delivery_note')} (\r\n\t\t\t`delivery_note_id` int(7) unsigned NOT NULL auto_increment,\r\n\t\t\t`note` text NOT NULL,\r\n\t\t\tPRIMARY KEY (`delivery_note_id`)\r\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;\r\n\t"); $installer->endSetup(); $setup = new Mage_Sales_Model_Mysql4_Setup('sales_setup'); $setup->getConnection()->addColumn($setup->getTable('sales_flat_quote'), 'delivery_note', 'text NULL DEFAULT NULL'); $setup->addAttribute('quote', 'delivery_note', array('type' => 'varchar', 'visible' => false)); $installer->addAttribute('order', 'delivery_note_id', array('type' => 'int', 'visible' => false, 'required' => false));
$installer->removeAttribute('catalog_product', 'qty_multiplier'); $installer->addAttribute('catalog_product', 'qty_multiplier', array('label' => 'Qty Multiplyer', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 'input' => 'text', 'type' => 'int', 'unique' => '0', 'required' => '0', 'used_in_product_listing' => '1', 'visible' => '1', 'user_defined' => '1', 'note' => '')); $installer->addAttributeToSet($entityTypeId, $attributeSetId, $attributeGroupId, 'qty_multiplier'); // 3. Install Order Item Attributes $setup = new Mage_Sales_Model_Mysql4_Setup(); $setup->getConnection()->dropColumn($setup->getTable("sales/order_item"), "box_id"); $setup->addAttribute("order_item", "box_id", array('type' => 'int')); $setup->getConnection()->dropColumn($setup->getTable("sales/quote_item"), "box_id"); $setup->addAttribute("quote_item", "box_id", array('type' => 'int')); $setup->getConnection()->dropColumn($setup->getTable("sales/order_item"), "box_sku"); $setup->addAttribute("order_item", "box_sku", array('type' => 'text')); $setup->getConnection()->dropColumn($setup->getTable("sales/quote_item"), "box_sku"); $setup->addAttribute("quote_item", "box_sku", array('type' => 'text')); // 4. Install Order Attributes $setup = new Mage_Sales_Model_Mysql4_Setup(); $setup->getConnection()->dropColumn($setup->getTable("sales/order"), "subscription_id"); $setup->addAttribute("order", "subscription_id", array('type' => 'int')); $setup->getConnection()->dropColumn($setup->getTable("sales/quote"), "subscription_id"); $setup->addAttribute("quote", "subscription_id", array('type' => 'int')); $setup->getConnection()->dropColumn($setup->getTable("sales/order"), "ids_code"); $setup->addAttribute("order", "ids_code", array('type' => 'text')); $setup->getConnection()->dropColumn($setup->getTable("sales/quote"), "ids_code"); $setup->addAttribute("quote", "ids_code", array('type' => 'text')); // 5. Install Customer Attributes $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); $setup->removeAttribute('customer', 'payment_token'); $entityTypeId = $setup->getEntityTypeId('customer'); $attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId); $attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); $setup->addAttribute('customer', 'payment_token', array('input' => 'text', "type" => 'varchar', 'label' => 'Payment Token', 'visible' => 1, 'required' => 0, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL)); $setup->addAttributeToSet($entityTypeId, $attributeSetId, $attributeGroupId, 'payment_token');
<?php $installer = $this; $installer->startSetup(); // 1. Install Order Attributes $setup = new Mage_Sales_Model_Mysql4_Setup(); $setup->getConnection()->dropColumn($setup->getTable("sales/order"), "is_prepay"); $setup->addAttribute("order", "is_prepay", array('type' => 'int')); $setup->getConnection()->dropColumn($setup->getTable("sales/quote"), "is_prepay"); $setup->addAttribute("quote", "is_prepay", array('type' => 'int')); $installer->endSetup();
foreach ($configValuesMap as $configPath => $configValue) { $installer->setConfigData($configPath, $configValue); } $installer->run("\n\tDROP TABLE IF EXISTS {$this->getTable('payperrentals/mailinglog')};\n\n\tCREATE TABLE {$this->getTable('payperrentals/mailinglog')} (\n\t\t`id` INT( 11 ) NOT NULL auto_increment,\n\t\t`is_cron` int(11) NOT NULL DEFAULT '0',\n\t\t`from_name` varchar(250) NOT NULL,\n\t\t`from_email` varchar(250) NOT NULL,\n\t\t`to_name` varchar(250) NOT NULL,\n\t\t`to_email` varchar(250) NOT NULL,\n\t\t`subject` TEXT,\n\t\t`message` TEXT,\n\t\t`message_error` TEXT,\n\t\t`created_at` DATETIME NOT NULL ,\n\t\tPRIMARY KEY ( `id` )\n\n\t) DEFAULT CHARSET utf8 ENGINE = InnoDB;\n\n\t"); $installer->endSetup(); $installer2 = new Mage_Sales_Model_Mysql4_Setup('sales_setup'); $installer2->startSetup(); $installer2->addAttribute('order', 'start_datetime', array('type' => 'datetime', 'grid' => true, 'unsigned' => true)); $installer2->addAttribute('order', 'end_datetime', array('type' => 'datetime', 'grid' => true, 'unsigned' => true)); $installer2->addAttribute('order', 'send_datetime', array('type' => 'datetime', 'grid' => true, 'unsigned' => true)); $installer2->addAttribute('order', 'return_datetime', array('type' => 'datetime', 'grid' => true, 'unsigned' => true)); $installer2->addAttribute('order', 'estimate_send', array('type' => 'datetime', 'grid' => true, 'unsigned' => true)); $installer2->addAttribute('order', 'estimate_return', array('type' => 'datetime', 'grid' => true, 'unsigned' => true)); $installer2->addAttribute('quote', 'start_datetime', array('type' => 'datetime', 'grid' => true, 'unsigned' => true)); $installer2->addAttribute('quote', 'end_datetime', array('type' => 'datetime', 'grid' => true, 'unsigned' => true)); $installer2->getConnection()->addColumn($installer2->getTable('sales/quote'), 'start_datetime', 'DATETIME'); $installer2->getConnection()->addColumn($installer2->getTable('sales/order'), 'end_datetime', 'DATETIME'); $installer2->getConnection()->addColumn($installer2->getTable('sales/quote'), 'end_datetime', 'DATETIME'); $installer2->getConnection()->addColumn($installer2->getTable('sales/order'), 'start_datetime', 'DATETIME'); $installer2->getConnection()->addColumn($installer2->getTable('sales/order'), 'send_datetime', 'DATETIME'); $installer2->getConnection()->addColumn($installer2->getTable('sales/order'), 'return_datetime', 'DATETIME'); $installer2->getConnection()->addColumn($installer2->getTable('sales/order'), 'estimate_send', 'DATETIME'); $installer2->getConnection()->addColumn($installer2->getTable('sales/order'), 'estimate_return', 'DATETIME'); $installer2->addAttribute('quote', 'send_datetime', array('type' => 'datetime', 'grid' => true, 'unsigned' => true)); $installer2->addAttribute('quote', 'return_datetime', array('type' => 'datetime', 'grid' => true, 'unsigned' => true)); $installer2->addAttribute('quote', 'estimate_send', array('type' => 'datetime', 'grid' => true, 'unsigned' => true)); $installer2->addAttribute('quote', 'estimate_return', array('type' => 'datetime', 'grid' => true, 'unsigned' => true)); $installer2->getConnection()->addColumn($installer2->getTable('sales/quote'), 'send_datetime', 'DATETIME'); $installer2->getConnection()->addColumn($installer2->getTable('sales/quote'), 'return_datetime', 'DATETIME'); $installer2->getConnection()->addColumn($installer2->getTable('sales/quote'), 'estimate_send', 'DATETIME'); $installer2->getConnection()->addColumn($installer2->getTable('sales/quote'), 'estimate_return', 'DATETIME');
<?php /** * * @author Enrique Piatti */ /** @var Mage_Catalog_Model_Resource_Setup $installer */ $installer = $this; $installer->startSetup(); $installer->endSetup(); $installer2 = new Mage_Sales_Model_Mysql4_Setup('sales_setup'); $installer2->startSetup(); $installer2->addAttribute('order', 'event_id', array('type' => 'int', 'grid' => true, 'unsigned' => true)); $installer2->addAttribute('quote', 'event_id', array('type' => 'int', 'grid' => true, 'unsigned' => true)); $installer2->addAttribute('order', 'event_name', array('type' => 'text', 'grid' => true)); $installer2->addAttribute('quote', 'event_name', array('type' => 'text', 'grid' => true)); $installer2->addAttribute('order', 'gate_name', array('type' => 'text', 'grid' => true)); $installer2->addAttribute('quote', 'gate_name', array('type' => 'text', 'grid' => true)); $installer2->getConnection()->addColumn($installer2->getTable('sales/quote'), 'gate_name', 'TEXT'); $installer2->getConnection()->addColumn($installer2->getTable('sales/order'), 'gate_name', 'TEXT'); $installer2->getConnection()->addColumn($installer2->getTable('sales/quote'), 'event_name', 'TEXT'); $installer2->getConnection()->addColumn($installer2->getTable('sales/order'), 'event_name', 'TEXT'); $installer2->getConnection()->addColumn($installer2->getTable('sales/quote'), 'event_id', 'INT'); $installer2->getConnection()->addColumn($installer2->getTable('sales/order'), 'event_id', 'INT'); $installer2->endSetup();
<?php $installer = $this; $installer->startSetup(); // 1. Install Order Item Attributes $setup = new Mage_Sales_Model_Mysql4_Setup(); $setup->getConnection()->dropColumn($setup->getTable("sales/order_item"), "is_subscription"); $setup->addAttribute("order_item", "is_subscription", array('type' => 'int')); $setup->getConnection()->dropColumn($setup->getTable("sales/quote_item"), "is_subscription"); $setup->addAttribute("quote_item", "is_subscription", array('type' => 'int')); $installer->endSetup();
<?php $this->startSetup(); $salesSetup = new Mage_Sales_Model_Mysql4_Setup('sales_setup'); $salesSetup->getConnection()->addColumn($salesSetup->getTable('sales_flat_quote'), 'subscribe_to_newsletter', 'smallint(6) NULL DEFAULT NULL'); $salesSetup->addAttribute('quote', 'subscribe_to_newsletter', array('type' => 'static', 'visible' => false)); $this->endSetup();