Saya menambahkan atribut khusus pelanggan sebagai customer_address
jenis dan itu berjalan dengan benar di admin dan di onepagecheckout serta di alamat pengiriman & penagihan.
Saya membuat:
my_namespace/my_module/etc/module.xml
dan registration.php
composer.json
file dalam direktori basis modul.
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();
}
}
Sekarang saya perlu menambahkan bidang atribut di formulir pelanggan add
dan edit
alamat yang terkait dengan file magento_customer / view / frontend / templates / address / edit.phtml
Saya menambahkan bidang tetapi saya tidak bisa mendapatkan dan menyimpan nilai atribut itu.