1 – I add a eav attribute to customer_address
$attributesInfo = [
'reference' => [
'label' => 'Reference',
'type' => 'varchar',
'input' => 'text',
'position' => 100,
'visible' => true,
'required' => false,
],
];
foreach ($attributesInfo as $attributeCode => $attributeParams) {
$customerSetup->addAttribute('customer_address', $attributeCode, $attributeParams);
}
2 – I added the extension attribute in my module
<extension_attributes for="Magento\Quote\Api\Data\AddressInterface">
<attribute code="reference" type="string"/>
</extension_attributes>
In my requirejs-config.js I override some javascript file to add reference field
var config = {
"map": {
"*": {
"Magento_Checkout/js/model/shipping-save-processor/default" : "Agr_Checkout/js/shipping-save-processor-default-override",
"Magento_Customer/js/model/customer/address" : "Agr_Checkout/js/model/customer/address",
"Magento_Checkout/js/model/address-converter" : "Agr_Checkout/js/model/address-converter",
"Magento_Checkout/js/model/new-customer-address" : "Agr_Checkout/js/model/new-customer-address"
}
}
3 – I confirm that the reference field is sending in address
4 – When i send my shipping information (Click on Next) I'm getting this error: "Property "Reference" does not have corresponding setter in class "Magento\Quote\Api\Data\AddressInterface"."
I already do:
– Clean and flush magento cache
– Run setup:upgrade
– Run setup:di:compile
What I'm doing wrong?
Best Answer
Setting up attributes in an eav setup or upgrade script works best, and will automatically add to forms you request to add it to.
This code here will add to the forms and there won't be any issue saving or going to next step