55 */
66namespace Magento \CustomerSampleData \Model ;
77
8+ use Magento \Customer \Api \CustomerMetadataInterface ;
89use Magento \Customer \Api \Data \RegionInterface ;
910use Magento \Framework \Serialize \Serializer \Json ;
1011use Magento \Framework \Setup \SampleData \Context as SampleDataContext ;
@@ -79,6 +80,11 @@ class Customer
7980 */
8081 private $ serializer ;
8182
83+ /**
84+ * @var CustomerMetadataInterface
85+ */
86+ private $ customerMetadata ;
87+
8288 /**
8389 * @param SampleDataContext $sampleDataContext
8490 * @param \Magento\Directory\Model\CountryFactory $countryFactory
@@ -89,7 +95,8 @@ class Customer
8995 * @param \Magento\Store\Model\StoreManagerInterface $storeManager
9096 * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
9197 * @param \Magento\Framework\App\State $appState
92- * @param Json|null $serializer
98+ * @param Json $serializer
99+ * @param CustomerMetadataInterface $customerMetadata
93100 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
94101 */
95102 public function __construct (
@@ -102,7 +109,8 @@ public function __construct(
102109 \Magento \Store \Model \StoreManagerInterface $ storeManager ,
103110 \Magento \Framework \Api \DataObjectHelper $ dataObjectHelper ,
104111 \Magento \Framework \App \State $ appState ,
105- Json $ serializer = null
112+ Json $ serializer ,
113+ CustomerMetadataInterface $ customerMetadata
106114 ) {
107115 $ this ->fixtureManager = $ sampleDataContext ->getFixtureManager ();
108116 $ this ->csvReader = $ sampleDataContext ->getCsvReader ();
@@ -114,7 +122,8 @@ public function __construct(
114122 $ this ->storeManager = $ storeManager ;
115123 $ this ->dataObjectHelper = $ dataObjectHelper ;
116124 $ this ->appState = $ appState ;
117- $ this ->serializer = $ serializer ?: \Magento \Framework \App \ObjectManager::getInstance ()->get (Json::class);
125+ $ this ->serializer = $ serializer ;
126+ $ this ->customerMetadata = $ customerMetadata ;
118127 }
119128
120129 /**
@@ -246,14 +255,25 @@ protected function getDefaultCustomerAddress()
246255 */
247256 protected function convertRowData ($ row , $ data )
248257 {
258+ $ genders = [];
259+ $ genderAttr = $ this ->customerMetadata ->getAttributeMetadata ('gender ' );
260+ foreach ($ genderAttr ->getOptions () as $ genderOption ) {
261+ $ genders [$ genderOption ->getValue ()] = $ genderOption ->getLabel ();
262+ }
263+
249264 foreach ($ row as $ field => $ value ) {
250265 if (isset ($ data [$ field ])) {
251- if ($ field == 'street ' ) {
252- $ data [$ field ] = $ this ->serializer ->unserialize ($ value );
266+ if ($ field === 'password ' ) {
253267 continue ;
254268 }
255- if ($ field == 'password ' ) {
256- continue ;
269+
270+ switch ($ field ) {
271+ case 'street ' :
272+ $ value = $ this ->serializer ->unserialize ($ value );
273+ break ;
274+ case 'gender ' :
275+ $ value = array_search ($ value , $ genders );
276+ break ;
257277 }
258278 $ data [$ field ] = $ value ;
259279 }
0 commit comments