ฉันเพิ่มแอตทริบิวต์ที่กำหนดเองของลูกค้าเป็นcustomer_addressประเภทและมันทำงานอย่างถูกต้องในผู้ดูแลระบบและใน onepagecheckout เช่นเดียวกับในที่อยู่จัดส่งและการเรียกเก็บเงิน
ฉันสร้าง:
 my_namespace/my_module/etc/module.xmlและregistration.php  composer.jsonไฟล์ในไดเรกทอรีฐานโมดูล
my_namespace / my_module / ติดตั้ง / InstallData.php
namespace Namespace\Module\Setup;
use Magento\Framework\Module\Setup\Migration;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
/**
 * @codeCoverageIgnore
 */
class InstallData implements InstallDataInterface
{
    /**
     * Customer setup factory
     *
     * @var CustomerSetupFactory
     */
    private $customerSetupFactory;
    /**
     * Init
     *
     * @param CustomerSetupFactory $customerSetupFactory
     */
    public function __construct(\Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory)
    {
        $this->customerSetupFactory = $customerSetupFactory;
    }
    /**
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        /** @var CustomerSetup $customerSetup */
        $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
        $setup->startSetup();
        // insert attribute
        $customerSetup->addAttribute('customer_address', 'attr_code',  [
            'label' => 'My attribute',
            'type' => 'varchar',
            'input' => 'text',
            'position' => 45,
            'visible' => true,
            'required' => false,
            'system' => 0
        ]);
        $MyAttribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'attr_code');
        $MyAttribute->setData(
            'used_in_forms',
            ['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address']
        );
        $MyAttribute->save();
        $setup->endSetup();
    }
}ตอนนี้ฉันต้องเพิ่มฟิลด์แอตทริบิวต์ในแบบฟอร์มลูกค้าaddและที่editอยู่ที่เกี่ยวข้องกับไฟล์magento_customer / view / frontend / templates / address / edit.phtml
ฉันเพิ่มฟิลด์ แต่ฉันไม่สามารถรับและบันทึกค่าของแอททริบิวต์นั้นได้