/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.46-0.9.47.php

https://bitbucket.org/dnejedly/eaparts · PHP · 126 lines · 83 code · 18 blank · 25 comment · 0 complexity · 62375ba25d0069e70792f6773a444abf MD5 · raw file

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Sales
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /* @var $installer Mage_Sales_Model_Mysql4_Setup */
  27. $installer = $this;
  28. $this->startSetup();
  29. $orderEntityType = $installer->getEntityType('order');
  30. $orderEntityTypeId = $orderEntityType['entity_type_id'];
  31. $attributes = array(
  32. $installer->getAttribute($orderEntityTypeId, 'is_virtual'),
  33. $installer->getAttribute($orderEntityTypeId, 'shipping_description')
  34. );
  35. $installer->getConnection()->addColumn($this->getTable('sales_order'), $attributes[0]['attribute_code'], "tinyint(1) UNSIGNED NOT NULL DEFAULT 0");
  36. $installer->getConnection()->addColumn($this->getTable('sales_order'), $attributes[1]['attribute_code'], "varchar(255) NOT NULL DEFAULT ''");
  37. try {
  38. $installer->getConnection()->beginTransaction();
  39. foreach ($attributes as $attribute) {
  40. $installer->run("
  41. UPDATE {$this->getTable('sales_order')} AS o, {$this->getTable('sales_order')}_{$attribute['backend_type']} AS od
  42. SET o.{$attribute['attribute_code']} = od.value
  43. WHERE od.entity_id = o.entity_id
  44. AND od.attribute_id = {$attribute['attribute_id']}
  45. AND od.entity_type_id = {$orderEntityTypeId}
  46. ");
  47. $installer->run("
  48. DELETE FROM {$this->getTable('sales_order')}_{$attribute['backend_type']}
  49. WHERE attribute_id = {$attribute['attribute_id']}
  50. AND entity_type_id = {$orderEntityTypeId}
  51. ");
  52. }
  53. foreach ($attributes as $attribute) {
  54. $installer->updateAttribute($orderEntityTypeId, $attribute['attribute_code'], array('backend_type' => 'static'));
  55. }
  56. $installer->getConnection()->commit();
  57. } catch (Exception $e) {
  58. $installer->getConnection()->rollback();
  59. foreach ($attributes as $attribute) {
  60. $installer->getConnection()->dropColumn($this->getTable('sales_order'), $attribute['attribute_code']);
  61. }
  62. throw $e;
  63. }
  64. $installer->run("
  65. CREATE TABLE `{$installer->getTable('sales/shipping_aggregated')}`
  66. (
  67. `id` int(11) unsigned NOT NULL auto_increment,
  68. `period` date NOT NULL DEFAULT '0000-00-00',
  69. `store_id` smallint(5) unsigned NULL DEFAULT NULL,
  70. `order_status` varchar(50) NOT NULL default '',
  71. `shipping_description` varchar(255) NOT NULL default '',
  72. `orders_count` int(11) NOT NULL DEFAULT '0',
  73. `total_shipping` decimal(12,4) NOT NULL DEFAULT '0',
  74. PRIMARY KEY (`id`),
  75. UNIQUE KEY `UNQ_PERIOD_STORE_ORDER_STATUS` (`period`,`store_id`, `order_status`, `shipping_description`),
  76. KEY `IDX_STORE_ID` (`store_id`)
  77. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  78. CREATE TABLE `{$installer->getTable('sales/shipping_aggregated_order')}`
  79. (
  80. `id` int(11) unsigned NOT NULL auto_increment,
  81. `period` date NOT NULL DEFAULT '0000-00-00',
  82. `store_id` smallint(5) unsigned NULL DEFAULT NULL,
  83. `order_status` varchar(50) NOT NULL default '',
  84. `shipping_description` varchar(255) NOT NULL default '',
  85. `orders_count` int(11) NOT NULL DEFAULT '0',
  86. `total_shipping` decimal(12,4) NOT NULL DEFAULT '0',
  87. PRIMARY KEY (`id`),
  88. UNIQUE KEY `UNQ_PERIOD_STORE_ORDER_STATUS` (`period`,`store_id`, `order_status`, `shipping_description`),
  89. KEY `IDX_STORE_ID` (`store_id`)
  90. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  91. ");
  92. $installer->getConnection()->addConstraint(
  93. 'SALES_SHIPPING_AGGREGATED_STORE',
  94. $installer->getTable('sales/shipping_aggregated'),
  95. 'store_id',
  96. $installer->getTable('core/store'),
  97. 'store_id',
  98. 'SET NULL'
  99. );
  100. $installer->getConnection()->addConstraint(
  101. 'SALES_SHIPPING_AGGREGATED_ORDER_STORE',
  102. $installer->getTable('sales/shipping_aggregated_order'),
  103. 'store_id',
  104. $installer->getTable('core/store'),
  105. 'store_id',
  106. 'SET NULL'
  107. );
  108. $this->endSetup();