InstallSchema.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * This file is part of the Klarna Core module
  4. *
  5. * (c) Klarna Bank AB (publ)
  6. *
  7. * For the full copyright and license information, please view the NOTICE
  8. * and LICENSE files that were distributed with this source code.
  9. */
  10. namespace Klarna\Core\Setup;
  11. use Magento\Framework\DB\Ddl\Table;
  12. use Magento\Framework\Setup\InstallSchemaInterface;
  13. use Magento\Framework\Setup\ModuleContextInterface;
  14. use Magento\Framework\Setup\SchemaSetupInterface;
  15. /**
  16. * Class InstallSchema
  17. *
  18. * @package Klarna\Core\Setup
  19. */
  20. class InstallSchema implements InstallSchemaInterface
  21. {
  22. /**
  23. * @param SchemaSetupInterface $setup
  24. * @param ModuleContextInterface $context
  25. * @throws \Zend_Db_Exception
  26. * @SuppressWarnings(PMD.UnusedFormalParameter)
  27. */
  28. public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
  29. {
  30. $installer = $setup;
  31. if ($installer->tableExists('klarna_core_order')) {
  32. return;
  33. }
  34. $installer->startSetup();
  35. /**
  36. * Create table 'klarna_kco_order'
  37. */
  38. $table = $installer->getConnection()
  39. ->newTable($installer->getTable('klarna_core_order'))
  40. ->addColumn(
  41. 'id',
  42. Table::TYPE_INTEGER,
  43. null,
  44. [
  45. 'identity' => true,
  46. 'unsigned' => true,
  47. 'nullable' => false,
  48. 'primary' => true,
  49. ],
  50. 'Entity Id'
  51. )
  52. ->addColumn(
  53. 'klarna_order_id',
  54. Table::TYPE_TEXT,
  55. 255,
  56. [],
  57. 'Klarna Order Id'
  58. )
  59. ->addColumn(
  60. 'session_id',
  61. Table::TYPE_TEXT,
  62. 255,
  63. [],
  64. 'Session Id'
  65. )
  66. ->addColumn(
  67. 'reservation_id',
  68. Table::TYPE_TEXT,
  69. 255,
  70. [],
  71. 'Reservation Id'
  72. )
  73. ->addColumn(
  74. 'order_id',
  75. Table::TYPE_INTEGER,
  76. null,
  77. [
  78. 'unsigned' => true,
  79. 'nullable' => false,
  80. ],
  81. 'Order Id'
  82. )
  83. ->addColumn(
  84. 'is_acknowledged',
  85. Table::TYPE_SMALLINT,
  86. null,
  87. [
  88. 'nullable' => false,
  89. 'default' => '0',
  90. ],
  91. 'Is Acknowledged'
  92. )
  93. ->addForeignKey(
  94. $installer->getFkName(
  95. 'klarna_core_order',
  96. 'order_id',
  97. 'sales_order',
  98. 'entity_id'
  99. ),
  100. 'order_id',
  101. $installer->getTable('sales_order'),
  102. 'entity_id',
  103. Table::ACTION_CASCADE,
  104. Table::ACTION_CASCADE
  105. )
  106. ->setComment('Klarna Order');
  107. $installer->getConnection()->createTable($table);
  108. $installer->endSetup();
  109. }
  110. }