Skip to content

Commit 780e91d

Browse files
committed
MAGETWO-90801: Can't create customer account on checkout success page when gender field is required
1 parent 283a799 commit 780e91d

File tree

5 files changed

+17
-48
lines changed

5 files changed

+17
-48
lines changed

app/code/Magento/Customer/Model/Delegation/Storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function consumeNewOperation()
120120
$this->logger->error($exception);
121121
$serialized = null;
122122
}
123-
if (!$serialized) {
123+
if ($serialized === null) {
124124
return null;
125125
}
126126

app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Customer\Model\ResourceModel;
88

99
use Magento\Customer\Api\CustomerMetadataInterface;
10+
use Magento\Customer\Api\Data\CustomerInterface;
1011
use Magento\Customer\Model\Delegation\Data\NewOperation;
1112
use Magento\Customer\Model\Customer\NotificationStorage;
1213
use Magento\Framework\Api\DataObjectHelper;
@@ -163,13 +164,11 @@ public function __construct(
163164
* {@inheritdoc}
164165
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
165166
* @SuppressWarnings(PHPMD.NPathComplexity)
166-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
167167
*/
168-
public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $passwordHash = null)
168+
public function save(CustomerInterface $customer, $passwordHash = null)
169169
{
170170
/** @var NewOperation|null $delegatedNewOperation */
171-
$delegatedNewOperation = !$customer->getId()
172-
? $this->delegatedStorage->consumeNewOperation() : null;
171+
$delegatedNewOperation = !$customer->getId() ? $this->delegatedStorage->consumeNewOperation() : null;
173172
$prevCustomerData = null;
174173
$prevCustomerDataArr = null;
175174
if ($customer->getId()) {
@@ -183,72 +182,48 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
183182
CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER,
184183
$prevCustomerData
185184
);
186-
187185
$origAddresses = $customer->getAddresses();
188186
$customer->setAddresses([]);
189-
$customerData = $this->extensibleDataObjectConverter->toNestedArray(
190-
$customer,
191-
[],
192-
\Magento\Customer\Api\Data\CustomerInterface::class
193-
);
194-
187+
$customerData = $this->extensibleDataObjectConverter->toNestedArray($customer, [], CustomerInterface::class);
195188
$customer->setAddresses($origAddresses);
196189
/** @var Customer $customerModel */
197-
$customerModel = $this->customerFactory->create(
198-
['data' => $customerData]
199-
);
200-
//Model's actual ID field maybe different than "id"
201-
//so "id" field from $customerData may be ignored.
190+
$customerModel = $this->customerFactory->create(['data' => $customerData]);
191+
//Model's actual ID field maybe different than "id" so "id" field from $customerData may be ignored.
202192
$customerModel->setId($customer->getId());
203-
204193
$storeId = $customerModel->getStoreId();
205194
if ($storeId === null) {
206195
$customerModel->setStoreId($this->storeManager->getStore()->getId());
207196
}
208-
209197
// Need to use attribute set or future updates can cause data loss
210198
if (!$customerModel->getAttributeSetId()) {
211-
$customerModel->setAttributeSetId(
212-
\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER
213-
);
199+
$customerModel->setAttributeSetId(CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER);
214200
}
215201
$this->populateCustomerWithSecureData($customerModel, $passwordHash);
216-
217202
// If customer email was changed, reset RpToken info
218-
if ($prevCustomerData
219-
&& $prevCustomerData->getEmail() !== $customerModel->getEmail()
220-
) {
203+
if ($prevCustomerData && $prevCustomerData->getEmail() !== $customerModel->getEmail()) {
221204
$customerModel->setRpToken(null);
222205
$customerModel->setRpTokenCreatedAt(null);
223206
}
224207
if (!array_key_exists('default_billing', $customerArr)
225208
&& null !== $prevCustomerDataArr
226209
&& array_key_exists('default_billing', $prevCustomerDataArr)
227210
) {
228-
$customerModel->setDefaultBilling(
229-
$prevCustomerDataArr['default_billing']
230-
);
211+
$customerModel->setDefaultBilling($prevCustomerDataArr['default_billing']);
231212
}
232213
if (!array_key_exists('default_shipping', $customerArr)
233214
&& null !== $prevCustomerDataArr
234215
&& array_key_exists('default_shipping', $prevCustomerDataArr)
235216
) {
236-
$customerModel->setDefaultShipping(
237-
$prevCustomerDataArr['default_shipping']
238-
);
217+
$customerModel->setDefaultShipping($prevCustomerDataArr['default_shipping']);
239218
}
240-
241219
$customerModel->save();
242220
$this->customerRegistry->push($customerModel);
243221
$customerId = $customerModel->getId();
244-
245222
if (!$customer->getAddresses()
246223
&& $delegatedNewOperation
247224
&& $delegatedNewOperation->getCustomer()->getAddresses()
248225
) {
249-
$customer->setAddresses(
250-
$delegatedNewOperation->getCustomer()->getAddresses()
251-
);
226+
$customer->setAddresses($delegatedNewOperation->getCustomer()->getAddresses());
252227
}
253228
if ($customer->getAddresses() !== null) {
254229
if ($customer->getId()) {
@@ -260,7 +235,6 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
260235
} else {
261236
$existingAddressIds = [];
262237
}
263-
264238
$savedAddressIds = [];
265239
foreach ($customer->getAddresses() as $address) {
266240
$address->setCustomerId($customerId)
@@ -270,22 +244,19 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
270244
$savedAddressIds[] = $address->getId();
271245
}
272246
}
273-
274247
$addressIdsToDelete = array_diff($existingAddressIds, $savedAddressIds);
275248
foreach ($addressIdsToDelete as $addressId) {
276249
$this->addressRepository->deleteById($addressId);
277250
}
278251
}
279252
$this->customerRegistry->remove($customerId);
280253
$savedCustomer = $this->get($customer->getEmail(), $customer->getWebsiteId());
281-
282254
$this->eventManager->dispatch(
283255
'customer_save_after_data_object',
284256
[
285257
'customer_data_object' => $savedCustomer,
286258
'orig_customer_data_object' => $prevCustomerData,
287-
'delegate_data' => $delegatedNewOperation
288-
? $delegatedNewOperation->getAdditionalData() : []
259+
'delegate_data' => $delegatedNewOperation ? $delegatedNewOperation->getAdditionalData() : [],
289260
]
290261
);
291262

@@ -350,7 +321,7 @@ public function getList(SearchCriteriaInterface $searchCriteria)
350321
$collection = $this->customerFactory->create()->getCollection();
351322
$this->extensionAttributesJoinProcessor->process(
352323
$collection,
353-
\Magento\Customer\Api\Data\CustomerInterface::class
324+
CustomerInterface::class
354325
);
355326
// This is needed to make sure all the attributes are properly loaded
356327
foreach ($this->customerMetadata->getAllAttributesMetadata() as $metadata) {
@@ -382,7 +353,7 @@ public function getList(SearchCriteriaInterface $searchCriteria)
382353
/**
383354
* {@inheritdoc}
384355
*/
385-
public function delete(\Magento\Customer\Api\Data\CustomerInterface $customer)
356+
public function delete(CustomerInterface $customer)
386357
{
387358
return $this->deleteById($customer->getId());
388359
}

dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@
116116
<constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" />
117117
</variation>
118118
<variation name="CreateSalesRuleEntityTestVariation5">
119-
<data name="issue" xsi:type="string">MAGETWO-89831: Unstable FAT: Magento\SalesRule\Test\TestCase\CreateSalesRuleEntityTest</data>
120-
<data name="tag" xsi:type="string">stable:no</data>
121119
<data name="address/data/country_id" xsi:type="string">United States</data>
122120
<data name="address/data/region_id" xsi:type="string">California</data>
123121
<data name="address/data/postcode" xsi:type="string">95814</data>

dev/tests/functional/tests/app/Magento/Shipping/Test/TestCase/TrackingShipmentForPlacedOrderTest.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
99
<testCase name="Magento\Shipping\Test\TestCase\TrackingShipmentForPlacedOrderTest" summary="Create shipment for order.">
1010
<variation name="TrackingShipmentForPlacedOrderTestVariation1" summary="Creating shipment for order placed within Flat Rate." ticketId="MAGETWO-65163">
11-
<data name="issue" xsi:type="string">MAGETWO-89858: Unstable FAT: Magento\Shipping\Test\TestCase\TrackingShipmentForPlacedOrderTest</data>
12-
<data name="tag" xsi:type="string">stable:no</data>
1311
<data name="products/0" xsi:type="string">catalogProductSimple::product_10_dollar</data>
1412
<data name="customer/dataset" xsi:type="string">default</data>
1513
<data name="shippingAddress/dataset" xsi:type="string">US_address_1_without_email</data>

dev/tests/integration/testsuite/Magento/Sales/Api/OrderCustomerDelegateInterfaceTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use PHPUnit\Framework\TestCase;
1919

2020
/**
21+
* Test for Magento\Sales\Api\OrderCustomerDelegateInterface class.
22+
*
2123
* @magentoAppIsolation enabled
2224
*/
2325
class OrderCustomerDelegateInterfaceTest extends TestCase

0 commit comments

Comments
 (0)