Использование Magento 2.3.0. Всякий раз, когда я пытаюсь спасти клиента, я получаю сообщения о том, что требуются вновь созданные атрибуты, даже когда я устанавливаю их значения.
etc / exte_attributes.xml
<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\CustomerInterface">
<attribute code="customershipping_enabled" type="string" />
<attribute code="customershipping_price" type="string" />
</extension_attributes>
</config>
Setup / InstallData.php
<?php
namespace <vendor>\<module_name>\Setup;
use Magento\Eav\Model\Entity\Attribute\Source\Boolean;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface {
private $customerSetupFactory;
public function __construct(
\Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory
) {
$this->customerSetupFactory = $customerSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
$customerSetup =$this->customerSetupFactory->create(['setup'=>$setup]);
$setup->startSetup();
$customerSetup->addAttribute('customer', 'customershipping_enabled', [
'label'=>'Customer Shipping Enabled',
'type' => 'int',
'input' => 'select',
'source' => Boolean::class,
'required'=>true,
'visible'=>true,
'default' => 0,
'position' => 198,
]);
$customerSetup->addAttribute('customer', 'customershipping_price', [
'label'=>'Customer Shipping Price',
'type'=>'decimal',
'input' => 'text',
'required'=>true,
'visible'=>true,
'default' => 0,
'position' => 199,
]);
$enabledAttribute = $customerSetup->getEavConfig()->getAttribute('customer', 'customershipping_enabled');
$enabledAttribute->setData('used_in_forms', ['adminhtml_customer']);
$enabledAttribute->save();
$priceAttribute = $customerSetup->getEavConfig()->getAttribute('customer', 'customershipping_price');
$priceAttribute->setData('used_in_forms', ['adminhtml_customer']);
$priceAttribute->save();
$setup->endSetup();
}
}
Я прочитал много учебников и документации по этому вопросу, и я считаю, что это должно бытьработает правильно, я что-то упустил?Всякий раз, когда я пытаюсь добавить нового клиента или обновлять существующего клиента, он говорит, что эти 2 атрибута являются обязательными значениями, сохранение не удается.
Также выглядит идентично этому посту: mage2gen.com / snippets / customerattribute