Dodałem niestandardowy atrybut klienta jako customer_address
typ i działa on poprawnie w administratorze i w kasie onepagecheckout, a także w adresie wysyłki i fakturowania.
Utworzyłem:
my_namespace/my_module/etc/module.xml
i registration.php
composer.json
pliki w katalogu podstawowym modułu.
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();
}
}
Teraz muszę dodać pole atrybutu w formularzu klienta add
i edit
adresu, które są powiązane z plikiem magento_customer / view / frontend / templates / address / edit.phtml
Dodałem pole, ale nie mogę uzyskać i zapisać wartości tego atrybutu.