PageRenderTime 27ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/app/code/core/Mage/Tax/sql/tax_setup/install-1.6.0.0.php

https://bitbucket.org/mkrasuski/magento-ce
PHP | 287 lines | 233 code | 7 blank | 47 comment | 0 complexity | 4c14e324b02ceb79258ccbd98e474389 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@magento.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.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Tax
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /** @var $installer Mage_Tax_Model_Resource_Setup */
  27. $installer = $this;
  28. $installer->startSetup();
  29. //
  30. /**
  31. * Create table 'tax/class'
  32. */
  33. $table = $installer->getConnection()
  34. ->newTable($installer->getTable('tax/tax_class'))
  35. ->addColumn('class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
  36. 'identity' => true,
  37. 'nullable' => false,
  38. 'primary' => true,
  39. ), 'Class Id')
  40. ->addColumn('class_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
  41. 'nullable' => false
  42. ), 'Class Name')
  43. ->addColumn('class_type', Varien_Db_Ddl_Table::TYPE_TEXT, 8, array(
  44. 'nullable' => false,
  45. 'default' => Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER,
  46. ), 'Class Type')
  47. ->setComment('Tax Class');
  48. $installer->getConnection()->createTable($table);
  49. /**
  50. * Create table 'tax/calculation_rule'
  51. */
  52. $table = $installer->getConnection()
  53. ->newTable($installer->getTable('tax/tax_calculation_rule'))
  54. ->addColumn('tax_calculation_rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  55. 'identity' => true,
  56. 'nullable' => false,
  57. 'primary' => true,
  58. ), 'Tax Calculation Rule Id')
  59. ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
  60. 'nullable' => false,
  61. ), 'Code')
  62. ->addColumn('priority', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  63. 'nullable' => false,
  64. ), 'Priority')
  65. ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  66. 'nullable' => false,
  67. ), 'Position')
  68. ->addIndex(
  69. $installer->getIdxName('tax/tax_calculation_rule',
  70. array('priority', 'position', 'tax_calculation_rule_id')),
  71. array('priority', 'position', 'tax_calculation_rule_id')
  72. )
  73. ->addIndex($installer->getIdxName('tax/tax_calculation_rule', array('code')),
  74. array('code'))
  75. ->setComment('Tax Calculation Rule');
  76. $installer->getConnection()->createTable($table);
  77. /**
  78. * Create table 'tax/calculation_rate'
  79. */
  80. $table = $installer->getConnection()
  81. ->newTable($installer->getTable('tax/tax_calculation_rate'))
  82. ->addColumn('tax_calculation_rate_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  83. 'identity' => true,
  84. 'nullable' => false,
  85. 'primary' => true,
  86. ), 'Tax Calculation Rate Id')
  87. ->addColumn('tax_country_id', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array(
  88. 'nullable' => false,
  89. ), 'Tax Country Id')
  90. ->addColumn('tax_region_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  91. 'nullable' => false,
  92. ), 'Tax Region Id')
  93. ->addColumn('tax_postcode', Varien_Db_Ddl_Table::TYPE_TEXT, 21, array(
  94. ), 'Tax Postcode')
  95. ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
  96. 'nullable' => false,
  97. ), 'Code')
  98. ->addColumn('rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
  99. 'nullable' => false,
  100. ), 'Rate')
  101. ->addColumn('zip_is_range', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
  102. ), 'Zip Is Range')
  103. ->addColumn('zip_from', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  104. 'unsigned' => true,
  105. ), 'Zip From')
  106. ->addColumn('zip_to', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  107. 'unsigned' => true,
  108. ), 'Zip To')
  109. ->addIndex(
  110. $installer->getIdxName('tax/tax_calculation_rate',
  111. array('tax_country_id', 'tax_region_id', 'tax_postcode')),
  112. array('tax_country_id', 'tax_region_id', 'tax_postcode')
  113. )
  114. ->addIndex($installer->getIdxName('tax/tax_calculation_rate', array('code')),
  115. array('code'))
  116. ->addIndex(
  117. $installer->getIdxName('tax/tax_calculation_rate',
  118. array('tax_calculation_rate_id', 'tax_country_id', 'tax_region_id', 'zip_is_range', 'tax_postcode')),
  119. array('tax_calculation_rate_id', 'tax_country_id', 'tax_region_id', 'zip_is_range', 'tax_postcode')
  120. )
  121. ->setComment('Tax Calculation Rate');
  122. $installer->getConnection()->createTable($table);
  123. /**
  124. * Create table 'tax/calculation'
  125. */
  126. $table = $installer->getConnection()
  127. ->newTable($installer->getTable('tax/tax_calculation'))
  128. ->addColumn('tax_calculation_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  129. 'identity' => true,
  130. 'nullable' => false,
  131. 'primary' => true,
  132. ), 'Tax Calculation Id')
  133. ->addColumn('tax_calculation_rate_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  134. 'nullable' => false,
  135. ), 'Tax Calculation Rate Id')
  136. ->addColumn('tax_calculation_rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  137. 'nullable' => false,
  138. ), 'Tax Calculation Rule Id')
  139. ->addColumn('customer_tax_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
  140. 'nullable' => false,
  141. ), 'Customer Tax Class Id')
  142. ->addColumn('product_tax_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
  143. 'nullable' => false,
  144. ), 'Product Tax Class Id')
  145. ->addIndex($installer->getIdxName('tax/tax_calculation', array('tax_calculation_rule_id')),
  146. array('tax_calculation_rule_id'))
  147. ->addIndex($installer->getIdxName('tax/tax_calculation', array('tax_calculation_rate_id')),
  148. array('tax_calculation_rate_id'))
  149. ->addIndex($installer->getIdxName('tax/tax_calculation', array('customer_tax_class_id')),
  150. array('customer_tax_class_id'))
  151. ->addIndex($installer->getIdxName('tax/tax_calculation', array('product_tax_class_id')),
  152. array('product_tax_class_id'))
  153. ->addIndex($installer->getIdxName('tax/tax_calculation',
  154. array('tax_calculation_rate_id', 'customer_tax_class_id', 'product_tax_class_id')),
  155. array('tax_calculation_rate_id', 'customer_tax_class_id', 'product_tax_class_id'))
  156. ->addForeignKey($installer->getFkName('tax/tax_calculation', 'product_tax_class_id', 'tax/tax_class', 'class_id'),
  157. 'product_tax_class_id', $installer->getTable('tax/tax_class'), 'class_id',
  158. Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
  159. ->addForeignKey($installer->getFkName('tax/tax_calculation', 'customer_tax_class_id', 'tax/tax_class', 'class_id'),
  160. 'customer_tax_class_id', $installer->getTable('tax/tax_class'), 'class_id',
  161. Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
  162. ->addForeignKey($installer->getFkName(
  163. 'tax/tax_calculation', 'tax_calculation_rate_id', 'tax/tax_calculation_rate', 'tax_calculation_rate_id'),
  164. 'tax_calculation_rate_id', $installer->getTable('tax/tax_calculation_rate'), 'tax_calculation_rate_id',
  165. Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
  166. ->addForeignKey($installer->getFkName(
  167. 'tax/tax_calculation', 'tax_calculation_rule_id', 'tax/tax_calculation_rule', 'tax_calculation_rule_id'),
  168. 'tax_calculation_rule_id', $installer->getTable('tax/tax_calculation_rule'), 'tax_calculation_rule_id',
  169. Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
  170. ->setComment('Tax Calculation');
  171. $installer->getConnection()->createTable($table);
  172. /**
  173. * Create table 'tax/calculation_rate_title'
  174. */
  175. $table = $installer->getConnection()
  176. ->newTable($installer->getTable('tax/tax_calculation_rate_title'))
  177. ->addColumn('tax_calculation_rate_title_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  178. 'identity' => true,
  179. 'nullable' => false,
  180. 'primary' => true,
  181. ), 'Tax Calculation Rate Title Id')
  182. ->addColumn('tax_calculation_rate_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  183. 'nullable' => false,
  184. ), 'Tax Calculation Rate Id')
  185. ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
  186. 'unsigned' => true,
  187. 'nullable' => false,
  188. ), 'Store Id')
  189. ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
  190. 'nullable' => false,
  191. ), 'Value')
  192. ->addIndex($installer->getIdxName('tax/tax_calculation_rate_title', array('tax_calculation_rate_id', 'store_id')),
  193. array('tax_calculation_rate_id', 'store_id'))
  194. ->addIndex($installer->getIdxName('tax/tax_calculation_rate_title', array('tax_calculation_rate_id')),
  195. array('tax_calculation_rate_id'))
  196. ->addIndex($installer->getIdxName('tax/tax_calculation_rate_title', array('store_id')),
  197. array('store_id'))
  198. ->addForeignKey($installer->getFkName('tax/tax_calculation_rate_title', 'store_id', 'core/store', 'store_id'),
  199. 'store_id', $installer->getTable('core/store'), 'store_id',
  200. Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
  201. ->addForeignKey($installer->getFkName(
  202. 'tax/tax_calculation_rate_title', 'tax_calculation_rate_id',
  203. 'tax/tax_calculation_rate', 'tax_calculation_rate_id'
  204. ),
  205. 'tax_calculation_rate_id', $installer->getTable('tax/tax_calculation_rate'), 'tax_calculation_rate_id',
  206. Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
  207. ->setComment('Tax Calculation Rate Title');
  208. $installer->getConnection()->createTable($table);
  209. /**
  210. * Create table 'tax/order_aggregated_created'
  211. */
  212. $table = $installer->getConnection()
  213. ->newTable($installer->getTable('tax/tax_order_aggregated_created'))
  214. ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  215. 'identity' => true,
  216. 'unsigned' => true,
  217. 'nullable' => false,
  218. 'primary' => true,
  219. ), 'Id')
  220. ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array(
  221. 'nullable' => true,
  222. ), 'Period')
  223. ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
  224. 'unsigned' => true,
  225. ), 'Store Id')
  226. ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
  227. 'nullable' => false,
  228. ), 'Code')
  229. ->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array(
  230. 'nullable' => false,
  231. ), 'Order Status')
  232. ->addColumn('percent', Varien_Db_Ddl_Table::TYPE_FLOAT, null, array(
  233. ), 'Percent')
  234. ->addColumn('orders_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
  235. 'unsigned' => true,
  236. 'nullable' => false,
  237. 'default' => '0',
  238. ), 'Orders Count')
  239. ->addColumn('tax_base_amount_sum', Varien_Db_Ddl_Table::TYPE_FLOAT, null, array(
  240. ), 'Tax Base Amount Sum')
  241. ->addIndex($installer->getIdxName(
  242. 'tax/tax_order_aggregated_created',
  243. array('period', 'store_id', 'code', 'percent', 'order_status'), true
  244. ),
  245. array('period', 'store_id', 'code', 'percent', 'order_status'), array('type' => 'unique'))
  246. ->addIndex($installer->getIdxName('tax/tax_order_aggregated_created', array('store_id')),
  247. array('store_id'))
  248. ->addForeignKey($installer->getFkName('tax/tax_order_aggregated_created', 'store_id', 'core/store', 'store_id'),
  249. 'store_id', $installer->getTable('core/store'), 'store_id',
  250. Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
  251. ->setComment('Tax Order Aggregation');
  252. $installer->getConnection()->createTable($table);
  253. /**
  254. * Add tax_class_id attribute to the 'eav/attribute' table
  255. */
  256. $catalogInstaller = Mage::getResourceModel('catalog/setup', 'catalog_setup');
  257. $catalogInstaller->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'tax_class_id', array(
  258. 'group' => 'Prices',
  259. 'type' => 'int',
  260. 'backend' => '',
  261. 'frontend' => '',
  262. 'label' => 'Tax Class',
  263. 'input' => 'select',
  264. 'class' => '',
  265. 'source' => 'tax/class_source_product',
  266. 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
  267. 'visible' => true,
  268. 'required' => true,
  269. 'user_defined' => false,
  270. 'default' => '',
  271. 'searchable' => true,
  272. 'filterable' => false,
  273. 'comparable' => false,
  274. 'visible_on_front' => false,
  275. 'visible_in_advanced_search' => true,
  276. 'used_in_product_listing' => true,
  277. 'unique' => false,
  278. 'apply_to' => 'simple,configurable,virtual,downloadable,bundle'
  279. ));
  280. $installer->endSetup();