Skip to content
Snippets Groups Projects
Commit eecf8501 authored by Oleksandr Karpenko's avatar Oleksandr Karpenko
Browse files

MAGETWO-50996: Some Customer data was removed after creating offline order

parent 76d181f0
Branches
No related merge requests found
......@@ -1560,11 +1560,13 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
{
$customer = $this->getQuote()->getCustomer();
$form = $this->_createCustomerForm($customer);
$customerData = $this->customerMapper->toFlatArray($customer);
// emulate request
$request = $form->prepareRequest($accountData);
$data = $form->extractData($request);
$data = $form->restoreData($data);
$data = array_merge($customerData, array_filter($data));
$customer = $this->customerFactory->create();
$this->dataObjectHelper->populateWithArray(
$customer,
......@@ -1574,7 +1576,6 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
$this->getQuote()->updateCustomerData($customer);
$data = [];
$customerData = $this->customerMapper->toFlatArray($customer);
foreach ($form->getAttributes() as $attribute) {
$code = sprintf('customer_%s', $attribute->getAttributeCode());
$data[$code] = isset($customerData[$attribute->getAttributeCode()])
......
......@@ -76,6 +76,11 @@ class CreateTest extends \PHPUnit_Framework_TestCase
*/
protected $accountManagementMock;
/**
* @var \Magento\Framework\Api\DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject
*/
protected $dataObjectHelper;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
......@@ -171,6 +176,9 @@ class CreateTest extends \PHPUnit_Framework_TestCase
'',
false
);
$this->dataObjectHelper = $this->getMockBuilder('Magento\Framework\Api\DataObjectHelper')
->disableOriginalConstructor()
->getMock();
$objectManagerHelper = new ObjectManagerHelper($this);
$this->adminOrderCreate = $objectManagerHelper->getObject(
......@@ -195,6 +203,7 @@ class CreateTest extends \PHPUnit_Framework_TestCase
'customerMapper' => $this->customerMapper,
'objectFactory' => $this->objectFactory,
'accountManagement' => $this->accountManagementMock,
'dataObjectHelper' => $this->dataObjectHelper,
]
);
}
......@@ -242,8 +251,11 @@ class CreateTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($this->getMock('Magento\Framework\App\RequestInterface')));
$customerMock = $this->getMock('Magento\Customer\Api\Data\CustomerInterface', [], [], '', false);
$this->customerMapper->expects($this->any())->method('toFlatArray')
->will($this->returnValue(['email' => 'user@example.com', 'group_id' => 1]));
$this->customerMapper->expects($this->atLeastOnce())
->method('toFlatArray')
->willReturn(['email' => 'user@example.com', 'group_id' => 1, 'gender' => 1]);
$quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false);
$quoteMock->expects($this->any())->method('getCustomer')->will($this->returnValue($customerMock));
$quoteMock->expects($this->once())
......@@ -255,6 +267,13 @@ class CreateTest extends \PHPUnit_Framework_TestCase
'customer_tax_class_id' => $taxClassId
]
);
$this->dataObjectHelper->expects($this->once())
->method('populateWithArray')
->with(
$customerMock,
['email' => 'user@example.com', 'group_id' => 1, 'gender' => 1],
'\Magento\Customer\Api\Data\CustomerInterface'
);
$this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerFormMock));
$this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock));
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment