我添加了一个客户自定义属性作为customer_address
类型,它可以在admin,onepagecheckout以及送货和帐单地址中正常运行。
我在模块基本目录中创建了:
my_namespace/my_module/etc/module.xml
和registration.php
composer.json
文件。
my_namespace / my_module / Setup / 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();
}
}
现在,我需要在与文件magento_customer / view / frontend / templates / address / edit.phtml相关的客户add
和edit
地址表单中添加属性字段
我添加了该字段,但无法获取和保存该属性的值。