diff --git a/vendor/magento/module-company/Model/CompanySuperUserGet.php b/vendor/magento/module-company/Model/CompanySuperUserGet.php index 68894fb1e9..6be15b5f7c 100644 --- a/vendor/magento/module-company/Model/CompanySuperUserGet.php +++ b/vendor/magento/module-company/Model/CompanySuperUserGet.php @@ -18,9 +18,12 @@ use Magento\Customer\Model\Metadata\Form; use Magento\Customer\Model\Metadata\FormFactory; use Magento\Framework\Api\DataObjectHelper; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Stdlib\DateTime\DateTime; /** * Creates or updates a company admin customer entity with given data during company save process in admin panel. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class CompanySuperUserGet { @@ -64,6 +67,11 @@ class CompanySuperUserGet */ private $customerMapper; + /** + * @var DateTime + */ + private $dateTime; + /** * @param CompanyAttributes $companyAttributes * @param CustomerRepositoryInterface $customerRepository @@ -73,6 +81,7 @@ class CompanySuperUserGet * @param CustomerRetriever $customerRetriever * @param FormFactory $customerFormFactory * @param Mapper $customerMapper + * @param DateTime $dateTime */ public function __construct( CompanyAttributes $companyAttributes, @@ -82,7 +91,8 @@ class CompanySuperUserGet AccountManagementInterface $accountManagement, CustomerRetriever $customerRetriever, FormFactory $customerFormFactory, - Mapper $customerMapper + Mapper $customerMapper, + DateTime $dateTime ) { $this->companyAttributes = $companyAttributes; $this->customerRepository = $customerRepository; @@ -92,6 +102,7 @@ class CompanySuperUserGet $this->customerRetriever = $customerRetriever; $this->customerFormFactory = $customerFormFactory; $this->customerMapper = $customerMapper; + $this->dateTime = $dateTime; } /** @@ -155,6 +166,10 @@ class CompanySuperUserGet if ($customer->getId()) { $customer = $this->customerRepository->save($customer); } else { + if (!$customer->getCreatedIn()) { + $createdAt = $this->dateTime->gmtDate('Y-m-d H:i:s'); + $customer->setCreatedAt($createdAt); + } $customer = $this->accountManagement->createAccountWithPasswordHash($customer, null); } @@ -196,7 +211,8 @@ class CompanySuperUserGet CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'adminhtml_customer', $attributeValues, - false + false, + Form::DONT_IGNORE_INVISIBLE ); } }