Мне нужно добавить новое поле ввода в форму группы клиентов.
Я использовал концепцию плагина, поэтому я сделал следующие шаги:
- Добавление части installSchema:
$installer->getTable('customer_group'),
'customer_tarif_code',
[
'type' => Table::TYPE_TEXT,
'nullable' => true,
'length' => 64,
'comment' => 'Customer Tarif Code'
]
);
$connection->addColumn(
$installer->getTable('customer_group'),
'erp_customer_group_code',
[
'type' => Table::TYPE_TEXT,
'nullable' => true,
'length' => 32,
'comment' => 'Colibase\'s customer group code'
],
null
);
2.Я создал следующий файл в etc / extension_attribues. xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Customer\Api\Data\GroupInterface">
<attribute code="erp_customer_group_code" type="string"/>
<attribute code="customer_tarif_code" type="string"/>
</extension_attributes>
</config>
3. Мне удалось отобразить форму с перехватчиком функции afterSetForm с плагином di. xml:
<type name="Magento\Customer\Block\Adminhtml\Group\Edit\Form">
<plugin name="editFormGroupCustomer" type="Middleware\Erp\Plugin\Magento\Customer\Block\Adminhtml\Group\Edit\Form"/>
</type>
Так же я сохранил атрибут с функцией afterExecute с плагином, di. xml:
<type name="Magento\Customer\Controller\Adminhtml\Group\Save">
<plugin name="customerGroupSave" type="Middleware\Colibase\Plugin\Magento\Customer\Controller\Adminhtml\Group\Save"/>
</type>
5. Моя проблема заключается в том, что входное значение отображается пустым в форме редактирования группы клиентов:
Я добавил функцию-перехватчик afterGetById для плагина, в di. xml:
<type name="Magento\Customer\Api\GroupRepositoryInterface">
<plugin name="editCustomerGroup" type="Middleware\Erp\Plugin\Magento\Customer\Model\ResourceModel\GroupRepository"/>
</type>
с этим источником код:
<?php
namespace Middleware\Erp\Plugin\Magento\Customer\Model\ResourceModel;
use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Customer\Api\Data\GroupExtension;
use Magento\Customer\Api\Data\GroupExtensionFactory;
use Magento\Customer\Api\Data\GroupInterface;
class GroupRepository
{
/**
* @var GroupExtensionFactory
*/
private $extensionFactory;
/**
* CartRepositoryPlugin constructor.
*
* @param GroupExtensionFactory $orderExtensionFactory
*/
public function __construct(
GroupExtensionFactory $orderExtensionFactory,
\Psr\Log\LoggerInterface $logger
) {
$this->extensionFactory = $orderExtensionFactory;
$this->logger = $logger;
}
/**
* @param GroupRepositoryInterface $subject
* @param \Magento\Customer\Api\GroupInterface $resultEntity
* @return GroupInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetById(
\Magento\Customer\Api\GroupRepositoryInterface $subject,
\Magento\Customer\Api\Data\GroupInterface $resultEntity
) {
$this->logger->debug('afterget by id');
$this->logger->debug($resultEntity->getExtensionAttributes()->getErpCustomerGroupCode());
$this->logger->debug('next');
return $resultEntity;
}
}
Всегда у меня есть результат, пустой от этой инструкции $ resultEntity-> getExtensionAttributes () -> getErpCustomerGroupCode ()
Любая помощь приветствуется.
Спасибо.