Skip to content

Commit fdb344c

Browse files
committed
ACP2E-2196: Unable to deploy Sample Data
1 parent 9eb0df3 commit fdb344c

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

app/code/Magento/CustomerSampleData/Model/Customer.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CustomerSampleData\Model;
77

8+
use Magento\Customer\Api\CustomerMetadataInterface;
89
use Magento\Customer\Api\Data\RegionInterface;
910
use Magento\Framework\Serialize\Serializer\Json;
1011
use 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
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
firstname,lastname,email,password,dob,gender,street,city,region,country_id,postcode,telephone
2-
Veronica,Costello,"[email protected]","[email protected]","1973-12-15",2,"[""6146 Honey Bluff Parkway"",""""]",Calder,Michigan,US,"49628-7978","(555) 229-3326"
2+
Veronica,Costello,"[email protected]","[email protected]","1973-12-15","Female","[""6146 Honey Bluff Parkway"",""""]",Calder,Michigan,US,"49628-7978","(555) 229-3326"

0 commit comments

Comments
 (0)