AddNonSpecifiedGenderAttributeOption.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 AddNonSpecifiedGenderAttributeOption
  26. * @package Magento\Customer\Setup\Patch
  27. */
  28. class AddNonSpecifiedGenderAttributeOption implements DataPatchInterface, PatchVersionInterface
  29. {
  30. /**
  31. * @var ModuleDataSetupInterface
  32. */
  33. private $moduleDataSetup;
  34. /**
  35. * @var CustomerSetupFactory
  36. */
  37. private $customerSetupFactory;
  38. /**
  39. * AddNonSpecifiedGenderAttributeOption 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. $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
  56. $entityTypeId = $customerSetup->getEntityTypeId(Customer::ENTITY);
  57. $attributeId = $customerSetup->getAttributeId($entityTypeId, 'gender');
  58. $option = ['attribute_id' => $attributeId, 'values' => [3 => 'Not Specified']];
  59. $customerSetup->addAttributeOption($option);
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public static function getDependencies()
  65. {
  66. return [
  67. UpdateCustomerAttributesMetadata::class,
  68. ];
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. public static function getVersion()
  74. {
  75. return '2.0.2';
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function getAliases()
  81. {
  82. return [];
  83. }
  84. }