Good evening. I need to create Module which will add Custom Attribute for Customer and Plugin which will set this attribute to 1000 after registration, but during registration of a new Customer it displays error "We can't save the customer" This is what I got:


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   <type name="Magento\Customer\Api\CustomerRepositoryInterface">
<plugin name="bonusPlugin" type="\Kt\Addbonus\BonusPlugin"/>



use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Eav\Model\Config;
use Magento\Eav\Setup\EavSetup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface

const ATTRIBUTE_CODE = 'bonus_attribute';
 * @var EavSetup
private $eavSetup;
 * @var Config
private $config;

public function __construct(EavSetup $eavSetup,
                            Config $config)

    $this->eavSetup = $eavSetup;
    $this->config = $config;

 * Installs data for a module
 * @param ModuleDataSetupInterface $setup
 * @param ModuleContextInterface $context
 * @return void
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)


    $this->eavSetup->addAttribute(Customer::ENTITY, ATTRIBUTE_CODE, [
        'type' => 'int',
        'label' => 'Custom Attribute',
        'input' => 'number',
        'required' => false,
        'visible' => true,
        'user_defined' => true,
        'position' =>999,
        'system' => 0,

    $attribute = $this->config->getAttribute(







use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Api\Data\CustomerInterfaceFactory;

class BonusPlugin
  public function afterSave(CustomerInterfaceFactory $factory, CustomerInterface $customer){

But when I try to create or register a new customer, it shows "We can't save the customer".

  • If you disabled your extension and delete attribute then same is happeing?
    – Amit Bera
    Mar 5 '18 at 14:54
  • @AmitBera no. When I disable my module it works ok.
    – newakkoff
    Mar 5 '18 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.