RemoveCheckoutRegisterAndUpdateAttributes.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Setup\Patch\Data;
  7. use Magento\Customer\Model\Customer;
  8. use Magento\Customer\Setup\CustomerSetupFactory;
  9. use Magento\Directory\Model\AllowedCountries;
  10. use Magento\Framework\App\ObjectManager;
  11. use Magento\Framework\Encryption\Encryptor;
  12. use Magento\Framework\Indexer\IndexerRegistry;
  13. use Magento\Framework\Setup\SetupInterface;
  14. use Magento\Framework\Setup\UpgradeDataInterface;
  15. use Magento\Framework\Setup\ModuleContextInterface;
  16. use Magento\Framework\Setup\ModuleDataSetupInterface;
  17. use Magento\Store\Model\ScopeInterface;
  18. use Magento\Store\Model\StoreManagerInterface;
  19. use Magento\Framework\DB\FieldDataConverterFactory;
  20. use Magento\Framework\DB\DataConverter\SerializedToJson;
  21. use Magento\Framework\App\ResourceConnection;
  22. use Magento\Framework\Setup\Patch\DataPatchInterface;
  23. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  24. /**
  25. * Class RemoveCheckoutRegisterAndUpdateAttributes
  26. * @package Magento\Customer\Setup\Patch
  27. */
  28. class RemoveCheckoutRegisterAndUpdateAttributes implements DataPatchInterface, PatchVersionInterface
  29. {
  30. /**
  31. * @var ModuleDataSetupInterface
  32. */
  33. private $moduleDataSetup;
  34. /**
  35. * @var CustomerSetupFactory
  36. */
  37. private $customerSetupFactory;
  38. /**
  39. * RemoveCheckoutRegisterAndUpdateAttributes constructor.
  40. * @param ModuleDataSetupInterface $moduleDataSetup
  41. * @param CustomerSetupFactory $customerSetupFactory
  42. */
  43. public function __construct(
  44. ModuleDataSetupInterface $moduleDataSetup,
  45. CustomerSetupFactory $customerSetupFactory
  46. ) {
  47. $this->moduleDataSetup = $moduleDataSetup;
  48. $this->customerSetupFactory = $customerSetupFactory;
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function apply()
  54. {
  55. $this->moduleDataSetup->getConnection()->delete(
  56. $this->moduleDataSetup->getTable('customer_form_attribute'),
  57. ['form_code = ?' => 'checkout_register']
  58. );
  59. $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
  60. $customerSetup->updateEntityType(
  61. \Magento\Customer\Model\Customer::ENTITY,
  62. 'entity_model',
  63. \Magento\Customer\Model\ResourceModel\Customer::class
  64. );
  65. $customerSetup->updateEntityType(
  66. \Magento\Customer\Model\Customer::ENTITY,
  67. 'increment_model',
  68. \Magento\Eav\Model\Entity\Increment\NumericValue::class
  69. );
  70. $customerSetup->updateEntityType(
  71. \Magento\Customer\Model\Customer::ENTITY,
  72. 'entity_attribute_collection',
  73. \Magento\Customer\Model\ResourceModel\Attribute\Collection::class
  74. );
  75. $customerSetup->updateEntityType(
  76. 'customer_address',
  77. 'entity_model',
  78. \Magento\Customer\Model\ResourceModel\Address::class
  79. );
  80. $customerSetup->updateEntityType(
  81. 'customer_address',
  82. 'entity_attribute_collection',
  83. \Magento\Customer\Model\ResourceModel\Address\Attribute\Collection::class
  84. );
  85. $customerSetup->updateAttribute(
  86. 'customer_address',
  87. 'country_id',
  88. 'source_model',
  89. \Magento\Customer\Model\ResourceModel\Address\Attribute\Source\Country::class
  90. );
  91. $customerSetup->updateAttribute(
  92. 'customer_address',
  93. 'region',
  94. 'backend_model',
  95. \Magento\Customer\Model\ResourceModel\Address\Attribute\Backend\Region::class
  96. );
  97. $customerSetup->updateAttribute(
  98. 'customer_address',
  99. 'region_id',
  100. 'source_model',
  101. \Magento\Customer\Model\ResourceModel\Address\Attribute\Source\Region::class
  102. );
  103. }
  104. /**
  105. * {@inheritdoc}
  106. */
  107. public static function getDependencies()
  108. {
  109. return [
  110. UpgradePasswordHashAndAddress::class,
  111. ];
  112. }
  113. /**
  114. * {@inheritdoc}
  115. */
  116. public static function getVersion()
  117. {
  118. return '2.0.6';
  119. }
  120. /**
  121. * {@inheritdoc}
  122. */
  123. public function getAliases()
  124. {
  125. return [];
  126. }
  127. }