custom attribute in customer address grid
Вопрос
I am trying to add a column in the customer address grid in admin with a custom attribute.
<column name="addresstypes" class="xxx\AddressAttribute\Ui\Component\Listing\Address\Column\Addresstype" sortOrder="95">
<settings>
<filter>text</filter>
<label translate="true">Address Type</label>
<editor>
<editorType>text</editorType>
</editor>
</settings>
</column>
It is added also and shown in the grid. but, the value which I in form, it's showing correctly if the customer has only one address. if they have multiple addresses, then also shows the same value for all. but in form, there is a different value.
this is my UI-component code:
public function prepareDataSource(array $dataSource): array
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$item) {
$name = $this->getData('name');
if (isset($item['entity_id'])) {
$customerId = $item['parent_id'];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerObj = $objectManager->create('Magento\Customer\Model\Customer')->load($customerId);
$billingAddressId = $customerObj->getDefaultBilling();
$customerAddress = array();
foreach ($customerObj->getAddresses() as $address)
{
$customerAddress[] = $address->toArray();
}
foreach ($customerAddress as $customerAddres) {
$addressId = $customerAddres['entity_id'];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$addressshipto = $objectManager->get('Magento\Customer\Model\AddressFactory')->create()->load($addressId);
$addresst = $addressshipto->getData('addresstype');
if(isset($customerAddres['addresstype'])){
$addressType = $customerAddres['addresstype'];
}
if(isset($addressType) && $addressType == 21764) {
$item['addresstypes'] = "Bill to ";
}else{
$item['addresstypes'] = "Ship to ";
}
}
}
}
}
return $dataSource;
}
Нет правильного решения
Не связан с magento.stackexchange