PrepareInitialCheckoutConfiguration.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Setup\Patch\Data;
  7. use Magento\Eav\Setup\EavSetup;
  8. use Magento\Eav\Setup\EavSetupFactory;
  9. use Magento\Framework\App\ResourceConnection;
  10. use Magento\Framework\Setup\ModuleDataSetupInterface;
  11. use Magento\Framework\Setup\Patch\DataPatchInterface;
  12. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  13. /**
  14. * Class PrepareInitialCheckoutConfiguration
  15. * @package Magento\Checkout\Setup\Patch
  16. */
  17. class PrepareInitialCheckoutConfiguration implements DataPatchInterface, PatchVersionInterface
  18. {
  19. /**
  20. * @var ModuleDataSetupInterface
  21. */
  22. private $moduleDataSetup;
  23. /**
  24. * @var EavSetupFactory
  25. */
  26. private $eavSetupFactory;
  27. /**
  28. * @var \Magento\Customer\Helper\Address
  29. */
  30. private $customerAddress;
  31. /**
  32. * PatchInitial constructor.
  33. * @param ModuleDataSetupInterface $moduleDataSetup
  34. */
  35. public function __construct(
  36. ModuleDataSetupInterface $moduleDataSetup,
  37. EavSetupFactory $eavSetupFactory,
  38. \Magento\Customer\Helper\Address $customerAddress
  39. ) {
  40. $this->moduleDataSetup = $moduleDataSetup;
  41. $this->eavSetupFactory = $eavSetupFactory;
  42. $this->customerAddress = $customerAddress;
  43. }
  44. /**
  45. * {@inheritdoc}
  46. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  47. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  48. * @SuppressWarnings(PHPMD.NPathComplexity)
  49. */
  50. public function apply()
  51. {
  52. /** @var EavSetup $eavSetup */
  53. $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
  54. $this->moduleDataSetup->getConnection()->startSetup();
  55. $connection = $this->moduleDataSetup->getConnection();
  56. $select = $connection->select()->from(
  57. $this->moduleDataSetup->getTable('core_config_data'),
  58. 'COUNT(*)'
  59. )->where(
  60. 'path=?',
  61. 'customer/address/prefix_show'
  62. )->where(
  63. 'value NOT LIKE ?',
  64. '0'
  65. );
  66. $showPrefix = (bool)$this->customerAddress->getConfig('prefix_show')
  67. || $connection->fetchOne($select) > 0;
  68. $select = $connection->select()->from(
  69. $this->moduleDataSetup->getTable('core_config_data'),
  70. 'COUNT(*)'
  71. )->where(
  72. 'path=?',
  73. 'customer/address/middlename_show'
  74. )->where(
  75. 'value NOT LIKE ?',
  76. '0'
  77. );
  78. $showMiddlename = (bool)$this->customerAddress->getConfig('middlename_show')
  79. || $connection->fetchOne($select) > 0;
  80. $select = $connection->select()->from(
  81. $this->moduleDataSetup->getTable('core_config_data'),
  82. 'COUNT(*)'
  83. )->where(
  84. 'path=?',
  85. 'customer/address/suffix_show'
  86. )->where(
  87. 'value NOT LIKE ?',
  88. '0'
  89. );
  90. $showSuffix = (bool)$this->customerAddress->getConfig('suffix_show')
  91. || $connection->fetchOne($select) > 0;
  92. $select = $connection->select()->from(
  93. $this->moduleDataSetup->getTable('core_config_data'),
  94. 'COUNT(*)'
  95. )->where(
  96. 'path=?',
  97. 'customer/address/dob_show'
  98. )->where(
  99. 'value NOT LIKE ?',
  100. '0'
  101. );
  102. $showDob = (bool)$this->customerAddress->getConfig('dob_show')
  103. || $connection->fetchOne($select) > 0;
  104. $select = $connection->select()->from(
  105. $this->moduleDataSetup->getTable('core_config_data'),
  106. 'COUNT(*)'
  107. )->where(
  108. 'path=?',
  109. 'customer/address/taxvat_show'
  110. )->where(
  111. 'value NOT LIKE ?',
  112. '0'
  113. );
  114. $showTaxVat = (bool)$this->customerAddress->getConfig('taxvat_show')
  115. || $connection->fetchOne($select) > 0;
  116. $customerEntityTypeId = $eavSetup->getEntityTypeId('customer');
  117. $addressEntityTypeId = $eavSetup->getEntityTypeId('customer_address');
  118. /**
  119. *****************************************************************************
  120. * checkout/onepage/register
  121. *****************************************************************************
  122. */
  123. $connection->insert(
  124. $this->moduleDataSetup->getTable('eav_form_type'),
  125. [
  126. 'code' => 'checkout_onepage_register',
  127. 'label' => 'checkout_onepage_register',
  128. 'is_system' => 1,
  129. 'theme' => '',
  130. 'store_id' => 0
  131. ]
  132. );
  133. $formTypeId = $connection->lastInsertId($this->moduleDataSetup->getTable('eav_form_type'));
  134. $connection->insert(
  135. $this->moduleDataSetup->getTable('eav_form_type_entity'),
  136. ['type_id' => $formTypeId, 'entity_type_id' => $customerEntityTypeId]
  137. );
  138. $connection->insert(
  139. $this->moduleDataSetup->getTable('eav_form_type_entity'),
  140. ['type_id' => $formTypeId, 'entity_type_id' => $addressEntityTypeId]
  141. );
  142. $elementSort = 0;
  143. if ($showPrefix) {
  144. $connection->insert(
  145. $this->moduleDataSetup->getTable('eav_form_element'),
  146. [
  147. 'type_id' => $formTypeId,
  148. 'fieldset_id' => null,
  149. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'prefix'),
  150. 'sort_order' => $elementSort++
  151. ]
  152. );
  153. }
  154. $connection->insert(
  155. $this->moduleDataSetup->getTable('eav_form_element'),
  156. [
  157. 'type_id' => $formTypeId,
  158. 'fieldset_id' => null,
  159. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'firstname'),
  160. 'sort_order' => $elementSort++
  161. ]
  162. );
  163. if ($showMiddlename) {
  164. $connection->insert(
  165. $this->moduleDataSetup->getTable('eav_form_element'),
  166. [
  167. 'type_id' => $formTypeId,
  168. 'fieldset_id' => null,
  169. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'middlename'),
  170. 'sort_order' => $elementSort++
  171. ]
  172. );
  173. }
  174. $connection->insert(
  175. $this->moduleDataSetup->getTable('eav_form_element'),
  176. [
  177. 'type_id' => $formTypeId,
  178. 'fieldset_id' => null,
  179. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'lastname'),
  180. 'sort_order' => $elementSort++
  181. ]
  182. );
  183. if ($showSuffix) {
  184. $connection->insert(
  185. $this->moduleDataSetup->getTable('eav_form_element'),
  186. [
  187. 'type_id' => $formTypeId,
  188. 'fieldset_id' => null,
  189. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'suffix'),
  190. 'sort_order' => $elementSort++
  191. ]
  192. );
  193. }
  194. $connection->insert(
  195. $this->moduleDataSetup->getTable('eav_form_element'),
  196. [
  197. 'type_id' => $formTypeId,
  198. 'fieldset_id' => null,
  199. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'company'),
  200. 'sort_order' => $elementSort++
  201. ]
  202. );
  203. $connection->insert(
  204. $this->moduleDataSetup->getTable('eav_form_element'),
  205. [
  206. 'type_id' => $formTypeId,
  207. 'fieldset_id' => null,
  208. 'attribute_id' => $eavSetup->getAttributeId($customerEntityTypeId, 'email'),
  209. 'sort_order' => $elementSort++
  210. ]
  211. );
  212. $connection->insert(
  213. $this->moduleDataSetup->getTable('eav_form_element'),
  214. [
  215. 'type_id' => $formTypeId,
  216. 'fieldset_id' => null,
  217. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'street'),
  218. 'sort_order' => $elementSort++
  219. ]
  220. );
  221. $connection->insert(
  222. $this->moduleDataSetup->getTable('eav_form_element'),
  223. [
  224. 'type_id' => $formTypeId,
  225. 'fieldset_id' => null,
  226. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'city'),
  227. 'sort_order' => $elementSort++
  228. ]
  229. );
  230. $connection->insert(
  231. $this->moduleDataSetup->getTable('eav_form_element'),
  232. [
  233. 'type_id' => $formTypeId,
  234. 'fieldset_id' => null,
  235. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'region'),
  236. 'sort_order' => $elementSort++
  237. ]
  238. );
  239. $connection->insert(
  240. $this->moduleDataSetup->getTable('eav_form_element'),
  241. [
  242. 'type_id' => $formTypeId,
  243. 'fieldset_id' => null,
  244. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'postcode'),
  245. 'sort_order' => $elementSort++
  246. ]
  247. );
  248. $connection->insert(
  249. $this->moduleDataSetup->getTable('eav_form_element'),
  250. [
  251. 'type_id' => $formTypeId,
  252. 'fieldset_id' => null,
  253. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'country_id'),
  254. 'sort_order' => $elementSort++
  255. ]
  256. );
  257. $connection->insert(
  258. $this->moduleDataSetup->getTable('eav_form_element'),
  259. [
  260. 'type_id' => $formTypeId,
  261. 'fieldset_id' => null,
  262. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'telephone'),
  263. 'sort_order' => $elementSort++
  264. ]
  265. );
  266. $connection->insert(
  267. $this->moduleDataSetup->getTable('eav_form_element'),
  268. [
  269. 'type_id' => $formTypeId,
  270. 'fieldset_id' => null,
  271. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'fax'),
  272. 'sort_order' => $elementSort++
  273. ]
  274. );
  275. if ($showDob) {
  276. $connection->insert(
  277. $this->moduleDataSetup->getTable('eav_form_element'),
  278. [
  279. 'type_id' => $formTypeId,
  280. 'fieldset_id' => null,
  281. 'attribute_id' => $eavSetup->getAttributeId($customerEntityTypeId, 'dob'),
  282. 'sort_order' => $elementSort++
  283. ]
  284. );
  285. }
  286. if ($showTaxVat) {
  287. $connection->insert(
  288. $this->moduleDataSetup->getTable('eav_form_element'),
  289. [
  290. 'type_id' => $formTypeId,
  291. 'fieldset_id' => null,
  292. 'attribute_id' => $eavSetup->getAttributeId($customerEntityTypeId, 'taxvat'),
  293. 'sort_order' => $elementSort++
  294. ]
  295. );
  296. }
  297. /**
  298. *****************************************************************************
  299. * checkout/onepage/register_guest
  300. *****************************************************************************
  301. */
  302. $connection->insert(
  303. $this->moduleDataSetup->getTable('eav_form_type'),
  304. [
  305. 'code' => 'checkout_onepage_register_guest',
  306. 'label' => 'checkout_onepage_register_guest',
  307. 'is_system' => 1,
  308. 'theme' => '',
  309. 'store_id' => 0
  310. ]
  311. );
  312. $formTypeId = $connection->lastInsertId($this->moduleDataSetup->getTable('eav_form_type'));
  313. $connection->insert(
  314. $this->moduleDataSetup->getTable('eav_form_type_entity'),
  315. ['type_id' => $formTypeId, 'entity_type_id' => $customerEntityTypeId]
  316. );
  317. $connection->insert(
  318. $this->moduleDataSetup->getTable('eav_form_type_entity'),
  319. ['type_id' => $formTypeId, 'entity_type_id' => $addressEntityTypeId]
  320. );
  321. $elementSort = 0;
  322. if ($showPrefix) {
  323. $connection->insert(
  324. $this->moduleDataSetup->getTable('eav_form_element'),
  325. [
  326. 'type_id' => $formTypeId,
  327. 'fieldset_id' => null,
  328. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'prefix'),
  329. 'sort_order' => $elementSort++
  330. ]
  331. );
  332. }
  333. $connection->insert(
  334. $this->moduleDataSetup->getTable('eav_form_element'),
  335. [
  336. 'type_id' => $formTypeId,
  337. 'fieldset_id' => null,
  338. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'firstname'),
  339. 'sort_order' => $elementSort++
  340. ]
  341. );
  342. if ($showMiddlename) {
  343. $connection->insert(
  344. $this->moduleDataSetup->getTable('eav_form_element'),
  345. [
  346. 'type_id' => $formTypeId,
  347. 'fieldset_id' => null,
  348. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'middlename'),
  349. 'sort_order' => $elementSort++
  350. ]
  351. );
  352. }
  353. $connection->insert(
  354. $this->moduleDataSetup->getTable('eav_form_element'),
  355. [
  356. 'type_id' => $formTypeId,
  357. 'fieldset_id' => null,
  358. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'lastname'),
  359. 'sort_order' => $elementSort++
  360. ]
  361. );
  362. if ($showSuffix) {
  363. $connection->insert(
  364. $this->moduleDataSetup->getTable('eav_form_element'),
  365. [
  366. 'type_id' => $formTypeId,
  367. 'fieldset_id' => null,
  368. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'suffix'),
  369. 'sort_order' => $elementSort++
  370. ]
  371. );
  372. }
  373. $connection->insert(
  374. $this->moduleDataSetup->getTable('eav_form_element'),
  375. [
  376. 'type_id' => $formTypeId,
  377. 'fieldset_id' => null,
  378. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'company'),
  379. 'sort_order' => $elementSort++
  380. ]
  381. );
  382. $connection->insert(
  383. $this->moduleDataSetup->getTable('eav_form_element'),
  384. [
  385. 'type_id' => $formTypeId,
  386. 'fieldset_id' => null,
  387. 'attribute_id' => $eavSetup->getAttributeId($customerEntityTypeId, 'email'),
  388. 'sort_order' => $elementSort++
  389. ]
  390. );
  391. $connection->insert(
  392. $this->moduleDataSetup->getTable('eav_form_element'),
  393. [
  394. 'type_id' => $formTypeId,
  395. 'fieldset_id' => null,
  396. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'street'),
  397. 'sort_order' => $elementSort++
  398. ]
  399. );
  400. $connection->insert(
  401. $this->moduleDataSetup->getTable('eav_form_element'),
  402. [
  403. 'type_id' => $formTypeId,
  404. 'fieldset_id' => null,
  405. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'city'),
  406. 'sort_order' => $elementSort++
  407. ]
  408. );
  409. $connection->insert(
  410. $this->moduleDataSetup->getTable('eav_form_element'),
  411. [
  412. 'type_id' => $formTypeId,
  413. 'fieldset_id' => null,
  414. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'region'),
  415. 'sort_order' => $elementSort++
  416. ]
  417. );
  418. $connection->insert(
  419. $this->moduleDataSetup->getTable('eav_form_element'),
  420. [
  421. 'type_id' => $formTypeId,
  422. 'fieldset_id' => null,
  423. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'postcode'),
  424. 'sort_order' => $elementSort++
  425. ]
  426. );
  427. $connection->insert(
  428. $this->moduleDataSetup->getTable('eav_form_element'),
  429. [
  430. 'type_id' => $formTypeId,
  431. 'fieldset_id' => null,
  432. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'country_id'),
  433. 'sort_order' => $elementSort++
  434. ]
  435. );
  436. $connection->insert(
  437. $this->moduleDataSetup->getTable('eav_form_element'),
  438. [
  439. 'type_id' => $formTypeId,
  440. 'fieldset_id' => null,
  441. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'telephone'),
  442. 'sort_order' => $elementSort++
  443. ]
  444. );
  445. $connection->insert(
  446. $this->moduleDataSetup->getTable('eav_form_element'),
  447. [
  448. 'type_id' => $formTypeId,
  449. 'fieldset_id' => null,
  450. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'fax'),
  451. 'sort_order' => $elementSort++
  452. ]
  453. );
  454. if ($showDob) {
  455. $connection->insert(
  456. $this->moduleDataSetup->getTable('eav_form_element'),
  457. [
  458. 'type_id' => $formTypeId,
  459. 'fieldset_id' => null,
  460. 'attribute_id' => $eavSetup->getAttributeId($customerEntityTypeId, 'dob'),
  461. 'sort_order' => $elementSort++
  462. ]
  463. );
  464. }
  465. if ($showTaxVat) {
  466. $connection->insert(
  467. $this->moduleDataSetup->getTable('eav_form_element'),
  468. [
  469. 'type_id' => $formTypeId,
  470. 'fieldset_id' => null,
  471. 'attribute_id' => $eavSetup->getAttributeId($customerEntityTypeId, 'taxvat'),
  472. 'sort_order' => $elementSort++
  473. ]
  474. );
  475. }
  476. /**
  477. *****************************************************************************
  478. * checkout/onepage/billing_address
  479. *****************************************************************************
  480. */
  481. $connection->insert(
  482. $this->moduleDataSetup->getTable('eav_form_type'),
  483. [
  484. 'code' => 'checkout_onepage_billing_address',
  485. 'label' => 'checkout_onepage_billing_address',
  486. 'is_system' => 1,
  487. 'theme' => '',
  488. 'store_id' => 0
  489. ]
  490. );
  491. $formTypeId = $connection->lastInsertId($this->moduleDataSetup->getTable('eav_form_type'));
  492. $connection->insert(
  493. $this->moduleDataSetup->getTable('eav_form_type_entity'),
  494. ['type_id' => $formTypeId, 'entity_type_id' => $addressEntityTypeId]
  495. );
  496. $elementSort = 0;
  497. if ($showPrefix) {
  498. $connection->insert(
  499. $this->moduleDataSetup->getTable('eav_form_element'),
  500. [
  501. 'type_id' => $formTypeId,
  502. 'fieldset_id' => null,
  503. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'prefix'),
  504. 'sort_order' => $elementSort++
  505. ]
  506. );
  507. }
  508. $connection->insert(
  509. $this->moduleDataSetup->getTable('eav_form_element'),
  510. [
  511. 'type_id' => $formTypeId,
  512. 'fieldset_id' => null,
  513. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'firstname'),
  514. 'sort_order' => $elementSort++
  515. ]
  516. );
  517. if ($showMiddlename) {
  518. $connection->insert(
  519. $this->moduleDataSetup->getTable('eav_form_element'),
  520. [
  521. 'type_id' => $formTypeId,
  522. 'fieldset_id' => null,
  523. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'middlename'),
  524. 'sort_order' => $elementSort++
  525. ]
  526. );
  527. }
  528. $connection->insert(
  529. $this->moduleDataSetup->getTable('eav_form_element'),
  530. [
  531. 'type_id' => $formTypeId,
  532. 'fieldset_id' => null,
  533. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'lastname'),
  534. 'sort_order' => $elementSort++
  535. ]
  536. );
  537. if ($showSuffix) {
  538. $connection->insert(
  539. $this->moduleDataSetup->getTable('eav_form_element'),
  540. [
  541. 'type_id' => $formTypeId,
  542. 'fieldset_id' => null,
  543. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'suffix'),
  544. 'sort_order' => $elementSort++
  545. ]
  546. );
  547. }
  548. $connection->insert(
  549. $this->moduleDataSetup->getTable('eav_form_element'),
  550. [
  551. 'type_id' => $formTypeId,
  552. 'fieldset_id' => null,
  553. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'company'),
  554. 'sort_order' => $elementSort++
  555. ]
  556. );
  557. $connection->insert(
  558. $this->moduleDataSetup->getTable('eav_form_element'),
  559. [
  560. 'type_id' => $formTypeId,
  561. 'fieldset_id' => null,
  562. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'street'),
  563. 'sort_order' => $elementSort++
  564. ]
  565. );
  566. $connection->insert(
  567. $this->moduleDataSetup->getTable('eav_form_element'),
  568. [
  569. 'type_id' => $formTypeId,
  570. 'fieldset_id' => null,
  571. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'city'),
  572. 'sort_order' => $elementSort++
  573. ]
  574. );
  575. $connection->insert(
  576. $this->moduleDataSetup->getTable('eav_form_element'),
  577. [
  578. 'type_id' => $formTypeId,
  579. 'fieldset_id' => null,
  580. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'region'),
  581. 'sort_order' => $elementSort++
  582. ]
  583. );
  584. $connection->insert(
  585. $this->moduleDataSetup->getTable('eav_form_element'),
  586. [
  587. 'type_id' => $formTypeId,
  588. 'fieldset_id' => null,
  589. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'postcode'),
  590. 'sort_order' => $elementSort++
  591. ]
  592. );
  593. $connection->insert(
  594. $this->moduleDataSetup->getTable('eav_form_element'),
  595. [
  596. 'type_id' => $formTypeId,
  597. 'fieldset_id' => null,
  598. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'country_id'),
  599. 'sort_order' => $elementSort++
  600. ]
  601. );
  602. $connection->insert(
  603. $this->moduleDataSetup->getTable('eav_form_element'),
  604. [
  605. 'type_id' => $formTypeId,
  606. 'fieldset_id' => null,
  607. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'telephone'),
  608. 'sort_order' => $elementSort++
  609. ]
  610. );
  611. $connection->insert(
  612. $this->moduleDataSetup->getTable('eav_form_element'),
  613. [
  614. 'type_id' => $formTypeId,
  615. 'fieldset_id' => null,
  616. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'fax'),
  617. 'sort_order' => $elementSort++
  618. ]
  619. );
  620. /**
  621. *****************************************************************************
  622. * checkout/onepage/shipping_address
  623. *****************************************************************************
  624. */
  625. $connection->insert(
  626. $this->moduleDataSetup->getTable('eav_form_type'),
  627. [
  628. 'code' => 'checkout_onepage_shipping_address',
  629. 'label' => 'checkout_onepage_shipping_address',
  630. 'is_system' => 1,
  631. 'theme' => '',
  632. 'store_id' => 0
  633. ]
  634. );
  635. $formTypeId = $connection->lastInsertId($this->moduleDataSetup->getTable('eav_form_type'));
  636. $connection->insert(
  637. $this->moduleDataSetup->getTable('eav_form_type_entity'),
  638. ['type_id' => $formTypeId, 'entity_type_id' => $addressEntityTypeId]
  639. );
  640. $elementSort = 0;
  641. if ($showPrefix) {
  642. $connection->insert(
  643. $this->moduleDataSetup->getTable('eav_form_element'),
  644. [
  645. 'type_id' => $formTypeId,
  646. 'fieldset_id' => null,
  647. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'prefix'),
  648. 'sort_order' => $elementSort++
  649. ]
  650. );
  651. }
  652. $connection->insert(
  653. $this->moduleDataSetup->getTable('eav_form_element'),
  654. [
  655. 'type_id' => $formTypeId,
  656. 'fieldset_id' => null,
  657. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'firstname'),
  658. 'sort_order' => $elementSort++
  659. ]
  660. );
  661. if ($showMiddlename) {
  662. $connection->insert(
  663. $this->moduleDataSetup->getTable('eav_form_element'),
  664. [
  665. 'type_id' => $formTypeId,
  666. 'fieldset_id' => null,
  667. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'middlename'),
  668. 'sort_order' => $elementSort++
  669. ]
  670. );
  671. }
  672. $connection->insert(
  673. $this->moduleDataSetup->getTable('eav_form_element'),
  674. [
  675. 'type_id' => $formTypeId,
  676. 'fieldset_id' => null,
  677. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'lastname'),
  678. 'sort_order' => $elementSort++
  679. ]
  680. );
  681. if ($showSuffix) {
  682. $connection->insert(
  683. $this->moduleDataSetup->getTable('eav_form_element'),
  684. [
  685. 'type_id' => $formTypeId,
  686. 'fieldset_id' => null,
  687. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'suffix'),
  688. 'sort_order' => $elementSort++
  689. ]
  690. );
  691. }
  692. $connection->insert(
  693. $this->moduleDataSetup->getTable('eav_form_element'),
  694. [
  695. 'type_id' => $formTypeId,
  696. 'fieldset_id' => null,
  697. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'company'),
  698. 'sort_order' => $elementSort++
  699. ]
  700. );
  701. $connection->insert(
  702. $this->moduleDataSetup->getTable('eav_form_element'),
  703. [
  704. 'type_id' => $formTypeId,
  705. 'fieldset_id' => null,
  706. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'street'),
  707. 'sort_order' => $elementSort++
  708. ]
  709. );
  710. $connection->insert(
  711. $this->moduleDataSetup->getTable('eav_form_element'),
  712. [
  713. 'type_id' => $formTypeId,
  714. 'fieldset_id' => null,
  715. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'city'),
  716. 'sort_order' => $elementSort++
  717. ]
  718. );
  719. $connection->insert(
  720. $this->moduleDataSetup->getTable('eav_form_element'),
  721. [
  722. 'type_id' => $formTypeId,
  723. 'fieldset_id' => null,
  724. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'region'),
  725. 'sort_order' => $elementSort++
  726. ]
  727. );
  728. $connection->insert(
  729. $this->moduleDataSetup->getTable('eav_form_element'),
  730. [
  731. 'type_id' => $formTypeId,
  732. 'fieldset_id' => null,
  733. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'postcode'),
  734. 'sort_order' => $elementSort++
  735. ]
  736. );
  737. $connection->insert(
  738. $this->moduleDataSetup->getTable('eav_form_element'),
  739. [
  740. 'type_id' => $formTypeId,
  741. 'fieldset_id' => null,
  742. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'country_id'),
  743. 'sort_order' => $elementSort++
  744. ]
  745. );
  746. $connection->insert(
  747. $this->moduleDataSetup->getTable('eav_form_element'),
  748. [
  749. 'type_id' => $formTypeId,
  750. 'fieldset_id' => null,
  751. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'telephone'),
  752. 'sort_order' => $elementSort++
  753. ]
  754. );
  755. $connection->insert(
  756. $this->moduleDataSetup->getTable('eav_form_element'),
  757. [
  758. 'type_id' => $formTypeId,
  759. 'fieldset_id' => null,
  760. 'attribute_id' => $eavSetup->getAttributeId($addressEntityTypeId, 'fax'),
  761. 'sort_order' => $elementSort++
  762. ]
  763. );
  764. $table = $this->moduleDataSetup->getTable('core_config_data');
  765. $select = $connection->select()->from(
  766. $table,
  767. ['config_id', 'value']
  768. )->where(
  769. 'path = ?',
  770. 'checkout/options/onepage_checkout_disabled'
  771. );
  772. $data = $connection->fetchAll($select);
  773. if ($data) {
  774. try {
  775. $connection->beginTransaction();
  776. foreach ($data as $value) {
  777. $bind = ['path' => 'checkout/options/onepage_checkout_enabled', 'value' => !(bool)$value['value']];
  778. $where = 'config_id = ' . $value['config_id'];
  779. $connection->update($table, $bind, $where);
  780. }
  781. $connection->commit();
  782. } catch (\Exception $e) {
  783. $connection->rollBack();
  784. throw $e;
  785. }
  786. }
  787. $connection->endSetup();
  788. }
  789. /**
  790. * {@inheritdoc}
  791. */
  792. public static function getDependencies()
  793. {
  794. return [];
  795. }
  796. /**
  797. * {@inheritdoc}
  798. */
  799. public static function getVersion()
  800. {
  801. return '2.0.0';
  802. }
  803. /**
  804. * {@inheritdoc}
  805. */
  806. public function getAliases()
  807. {
  808. return [];
  809. }
  810. }