custom fields for address are not being saved?

Viewed 44

I added some custom fields for address for in a twig template which extends from

@Storefront/storefront/component/address/address-form.html.twig

when i submit the form from the /checkout/register page, the custom fields are not saved.

In the Shopware\Core\Checkout\Customer\SalesChannel\RegisterRoute.php file, when data mapping is done for address, only the fields below are mapped:

private function mapAddressData(DataBag $addressData): array
{
    $mappedData = $addressData->only(
        'firstName',
        'lastName',
        'salutationId',
        'street',
        'zipcode',
        'city',
        'company',
        'department',
        'countryStateId',
        'countryId',
        'additionalAddressLine1',
        'additionalAddressLine2',
        'phoneNumber'
    );

    if (isset($mappedData['countryStateId']) && $mappedData['countryStateId'] === '') {
        $mappedData['countryStateId'] = null;
    }

    return $mappedData;
}

How can i save custom fields for an address when developing an app? is it possible ?

1 Answers

There's this repository (not mine) with an example on how to add additional inputs to the storefront and how to map them to the payload when persisting the address. Basically you subscribe to the corresponding CustomerEvents, take the user inputs and enrich the payload.

Related