How to extend the core customer table?

Viewed 452

I created a custom table with additional settings for customers. Next I added a field to the customer core table in which I'd like to store the id choice per customer. I extended with EntityExtensionInterface the customerDefinition :

public function extendFields(FieldCollection $collection): void
{
    $collection->add(
        (new OneToOneAssociationField(
            'customerSetting',
            'customer_setting',
            'id',
            WdtCustomerSettingsDefinition::class,
            true
        ))->addFlags(new Inherited())
    );
}

public function getDefinitionClass(): string
{
    return CustomerDefinition::class;
}

When I manually manipulate the customer table, with an id from my custom table in the added field, I can retrieve and use the settings from my custom table in the storefront.

For the backend I created a single select to the entity custom_table,

<sw-entity-single-select entity="wdt_customer_settings" v-model="customer.extensions.customerSetting.id" >
</sw-entity-single-select>

and with the manually 'injected' id from the custom table, this choice indicates indeed 'selected' However, after changing to another choice and saving results in an error: Customer could not be saved.

What am I missing?

1 Answers

You should look always to the ajax responses. There is the explict error which is occured. Do you added some boilerplate code to check that your extensions is always available? Otherwise it would cause issues on new entities

Related