先确认问题落在哪一层

结账页新增门牌号或税号字段后,前端能填写,但shipping-information返回400,或订单地址里为空。必须把显示、传输和持久化三层分别验证。

确认customer_address属性backend_type、is_required和used_in_forms。结账使用的表单代码与后台客户地址不同,属性没有分配到正确form时Repository可能忽略。

在浏览器Network检查字段位于shippingAddress.customAttributes还是extension_attributes,并与后端插件读取路径一致。字段名必须和attribute_code完全相同。

SELECT attribute_id,attribute_code,backend_type,is_required FROM eav_attribute WHERE entity_type_id=(SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code='customer_address');
SELECT * FROM customer_form_attribute WHERE attribute_id=:attribute_id;
bin/magento setup:di:compile

实际修复

  • 声明extension_attributes.xml并生成代码;保存前把扩展属性复制到Customer Address/Quote Address,提交订单时再明确复制到Order Address。不要依赖任意数组自动落库。
  • 非必填字段要允许null和空字符串;下拉字段提交option value而不是显示label。清generated并重新compile后测试。

怎样才算修好

测试访客新地址、登录客户新地址、已保存地址和账单地址同/不同四种路径,customer_address_entity、quote_address和sales_order_address值一致。