RmaSetupSchema.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Setup;
  6. use Magento\Framework\DB\Ddl\Table;
  7. use Magento\Framework\Setup\SchemaSetupInterface;
  8. use Temando\Shipping\Api\Data\Shipment\ShipmentReferenceInterface;
  9. use Temando\Shipping\Model\Config\ModuleConfigInterface;
  10. use Temando\Shipping\Model\ResourceModel\Rma\RmaShipment;
  11. /**
  12. * Schema setup for use during installation / upgrade
  13. *
  14. * @package Temando\Shipping\Setup
  15. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  16. * @author Benjamin Heuer <benjamin.heuer@netresearch.de>
  17. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  18. * @link http://www.temando.com/
  19. */
  20. class RmaSetupSchema
  21. {
  22. const TABLE_RMA_SHIPMENT = 'temando_rma_shipment';
  23. /**
  24. * @var ModuleConfigInterface
  25. */
  26. private $moduleConfig;
  27. /**
  28. * RmaSetupSchema constructor.
  29. * @param ModuleConfigInterface $moduleConfig
  30. */
  31. public function __construct(ModuleConfigInterface $moduleConfig)
  32. {
  33. $this->moduleConfig = $moduleConfig;
  34. }
  35. /**
  36. * @param SchemaSetupInterface $installer
  37. *
  38. * @return void
  39. * @throws \Zend_Db_Exception
  40. */
  41. public function createRmaShipmentTable(SchemaSetupInterface $installer)
  42. {
  43. if (!$this->moduleConfig->isRmaAvailable()) {
  44. return;
  45. }
  46. $table = $installer->getConnection()->newTable(
  47. $installer->getTable(self::TABLE_RMA_SHIPMENT)
  48. );
  49. $table->addColumn(
  50. RmaShipment::RMA_ID,
  51. Table::TYPE_INTEGER,
  52. null,
  53. ['primary' => true, 'identity' => false, 'nullable' => false, 'unsigned' => true],
  54. 'RMA ID'
  55. );
  56. $table->addColumn(
  57. RmaShipment::RMA_SHIPMENT_ID,
  58. Table::TYPE_TEXT,
  59. 64,
  60. ['primary' => true, 'identity' => false, 'nullable' => false],
  61. 'External Return Shipment ID'
  62. );
  63. $table->addForeignKey(
  64. $installer->getFkName(
  65. self::TABLE_RMA_SHIPMENT,
  66. RmaShipment::RMA_ID,
  67. 'magento_rma',
  68. 'entity_id'
  69. ),
  70. RmaShipment::RMA_ID,
  71. $installer->getTable('magento_rma'),
  72. 'entity_id',
  73. Table::ACTION_CASCADE
  74. );
  75. $table->setComment(
  76. 'RMA to Return Shipment Associations'
  77. );
  78. $installer->getConnection()->createTable($table);
  79. }
  80. /**
  81. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  82. * @return void
  83. */
  84. public function addReturnShipmentIdColumn(SchemaSetupInterface $installer)
  85. {
  86. $tableName = $installer->getTable(SetupSchema::TABLE_SHIPMENT, SetupSchema::SALES_CONNECTION_NAME);
  87. $installer->getConnection(SetupSchema::SALES_CONNECTION_NAME)->addColumn(
  88. $tableName,
  89. ShipmentReferenceInterface::EXT_RETURN_SHIPMENT_ID,
  90. [
  91. 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
  92. 'length' => 64,
  93. 'nullable' => true,
  94. 'comment' => 'External Return Shipment Id'
  95. ]
  96. );
  97. }
  98. }