4

I am facing a problem adding customer address custom attributes, in Magento 2.2 is working fine but after upgrading to Magento 2.3 I am receiving this error when shipping-information is saved:

An error occurred during "shipping_address" processing. An error occurred during "customAttributes" processing. A custom attribute is specified with a missing attribute code. Verify the code and try again.

It is happening when sending shipping information, custom attributes keys are not the custom attributes labels, so when Magento validate the customer attributes it's sending the error. I don't find any difference in documentation from Magento 2.2 and 2.3 about adding custom attributes.

enter image description here

Here is an example of how I am adding custom attributes

$customFieldBetweenStreets = [ 'component' => 'Magento_Ui/js/form/element/abstract', 'config' => [ // customScope is used to group elements within a single form (e.g. they can be validated separately) 'customScope' => 'shippingAddress.custom_attributes', 'customEntry' => null, 'template' => 'ui/form/field', 'elementTmpl' => 'ui/form/element/input', 'tooltip' => [ 'description' => 'Entre calles', ], ], 'dataScope' => 'shippingAddress.custom_attributes' . '.' . $customAttributeCodeBetweenStreets, 'label' => 'Entre calles', 'provider' => 'checkoutProvider', 'sortOrder' => 122, 'validation' => [ 'required-entry' => true, 'max_text_length' => 60 ], 'options' => [], 'filterBy' => null, 'customEntry' => null, 'visible' => true, ]; 

And my set-shipping-information-mixin

return function (setShippingInformationAction) { return wrapper.wrap(setShippingInformationAction, function (originalAction, messageContainer) { var shippingAddress = quote.shippingAddress(); if (shippingAddress['extension_attributes'] === undefined) { shippingAddress['extension_attributes'] = {}; } if (shippingAddress.customAttributes != undefined) { $.each(shippingAddress.customAttributes , function( key, value ) { if($.isPlainObject(value)){ value = value['value']; } shippingAddress['customAttributes'][key] = value; shippingAddress['extension_attributes'][key] = value; }); } return originalAction(messageContainer); }); }; 

});

Here the $.each(shippingAddress.customAttributes , function( key, value ) Key is returning the 0,1,2,3 etc, index while in Magento 2.2 is the custom attribute code I am adding in my Layout Processor

Any help would be appreciated

1
  • were you able to find solution Commented Jan 9, 2020 at 11:59

1 Answer 1

3

The problem is in the 'key' value, it's undefined.

'Property "0" does not have accessor method "get0" in class "Magento\Quote\Api\Data\AddressExtensionInterface'

We solved it adding assigning to the key, the attribute code.

Change

 if($.isPlainObject(value)){ value = value['value']; } 

To this

 if($.isPlainObject(value)){ value = value['value']; key = this.attribute_code; } 

It should work.

Regards

1
  • what is the this "this.attribute_code;" ? Commented Dec 16, 2019 at 13:32

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.