Skip to content

Commit 402e59e

Browse files
Stanislav Idolovisitnikov
authored andcommitted
MAGETWO-50912: Custom Customer Attributes not saving at checkout
1 parent d5a54e3 commit 402e59e

File tree

6 files changed

+76
-10
lines changed

6 files changed

+76
-10
lines changed

app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
/*global alert*/
77
define([], function() {
88
/**
9-
* @param addressData
9+
* @param {Object} addressData
1010
* Returns new address object
1111
*/
1212
return function (addressData) {
1313
var identifier = Date.now();
14+
1415
return {
1516
email: addressData.email,
1617
countryId: (addressData.country_id) ? addressData.country_id : window.checkoutConfig.defaultCountryId,
17-
regionId: (addressData.region && addressData.region.region_id)
18-
? addressData.region.region_id
18+
regionId: (addressData.region && addressData.region.region_id) ?
19+
addressData.region.region_id
1920
: window.checkoutConfig.defaultRegionId,
2021
regionCode: (addressData.region) ? addressData.region.region_code : null,
2122
region: (addressData.region) ? addressData.region.region : null,
@@ -33,25 +34,26 @@ define([], function() {
3334
suffix: addressData.suffix,
3435
vatId: addressData.vat_id,
3536
saveInAddressBook: addressData.save_in_address_book,
36-
isDefaultShipping: function() {
37+
customAttributes: addressData.custom_attributes,
38+
isDefaultShipping: function () {
3739
return addressData.default_shipping;
3840
},
39-
isDefaultBilling: function() {
41+
isDefaultBilling: function () {
4042
return addressData.default_billing;
4143
},
42-
getType: function() {
44+
getType: function () {
4345
return 'new-customer-address'
4446
},
45-
getKey: function() {
47+
getKey: function () {
4648
return this.getType();
4749
},
48-
getCacheKey: function() {
50+
getCacheKey: function () {
4951
return this.getType() + identifier;
5052
},
51-
isEditable: function() {
53+
isEditable: function () {
5254
return true;
5355
},
54-
canUseForBilling: function() {
56+
canUseForBilling: function () {
5557
return true;
5658
}
5759
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress
4747
*/
4848
protected $indexerRegistry;
4949

50+
/**
51+
* @var \Magento\Customer\Model\Address\CustomAttributeListInterface
52+
*/
53+
protected $attributeList;
54+
5055
/**
5156
* @param \Magento\Framework\Model\Context $context
5257
* @param \Magento\Framework\Registry $registry
@@ -347,4 +352,27 @@ public function reindex()
347352
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
348353
$indexer->reindexRow($this->getCustomerId());
349354
}
355+
356+
/**
357+
* {@inheritdoc}
358+
*/
359+
protected function getCustomAttributesCodes()
360+
{
361+
return array_keys($this->getAttributeList()->getAttributes());
362+
}
363+
364+
/**
365+
* Get new AttributeList dependency for application code.
366+
* @return \Magento\Customer\Model\Address\CustomAttributeListInterface
367+
* @deprecated
368+
*/
369+
private function getAttributeList()
370+
{
371+
if (!$this->attributeList) {
372+
$this->attributeList = \Magento\Framework\App\ObjectManager::getInstance()->get(
373+
\Magento\Customer\Model\Address\CustomAttributeListInterface::class
374+
);
375+
}
376+
return $this->attributeList;
377+
}
350378
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Model\Address;
7+
8+
class CustomAttributeList implements CustomAttributeListInterface
9+
{
10+
/**
11+
* {@inheritdoc}
12+
*/
13+
public function getAttributes()
14+
{
15+
return [];
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Model\Address;
7+
8+
interface CustomAttributeListInterface
9+
{
10+
/**
11+
* Retrieve list of customer addresses custom attributes
12+
*
13+
* @return array
14+
*/
15+
public function getAttributes();
16+
}

app/code/Magento/Customer/etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
type="Magento\Customer\Model\Metadata\AddressMetadataManagement" />
4444
<preference for="Magento\Customer\Api\CustomerManagementInterface"
4545
type="Magento\Customer\Model\CustomerManagement" />
46+
<preference for="Magento\Customer\Model\Address\CustomAttributeListInterface"
47+
type="Magento\Customer\Model\Address\CustomAttributeList" />
4648
<type name="Magento\Customer\Model\Session">
4749
<arguments>
4850
<argument name="configShare" xsi:type="object">Magento\Customer\Model\Config\Share\Proxy</argument>

app/code/Magento/Customer/view/frontend/web/js/model/customer/address.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ define([], function() {
3232
vatId: addressData.vat_id,
3333
sameAsBilling: addressData.same_as_billing,
3434
saveInAddressBook: addressData.save_in_address_book,
35+
customAttributes: addressData.custom_attributes,
3536
isDefaultShipping: function() {
3637
return addressData.default_shipping;
3738
},

0 commit comments

Comments
 (0)