SetupSchema.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  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\Adapter\AdapterInterface;
  7. use Magento\Framework\DB\Ddl\Table;
  8. use Magento\Framework\Setup\SchemaSetupInterface;
  9. use Temando\Shipping\Api\Data\Checkout\AddressInterface;
  10. use Temando\Shipping\Api\Data\Delivery\CollectionPointSearchRequestInterface;
  11. use Temando\Shipping\Api\Data\Delivery\OrderCollectionPointInterface;
  12. use Temando\Shipping\Api\Data\Delivery\OrderPickupLocationInterface;
  13. use Temando\Shipping\Api\Data\Delivery\PickupLocationSearchRequestInterface;
  14. use Temando\Shipping\Api\Data\Delivery\QuoteCollectionPointInterface;
  15. use Temando\Shipping\Api\Data\Delivery\QuotePickupLocationInterface;
  16. use Temando\Shipping\Api\Data\Order\OrderReferenceInterface;
  17. use Temando\Shipping\Api\Data\Shipment\ShipmentReferenceInterface;
  18. /**
  19. * Schema setup for use during installation / upgrade
  20. *
  21. * @package Temando\Shipping\Setup
  22. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  23. * @author Benjamin Heuer <benjamin.heuer@netresearch.de>
  24. * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. * @link https://www.temando.com/
  26. */
  27. class SetupSchema
  28. {
  29. const CHECKOUT_CONNECTION_NAME = 'checkout';
  30. const SALES_CONNECTION_NAME = 'sales';
  31. const TABLE_SHIPMENT = 'temando_shipment';
  32. const TABLE_ORDER = 'temando_order';
  33. const TABLE_CHECKOUT_ADDRESS = 'temando_checkout_address';
  34. const TABLE_COLLECTION_POINT_SEARCH = 'temando_collection_point_search';
  35. const TABLE_QUOTE_COLLECTION_POINT = 'temando_quote_collection_point';
  36. const TABLE_ORDER_COLLECTION_POINT = 'temando_order_collection_point';
  37. const TABLE_PICKUP_LOCATION_SEARCH = 'temando_pickup_location_search';
  38. const TABLE_QUOTE_PICKUP_LOCATION = 'temando_quote_pickup_location';
  39. const TABLE_ORDER_PICKUP_LOCATION = 'temando_order_pickup_location';
  40. /**
  41. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  42. *
  43. * @return void
  44. * @throws \Zend_Db_Exception
  45. */
  46. public function createShipmentTable(SchemaSetupInterface $installer)
  47. {
  48. $table = $installer->getConnection(self::SALES_CONNECTION_NAME)->newTable(
  49. $installer->getTable(self::TABLE_SHIPMENT, self::SALES_CONNECTION_NAME)
  50. );
  51. $table->addColumn(
  52. ShipmentReferenceInterface::ENTITY_ID,
  53. Table::TYPE_INTEGER,
  54. null,
  55. ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
  56. 'Entity Id'
  57. );
  58. $table->addColumn(
  59. ShipmentReferenceInterface::SHIPMENT_ID,
  60. Table::TYPE_INTEGER,
  61. null,
  62. ['unsigned' => true, 'nullable' => false],
  63. 'Magento Shipment Id'
  64. );
  65. $table->addColumn(
  66. ShipmentReferenceInterface::EXT_SHIPMENT_ID,
  67. Table::TYPE_TEXT,
  68. 64,
  69. ['nullable' => false],
  70. 'External Shipment Id'
  71. );
  72. $table->addColumn(
  73. ShipmentReferenceInterface::EXT_LOCATION_ID,
  74. Table::TYPE_TEXT,
  75. 64,
  76. ['nullable' => false],
  77. 'External Location Id'
  78. );
  79. $table->addColumn(
  80. ShipmentReferenceInterface::EXT_TRACKING_URL,
  81. Table::TYPE_TEXT,
  82. 255,
  83. [],
  84. 'External Tracking Url'
  85. );
  86. $table->addColumn(
  87. ShipmentReferenceInterface::EXT_TRACKING_REFERENCE,
  88. Table::TYPE_TEXT,
  89. 255,
  90. [],
  91. 'External Tracking Reference'
  92. );
  93. $table->addForeignKey(
  94. $installer->getFkName(
  95. self::TABLE_SHIPMENT,
  96. ShipmentReferenceInterface::SHIPMENT_ID,
  97. 'sales_shipment',
  98. 'entity_id'
  99. ),
  100. ShipmentReferenceInterface::SHIPMENT_ID,
  101. $installer->getTable('sales_shipment', self::SALES_CONNECTION_NAME),
  102. 'entity_id',
  103. Table::ACTION_CASCADE
  104. );
  105. $table->addIndex(
  106. $installer->getIdxName(
  107. self::TABLE_SHIPMENT,
  108. [ShipmentReferenceInterface::SHIPMENT_ID, ShipmentReferenceInterface::EXT_SHIPMENT_ID],
  109. AdapterInterface::INDEX_TYPE_UNIQUE
  110. ),
  111. [ShipmentReferenceInterface::SHIPMENT_ID, ShipmentReferenceInterface::EXT_SHIPMENT_ID],
  112. ['type' => AdapterInterface::INDEX_TYPE_UNIQUE]
  113. );
  114. $table->setComment(
  115. 'Temando Shipment'
  116. );
  117. $installer->getConnection(self::SALES_CONNECTION_NAME)->createTable($table);
  118. }
  119. /**
  120. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  121. *
  122. * @return void
  123. * @throws \Zend_Db_Exception
  124. */
  125. public function createOrderTable(SchemaSetupInterface $installer)
  126. {
  127. $table = $installer->getConnection(self::SALES_CONNECTION_NAME)->newTable(
  128. $installer->getTable(self::TABLE_ORDER, self::SALES_CONNECTION_NAME)
  129. );
  130. $table->addColumn(
  131. OrderReferenceInterface::ENTITY_ID,
  132. Table::TYPE_INTEGER,
  133. null,
  134. ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
  135. 'Entity Id'
  136. );
  137. $table->addColumn(
  138. OrderReferenceInterface::ORDER_ID,
  139. Table::TYPE_INTEGER,
  140. null,
  141. ['unsigned' => true, 'nullable' => false],
  142. 'Magento Order Id'
  143. );
  144. $table->addColumn(
  145. OrderReferenceInterface::EXT_ORDER_ID,
  146. Table::TYPE_TEXT,
  147. 64,
  148. ['nullable' => false],
  149. 'Temando Order Id'
  150. );
  151. $table->addForeignKey(
  152. $installer->getFkName(
  153. self::TABLE_ORDER,
  154. OrderReferenceInterface::ORDER_ID,
  155. 'sales_order',
  156. 'entity_id'
  157. ),
  158. OrderReferenceInterface::ORDER_ID,
  159. $installer->getTable('sales_order', self::SALES_CONNECTION_NAME),
  160. 'entity_id',
  161. Table::ACTION_CASCADE
  162. );
  163. $table->setComment(
  164. 'Temando Order'
  165. );
  166. $installer->getConnection(self::SALES_CONNECTION_NAME)->createTable($table);
  167. }
  168. /**
  169. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  170. *
  171. * @return void
  172. * @throws \Zend_Db_Exception
  173. */
  174. public function createAddressTable(SchemaSetupInterface $installer)
  175. {
  176. $table = $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->newTable(
  177. $installer->getTable(self::TABLE_CHECKOUT_ADDRESS, self::CHECKOUT_CONNECTION_NAME)
  178. );
  179. $table->addColumn(
  180. AddressInterface::ENTITY_ID,
  181. Table::TYPE_INTEGER,
  182. null,
  183. ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
  184. 'Entity Id'
  185. );
  186. $table->addColumn(
  187. AddressInterface::SHIPPING_ADDRESS_ID,
  188. Table::TYPE_INTEGER,
  189. null,
  190. ['unsigned' => true, 'nullable' => false],
  191. 'Magento Quote Address Id'
  192. );
  193. $table->addColumn(
  194. AddressInterface::SERVICE_SELECTION,
  195. Table::TYPE_TEXT,
  196. null,
  197. [],
  198. 'Value Added Services'
  199. );
  200. $table->addForeignKey(
  201. $installer->getFkName(
  202. self::TABLE_CHECKOUT_ADDRESS,
  203. AddressInterface::SHIPPING_ADDRESS_ID,
  204. 'quote_address',
  205. 'address_id'
  206. ),
  207. AddressInterface::SHIPPING_ADDRESS_ID,
  208. $installer->getTable('quote_address', self::CHECKOUT_CONNECTION_NAME),
  209. 'address_id',
  210. Table::ACTION_CASCADE
  211. );
  212. $table->setComment(
  213. 'Temando Checkout Address'
  214. );
  215. $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->createTable($table);
  216. }
  217. /**
  218. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  219. *
  220. * @return void
  221. */
  222. public function setShipmentOriginLocationNullable(SchemaSetupInterface $installer)
  223. {
  224. $tableName = $installer->getTable(self::TABLE_SHIPMENT, self::SALES_CONNECTION_NAME);
  225. $installer->getConnection(self::SALES_CONNECTION_NAME)->modifyColumn(
  226. $tableName,
  227. ShipmentReferenceInterface::EXT_LOCATION_ID,
  228. [
  229. 'type' => Table::TYPE_TEXT,
  230. 'length' => 64,
  231. 'nullable' => true,
  232. ]
  233. );
  234. }
  235. /**
  236. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  237. *
  238. * @return void
  239. * @throws \Zend_Db_Exception
  240. */
  241. public function createCollectionPointSearchTable(SchemaSetupInterface $installer)
  242. {
  243. $table = $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->newTable(
  244. $installer->getTable(self::TABLE_COLLECTION_POINT_SEARCH, self::CHECKOUT_CONNECTION_NAME)
  245. );
  246. $table->addColumn(
  247. CollectionPointSearchRequestInterface::SHIPPING_ADDRESS_ID,
  248. Table::TYPE_INTEGER,
  249. 10,
  250. ['unsigned' => true, 'nullable' => false, 'primary' => true],
  251. 'Entity Id'
  252. );
  253. $table->addColumn(
  254. CollectionPointSearchRequestInterface::COUNTRY_ID,
  255. Table::TYPE_TEXT,
  256. 2,
  257. ['nullable' => false],
  258. 'Country Code'
  259. );
  260. $table->addColumn(
  261. CollectionPointSearchRequestInterface::POSTCODE,
  262. Table::TYPE_TEXT,
  263. 255,
  264. ['nullable' => false],
  265. 'Zip/Postal Code'
  266. );
  267. $table->addForeignKey(
  268. $installer->getFkName(
  269. self::TABLE_COLLECTION_POINT_SEARCH,
  270. CollectionPointSearchRequestInterface::SHIPPING_ADDRESS_ID,
  271. 'quote_address',
  272. 'address_id'
  273. ),
  274. CollectionPointSearchRequestInterface::SHIPPING_ADDRESS_ID,
  275. $installer->getTable('quote_address', self::CHECKOUT_CONNECTION_NAME),
  276. 'address_id',
  277. Table::ACTION_CASCADE
  278. );
  279. $countryTable = $installer->getTable('directory_country', self::CHECKOUT_CONNECTION_NAME);
  280. if ($installer->tableExists($countryTable, self::CHECKOUT_CONNECTION_NAME)) {
  281. $table->addForeignKey(
  282. $installer->getFkName(
  283. self::TABLE_COLLECTION_POINT_SEARCH,
  284. CollectionPointSearchRequestInterface::COUNTRY_ID,
  285. 'directory_country',
  286. 'country_id'
  287. ),
  288. CollectionPointSearchRequestInterface::COUNTRY_ID,
  289. $countryTable,
  290. 'country_id',
  291. Table::ACTION_NO_ACTION
  292. );
  293. }
  294. $table->setComment('Collection Point Search');
  295. $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->createTable($table);
  296. }
  297. /**
  298. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  299. *
  300. * @return void
  301. * @throws \Zend_Db_Exception
  302. */
  303. public function createQuoteCollectionPointTable(SchemaSetupInterface $installer)
  304. {
  305. $table = $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->newTable(
  306. $installer->getTable(self::TABLE_QUOTE_COLLECTION_POINT, self::CHECKOUT_CONNECTION_NAME)
  307. );
  308. $table->addColumn(
  309. QuoteCollectionPointInterface::ENTITY_ID,
  310. Table::TYPE_INTEGER,
  311. null,
  312. ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
  313. 'Entity Id'
  314. );
  315. $table->addColumn(
  316. QuoteCollectionPointInterface::RECIPIENT_ADDRESS_ID,
  317. Table::TYPE_INTEGER,
  318. null,
  319. ['unsigned' => true, 'nullable' => false],
  320. 'Quote Address Id'
  321. );
  322. $table->addColumn(
  323. QuoteCollectionPointInterface::COLLECTION_POINT_ID,
  324. Table::TYPE_TEXT,
  325. 64,
  326. ['nullable' => false],
  327. 'Collection Point Id'
  328. );
  329. $table->addColumn(
  330. QuoteCollectionPointInterface::NAME,
  331. Table::TYPE_TEXT,
  332. 255,
  333. [],
  334. 'Name'
  335. );
  336. $table->addColumn(
  337. QuoteCollectionPointInterface::COUNTRY,
  338. Table::TYPE_TEXT,
  339. 2,
  340. ['nullable' => false],
  341. 'Country Code'
  342. );
  343. $table->addColumn(
  344. QuoteCollectionPointInterface::REGION,
  345. Table::TYPE_TEXT,
  346. 255,
  347. ['nullable' => false],
  348. 'Region'
  349. );
  350. $table->addColumn(
  351. QuoteCollectionPointInterface::POSTCODE,
  352. Table::TYPE_TEXT,
  353. 255,
  354. ['nullable' => false],
  355. 'Zip/Postal Code'
  356. );
  357. $table->addColumn(
  358. QuoteCollectionPointInterface::CITY,
  359. Table::TYPE_TEXT,
  360. 255,
  361. ['nullable' => false],
  362. 'City'
  363. );
  364. $table->addColumn(
  365. QuoteCollectionPointInterface::STREET,
  366. Table::TYPE_TEXT,
  367. null,
  368. ['nullable' => false],
  369. 'Street'
  370. );
  371. $table->addColumn(
  372. QuoteCollectionPointInterface::OPENING_HOURS,
  373. Table::TYPE_TEXT,
  374. null,
  375. ['nullable' => false],
  376. 'Opening Hours'
  377. );
  378. $table->addColumn(
  379. QuoteCollectionPointInterface::SHIPPING_EXPERIENCES,
  380. Table::TYPE_TEXT,
  381. null,
  382. ['nullable' => false],
  383. 'Shipping Experiences'
  384. );
  385. $table->addColumn(
  386. QuoteCollectionPointInterface::SELECTED,
  387. Table::TYPE_SMALLINT,
  388. null,
  389. ['unsigned' => true, 'nullable' => false, 'default' => 0],
  390. 'Is Selected'
  391. );
  392. $table->addForeignKey(
  393. $installer->getFkName(
  394. self::TABLE_QUOTE_COLLECTION_POINT,
  395. QuoteCollectionPointInterface::RECIPIENT_ADDRESS_ID,
  396. self::TABLE_COLLECTION_POINT_SEARCH,
  397. CollectionPointSearchRequestInterface::SHIPPING_ADDRESS_ID
  398. ),
  399. QuoteCollectionPointInterface::RECIPIENT_ADDRESS_ID,
  400. $installer->getTable(self::TABLE_COLLECTION_POINT_SEARCH, self::CHECKOUT_CONNECTION_NAME),
  401. CollectionPointSearchRequestInterface::SHIPPING_ADDRESS_ID,
  402. Table::ACTION_CASCADE
  403. );
  404. $table->setComment('Quote Collection Point Entity');
  405. $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->createTable($table);
  406. }
  407. /**
  408. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  409. *
  410. * @return void
  411. * @throws \Zend_Db_Exception
  412. */
  413. public function createOrderCollectionPointTable(SchemaSetupInterface $installer)
  414. {
  415. $table = $installer->getConnection(self::SALES_CONNECTION_NAME)->newTable(
  416. $installer->getTable(self::TABLE_ORDER_COLLECTION_POINT, self::SALES_CONNECTION_NAME)
  417. );
  418. $table->addColumn(
  419. OrderCollectionPointInterface::RECIPIENT_ADDRESS_ID,
  420. Table::TYPE_INTEGER,
  421. null,
  422. ['unsigned' => true, 'nullable' => false, 'primary' => true],
  423. 'Entity Id'
  424. );
  425. $table->addColumn(
  426. OrderCollectionPointInterface::COLLECTION_POINT_ID,
  427. Table::TYPE_TEXT,
  428. 64,
  429. ['nullable' => false],
  430. 'Collection Point Id'
  431. );
  432. $table->addColumn(
  433. OrderCollectionPointInterface::NAME,
  434. Table::TYPE_TEXT,
  435. 255,
  436. [],
  437. 'Name'
  438. );
  439. $table->addColumn(
  440. OrderCollectionPointInterface::COUNTRY,
  441. Table::TYPE_TEXT,
  442. 2,
  443. ['nullable' => false],
  444. 'Country Code'
  445. );
  446. $table->addColumn(
  447. OrderCollectionPointInterface::REGION,
  448. Table::TYPE_TEXT,
  449. 255,
  450. ['nullable' => false],
  451. 'Region'
  452. );
  453. $table->addColumn(
  454. OrderCollectionPointInterface::POSTCODE,
  455. Table::TYPE_TEXT,
  456. 255,
  457. ['nullable' => false],
  458. 'Zip/Postal Code'
  459. );
  460. $table->addColumn(
  461. OrderCollectionPointInterface::CITY,
  462. Table::TYPE_TEXT,
  463. 255,
  464. ['nullable' => false],
  465. 'City'
  466. );
  467. $table->addColumn(
  468. OrderCollectionPointInterface::STREET,
  469. Table::TYPE_TEXT,
  470. null,
  471. ['nullable' => false],
  472. 'Street'
  473. );
  474. $table->addForeignKey(
  475. $installer->getFkName(
  476. self::TABLE_QUOTE_COLLECTION_POINT,
  477. OrderCollectionPointInterface::RECIPIENT_ADDRESS_ID,
  478. 'sales_order_address',
  479. 'entity_id'
  480. ),
  481. OrderCollectionPointInterface::RECIPIENT_ADDRESS_ID,
  482. $installer->getTable('sales_order_address', self::SALES_CONNECTION_NAME),
  483. 'entity_id',
  484. Table::ACTION_CASCADE
  485. );
  486. $table->setComment('Order Collection Point Entity');
  487. $installer->getConnection(self::SALES_CONNECTION_NAME)->createTable($table);
  488. }
  489. /**
  490. * Add an indicator for collection point checkout being in progress.
  491. *
  492. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  493. * @return void
  494. */
  495. public function addCollectionPointSearchPendingColumn(SchemaSetupInterface $installer)
  496. {
  497. $tableName = $installer->getTable(self::TABLE_COLLECTION_POINT_SEARCH, self::CHECKOUT_CONNECTION_NAME);
  498. // allow empty values for pending searches
  499. $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->modifyColumn(
  500. $tableName,
  501. CollectionPointSearchRequestInterface::COUNTRY_ID,
  502. ['type' => Table::TYPE_TEXT, 'length' => 2, 'nullable' => true]
  503. );
  504. $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->modifyColumn(
  505. $tableName,
  506. CollectionPointSearchRequestInterface::POSTCODE,
  507. ['type' => Table::TYPE_TEXT, 'length' => 255, 'nullable' => true]
  508. );
  509. // add pending indicator
  510. $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->addColumn(
  511. $tableName,
  512. CollectionPointSearchRequestInterface::PENDING,
  513. [
  514. 'type' => Table::TYPE_BOOLEAN,
  515. 'nullable' => false,
  516. 'default' => 0,
  517. 'comment' => 'Pending'
  518. ]
  519. );
  520. }
  521. /**
  522. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  523. *
  524. * @return void
  525. * @throws \Zend_Db_Exception
  526. */
  527. public function createPickupLocationSearchTable(SchemaSetupInterface $installer)
  528. {
  529. $table = $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->newTable(
  530. $installer->getTable(self::TABLE_PICKUP_LOCATION_SEARCH, self::CHECKOUT_CONNECTION_NAME)
  531. );
  532. $table->addColumn(
  533. PickupLocationSearchRequestInterface::SHIPPING_ADDRESS_ID,
  534. Table::TYPE_INTEGER,
  535. 10,
  536. ['unsigned' => true, 'nullable' => false, 'primary' => true],
  537. 'Entity Id'
  538. );
  539. $table->addColumn(
  540. PickupLocationSearchRequestInterface::ACTIVE,
  541. Table::TYPE_BOOLEAN,
  542. 2,
  543. ['nullable' => false],
  544. 'Active'
  545. );
  546. $table->addForeignKey(
  547. $installer->getFkName(
  548. self::TABLE_PICKUP_LOCATION_SEARCH,
  549. PickupLocationSearchRequestInterface::SHIPPING_ADDRESS_ID,
  550. 'quote_address',
  551. 'address_id'
  552. ),
  553. PickupLocationSearchRequestInterface::SHIPPING_ADDRESS_ID,
  554. $installer->getTable('quote_address', self::CHECKOUT_CONNECTION_NAME),
  555. 'address_id',
  556. Table::ACTION_CASCADE
  557. );
  558. $table->setComment('Pickup Location Search');
  559. $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->createTable($table);
  560. }
  561. /**
  562. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  563. *
  564. * @return void
  565. * @throws \Zend_Db_Exception
  566. */
  567. public function createQuotePickupLocationTable(SchemaSetupInterface $installer)
  568. {
  569. $table = $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->newTable(
  570. $installer->getTable(self::TABLE_QUOTE_PICKUP_LOCATION, self::CHECKOUT_CONNECTION_NAME)
  571. );
  572. $table->addColumn(
  573. QuotePickupLocationInterface::ENTITY_ID,
  574. Table::TYPE_INTEGER,
  575. null,
  576. ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
  577. 'Entity Id'
  578. );
  579. $table->addColumn(
  580. QuotePickupLocationInterface::RECIPIENT_ADDRESS_ID,
  581. Table::TYPE_INTEGER,
  582. null,
  583. ['unsigned' => true, 'nullable' => false],
  584. 'Quote Address Id'
  585. );
  586. $table->addColumn(
  587. QuotePickupLocationInterface::PICKUP_LOCATION_ID,
  588. Table::TYPE_TEXT,
  589. 64,
  590. ['nullable' => false],
  591. 'Pickup Location Id'
  592. );
  593. $table->addColumn(
  594. QuotePickupLocationInterface::NAME,
  595. Table::TYPE_TEXT,
  596. 255,
  597. [],
  598. 'Name'
  599. );
  600. $table->addColumn(
  601. QuotePickupLocationInterface::COUNTRY,
  602. Table::TYPE_TEXT,
  603. 2,
  604. ['nullable' => false],
  605. 'Country Code'
  606. );
  607. $table->addColumn(
  608. QuotePickupLocationInterface::REGION,
  609. Table::TYPE_TEXT,
  610. 255,
  611. ['nullable' => false],
  612. 'Region'
  613. );
  614. $table->addColumn(
  615. QuotePickupLocationInterface::POSTCODE,
  616. Table::TYPE_TEXT,
  617. 255,
  618. ['nullable' => false],
  619. 'Zip/Postal Code'
  620. );
  621. $table->addColumn(
  622. QuotePickupLocationInterface::CITY,
  623. Table::TYPE_TEXT,
  624. 255,
  625. ['nullable' => false],
  626. 'City'
  627. );
  628. $table->addColumn(
  629. QuotePickupLocationInterface::STREET,
  630. Table::TYPE_TEXT,
  631. null,
  632. ['nullable' => false],
  633. 'Street'
  634. );
  635. $table->addColumn(
  636. QuotePickupLocationInterface::OPENING_HOURS,
  637. Table::TYPE_TEXT,
  638. null,
  639. ['nullable' => false],
  640. 'Opening Hours'
  641. );
  642. $table->addColumn(
  643. QuotePickupLocationInterface::SHIPPING_EXPERIENCES,
  644. Table::TYPE_TEXT,
  645. null,
  646. ['nullable' => false],
  647. 'Shipping Experiences'
  648. );
  649. $table->addColumn(
  650. QuotePickupLocationInterface::SELECTED,
  651. Table::TYPE_SMALLINT,
  652. null,
  653. ['unsigned' => true, 'nullable' => false, 'default' => 0],
  654. 'Is Selected'
  655. );
  656. $table->addForeignKey(
  657. $installer->getFkName(
  658. self::TABLE_QUOTE_PICKUP_LOCATION,
  659. QuotePickupLocationInterface::RECIPIENT_ADDRESS_ID,
  660. self::TABLE_PICKUP_LOCATION_SEARCH,
  661. PickupLocationSearchRequestInterface::SHIPPING_ADDRESS_ID
  662. ),
  663. QuotePickupLocationInterface::RECIPIENT_ADDRESS_ID,
  664. $installer->getTable(self::TABLE_PICKUP_LOCATION_SEARCH, self::CHECKOUT_CONNECTION_NAME),
  665. PickupLocationSearchRequestInterface::SHIPPING_ADDRESS_ID,
  666. Table::ACTION_CASCADE
  667. );
  668. $table->setComment('Quote Pickup Location Entity');
  669. $installer->getConnection(self::CHECKOUT_CONNECTION_NAME)->createTable($table);
  670. }
  671. /**
  672. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  673. *
  674. * @return void
  675. * @throws \Zend_Db_Exception
  676. */
  677. public function createOrderPickupLocationTable(SchemaSetupInterface $installer)
  678. {
  679. $table = $installer->getConnection(self::SALES_CONNECTION_NAME)->newTable(
  680. $installer->getTable(self::TABLE_ORDER_PICKUP_LOCATION, self::SALES_CONNECTION_NAME)
  681. );
  682. $table->addColumn(
  683. OrderPickupLocationInterface::RECIPIENT_ADDRESS_ID,
  684. Table::TYPE_INTEGER,
  685. null,
  686. ['unsigned' => true, 'nullable' => false, 'primary' => true],
  687. 'Entity Id'
  688. );
  689. $table->addColumn(
  690. OrderPickupLocationInterface::PICKUP_LOCATION_ID,
  691. Table::TYPE_TEXT,
  692. 64,
  693. ['nullable' => false],
  694. 'Pickup Location Id'
  695. );
  696. $table->addColumn(
  697. OrderPickupLocationInterface::NAME,
  698. Table::TYPE_TEXT,
  699. 255,
  700. [],
  701. 'Name'
  702. );
  703. $table->addColumn(
  704. OrderPickupLocationInterface::COUNTRY,
  705. Table::TYPE_TEXT,
  706. 2,
  707. ['nullable' => false],
  708. 'Country Code'
  709. );
  710. $table->addColumn(
  711. OrderPickupLocationInterface::REGION,
  712. Table::TYPE_TEXT,
  713. 255,
  714. ['nullable' => false],
  715. 'Region'
  716. );
  717. $table->addColumn(
  718. OrderPickupLocationInterface::POSTCODE,
  719. Table::TYPE_TEXT,
  720. 255,
  721. ['nullable' => false],
  722. 'Zip/Postal Code'
  723. );
  724. $table->addColumn(
  725. OrderPickupLocationInterface::CITY,
  726. Table::TYPE_TEXT,
  727. 255,
  728. ['nullable' => false],
  729. 'City'
  730. );
  731. $table->addColumn(
  732. OrderPickupLocationInterface::STREET,
  733. Table::TYPE_TEXT,
  734. null,
  735. ['nullable' => false],
  736. 'Street'
  737. );
  738. $table->addForeignKey(
  739. $installer->getFkName(
  740. self::TABLE_ORDER_PICKUP_LOCATION,
  741. OrderPickupLocationInterface::RECIPIENT_ADDRESS_ID,
  742. 'sales_order_address',
  743. 'entity_id'
  744. ),
  745. OrderPickupLocationInterface::RECIPIENT_ADDRESS_ID,
  746. $installer->getTable('sales_order_address', self::SALES_CONNECTION_NAME),
  747. 'entity_id',
  748. Table::ACTION_CASCADE
  749. );
  750. $table->setComment('Order Pickup Location Entity');
  751. $installer->getConnection(self::SALES_CONNECTION_NAME)->createTable($table);
  752. }
  753. /**
  754. * Add distance property to delivery location tables.
  755. *
  756. * @param SchemaSetupInterface|\Magento\Framework\Module\Setup $installer
  757. * @return void
  758. */
  759. public function addDeliveryLocationDistanceColumn(SchemaSetupInterface $installer)
  760. {
  761. $tableName = $installer->getTable(self::TABLE_QUOTE_COLLECTION_POINT, self::CHECKOUT_CONNECTION_NAME);
  762. $installer
  763. ->getConnection(self::CHECKOUT_CONNECTION_NAME)
  764. ->addColumn(
  765. $tableName,
  766. QuoteCollectionPointInterface::DISTANCE,
  767. [
  768. 'type' => Table::TYPE_INTEGER,
  769. 'unsigned' => true,
  770. 'nullable' => true,
  771. 'comment' => 'Distance in Meters'
  772. ]
  773. );
  774. $tableName = $installer->getTable(self::TABLE_QUOTE_PICKUP_LOCATION, self::CHECKOUT_CONNECTION_NAME);
  775. $installer
  776. ->getConnection(self::CHECKOUT_CONNECTION_NAME)
  777. ->addColumn(
  778. $tableName,
  779. QuotePickupLocationInterface::DISTANCE,
  780. [
  781. 'type' => Table::TYPE_INTEGER,
  782. 'unsigned' => true,
  783. 'nullable' => true,
  784. 'comment' => 'Distance in Meters'
  785. ]
  786. );
  787. }
  788. }