UpdateCustomerAttributesMetadata.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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\Setup\CustomerSetup;
  8. use Magento\Customer\Setup\CustomerSetupFactory;
  9. use Magento\Framework\Setup\ModuleDataSetupInterface;
  10. use Magento\Framework\Setup\Patch\DataPatchInterface;
  11. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  12. /**
  13. * Class UpdateCustomerAttributesMetadata
  14. * @package Magento\Customer\Setup\Patch
  15. */
  16. class UpdateCustomerAttributesMetadata implements DataPatchInterface, PatchVersionInterface
  17. {
  18. /**
  19. * @var ModuleDataSetupInterface
  20. */
  21. private $moduleDataSetup;
  22. /**
  23. * @var CustomerSetupFactory
  24. */
  25. private $customerSetupFactory;
  26. /**
  27. * UpdateCustomerAttributesMetadata constructor.
  28. * @param ModuleDataSetupInterface $moduleDataSetup
  29. * @param CustomerSetupFactory $customerSetupFactory
  30. */
  31. public function __construct(
  32. ModuleDataSetupInterface $moduleDataSetup,
  33. CustomerSetupFactory $customerSetupFactory
  34. ) {
  35. $this->moduleDataSetup = $moduleDataSetup;
  36. $this->customerSetupFactory = $customerSetupFactory;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function apply()
  42. {
  43. /** @var CustomerSetup $customerSetup */
  44. $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
  45. $this->updateCustomerAttributesMetadata($customerSetup);
  46. }
  47. /**
  48. * @param CustomerSetup $customerSetup
  49. * @return void
  50. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  51. */
  52. private function updateCustomerAttributesMetadata($customerSetup)
  53. {
  54. $entityAttributes = [
  55. 'customer' => [
  56. 'website_id' => [
  57. 'is_used_in_grid' => true,
  58. 'is_visible_in_grid' => true,
  59. 'is_filterable_in_grid' => true,
  60. 'is_searchable_in_grid' => false,
  61. ],
  62. 'created_in' => [
  63. 'is_used_in_grid' => true,
  64. 'is_visible_in_grid' => true,
  65. 'is_filterable_in_grid' => false,
  66. 'is_searchable_in_grid' => true,
  67. ],
  68. 'email' => [
  69. 'is_used_in_grid' => true,
  70. 'is_visible_in_grid' => true,
  71. 'is_filterable_in_grid' => true,
  72. 'is_searchable_in_grid' => true,
  73. ],
  74. 'group_id' => [
  75. 'is_used_in_grid' => true,
  76. 'is_visible_in_grid' => true,
  77. 'is_filterable_in_grid' => true,
  78. 'is_searchable_in_grid' => false,
  79. ],
  80. 'dob' => [
  81. 'is_used_in_grid' => true,
  82. 'is_visible_in_grid' => true,
  83. 'is_filterable_in_grid' => true,
  84. 'is_searchable_in_grid' => false,
  85. ],
  86. 'taxvat' => [
  87. 'is_used_in_grid' => true,
  88. 'is_visible_in_grid' => true,
  89. 'is_filterable_in_grid' => false,
  90. 'is_searchable_in_grid' => true,
  91. ],
  92. 'confirmation' => [
  93. 'is_used_in_grid' => true,
  94. 'is_visible_in_grid' => true,
  95. 'is_filterable_in_grid' => true,
  96. 'is_searchable_in_grid' => false,
  97. ],
  98. 'created_at' => [
  99. 'is_used_in_grid' => true,
  100. 'is_visible_in_grid' => true,
  101. 'is_filterable_in_grid' => true,
  102. 'is_searchable_in_grid' => false,
  103. ],
  104. 'gender' => [
  105. 'is_used_in_grid' => true,
  106. 'is_visible_in_grid' => true,
  107. 'is_filterable_in_grid' => true,
  108. 'is_searchable_in_grid' => false,
  109. ],
  110. ],
  111. 'customer_address' => [
  112. 'company' => [
  113. 'is_used_in_grid' => true,
  114. 'is_visible_in_grid' => false,
  115. 'is_filterable_in_grid' => false,
  116. 'is_searchable_in_grid' => true,
  117. ],
  118. 'street' => [
  119. 'is_used_in_grid' => true,
  120. 'is_visible_in_grid' => false,
  121. 'is_filterable_in_grid' => false,
  122. 'is_searchable_in_grid' => true,
  123. ],
  124. 'city' => [
  125. 'is_used_in_grid' => true,
  126. 'is_visible_in_grid' => false,
  127. 'is_filterable_in_grid' => false,
  128. 'is_searchable_in_grid' => true,
  129. ],
  130. 'country_id' => [
  131. 'is_used_in_grid' => true,
  132. 'is_visible_in_grid' => true,
  133. 'is_filterable_in_grid' => true,
  134. 'is_searchable_in_grid' => false,
  135. ],
  136. 'region' => [
  137. 'is_used_in_grid' => true,
  138. 'is_visible_in_grid' => true,
  139. 'is_filterable_in_grid' => false,
  140. 'is_searchable_in_grid' => true,
  141. ],
  142. 'region_id' => [
  143. 'is_used_in_grid' => true,
  144. 'is_visible_in_grid' => false,
  145. 'is_filterable_in_grid' => true,
  146. 'is_searchable_in_grid' => false,
  147. ],
  148. 'postcode' => [
  149. 'is_used_in_grid' => true,
  150. 'is_visible_in_grid' => true,
  151. 'is_filterable_in_grid' => true,
  152. 'is_searchable_in_grid' => true,
  153. ],
  154. 'telephone' => [
  155. 'is_used_in_grid' => true,
  156. 'is_visible_in_grid' => true,
  157. 'is_filterable_in_grid' => true,
  158. 'is_searchable_in_grid' => true,
  159. ],
  160. 'fax' => [
  161. 'is_used_in_grid' => true,
  162. 'is_visible_in_grid' => false,
  163. 'is_filterable_in_grid' => false,
  164. 'is_searchable_in_grid' => true,
  165. ],
  166. ],
  167. ];
  168. $customerSetup->upgradeAttributes($entityAttributes);
  169. }
  170. /**
  171. * {@inheritdoc}
  172. */
  173. public static function getDependencies()
  174. {
  175. return [
  176. DefaultCustomerGroupsAndAttributes::class,
  177. ];
  178. }
  179. /**
  180. * {@inheritdoc}
  181. */
  182. public static function getVersion()
  183. {
  184. return '2.0.1';
  185. }
  186. /**
  187. * {@inheritdoc}
  188. */
  189. public function getAliases()
  190. {
  191. return [];
  192. }
  193. }