Skip to content

Commit

Permalink
Merge branch '2.4-develop' of https://github.com/mage-os/mirror-magen…
Browse files Browse the repository at this point in the history
…to2-sample-data into 2.4-develop
  • Loading branch information
mage-os-ci committed Oct 4, 2023
2 parents e28844a + 8e8aa29 commit 07a063f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
34 changes: 27 additions & 7 deletions app/code/Magento/CustomerSampleData/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\CustomerSampleData\Model;

use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Customer\Api\Data\RegionInterface;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Setup\SampleData\Context as SampleDataContext;
Expand Down Expand Up @@ -79,6 +80,11 @@ class Customer
*/
private $serializer;

/**
* @var CustomerMetadataInterface
*/
private $customerMetadata;

/**
* @param SampleDataContext $sampleDataContext
* @param \Magento\Directory\Model\CountryFactory $countryFactory
Expand All @@ -89,7 +95,8 @@ class Customer
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
* @param \Magento\Framework\App\State $appState
* @param Json|null $serializer
* @param Json $serializer
* @param CustomerMetadataInterface $customerMetadata
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -102,7 +109,8 @@ public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
\Magento\Framework\App\State $appState,
Json $serializer = null
Json $serializer,
CustomerMetadataInterface $customerMetadata
) {
$this->fixtureManager = $sampleDataContext->getFixtureManager();
$this->csvReader = $sampleDataContext->getCsvReader();
Expand All @@ -114,7 +122,8 @@ public function __construct(
$this->storeManager = $storeManager;
$this->dataObjectHelper = $dataObjectHelper;
$this->appState = $appState;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class);
$this->serializer = $serializer;
$this->customerMetadata = $customerMetadata;
}

/**
Expand Down Expand Up @@ -246,14 +255,25 @@ protected function getDefaultCustomerAddress()
*/
protected function convertRowData($row, $data)
{
$genders = [];
$genderAttr = $this->customerMetadata->getAttributeMetadata('gender');
foreach ($genderAttr->getOptions() as $genderOption) {
$genders[$genderOption->getValue()] = $genderOption->getLabel();
}

foreach ($row as $field => $value) {
if (isset($data[$field])) {
if ($field == 'street') {
$data[$field] = $this->serializer->unserialize($value);
if ($field === 'password') {
continue;
}
if ($field == 'password') {
continue;

switch ($field) {
case 'street':
$value = $this->serializer->unserialize($value);
break;
case 'gender':
$value = array_search($value, $genders);
break;
}
$data[$field] = $value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
firstname,lastname,email,password,dob,gender,street,city,region,country_id,postcode,telephone
Veronica,Costello,"[email protected]","[email protected]","1973-12-15",2,"[""6146 Honey Bluff Parkway"",""""]",Calder,Michigan,US,"49628-7978","(555) 229-3326"
Veronica,Costello,"[email protected]","[email protected]","1973-12-15","Female","[""6146 Honey Bluff Parkway"",""""]",Calder,Michigan,US,"49628-7978","(555) 229-3326"

0 comments on commit 07a063f

Please sign in to comment.