I need to create a custom attribute on the order address to stock my ERP id of the address for a syncing purpose.
I've tried to create a Eav in Maru3l/SyncOrchestra/Setup/InstallData.php. I don't see the input appeared in the admin panel but the file in the log folder is created.
<?php
namespace Maru3l\SyncOrchestra\Setup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
/**
* Attribute Code of the Orchestra ID attribute
*/
const ORECHESTRA_ID_ATTRIBUTE_CODE = 'orchestra_id';
/**
* @var EavSetupFactory
*/
protected $eavSetupFactory;
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
/**
* Install Orchestra id attribute
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
'customer_address',
self::ORECHESTRA_ID_ATTRIBUTE_CODE,
[
'label' => 'Orchestra ID',
'input' => 'text',
'visible' => true,
'position' => 100,
'unique' => true,
'required' => false,
'system' => false
]
);
$dumpFile = fopen('/var/www/vhosts/store-api.silverwax.ca/httpdocs/var/log/dataDump', 'w+');
fwrite($dumpFile, 'Install eav \n');
$setup->endSetup();
}
}
I've also created the Maru3l/SyncOrchestra/etc/extension_attributes.xml:
<?xml version="1.0"?>
<!--
/**
* Copyright © Mageside. All rights reserved.
* See MS-LICENSE.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Sales\Api\Data\OrderAddressInterface">
<attribute code="orchestra_id" type="string" />
</extension_attributes>
</config>
My other concern is how can I get or set the value programmatically.