Custom fields

If your commerce backend has data that you need to use but it isn't mapped by Frontastic, you can add it in. We allow you to store any custom data that you need for your streams, even if our current dataObjects don't support it.

Let's look at an example. In the commercetools account entity, they include vatId which the Frontastic Account doesn't currently map. If you want to use this field, you can do it through projectSpecificData within the Account entity for both Read or Write actions. To do this, an event decorator should be created for the service that you want to target (see this article for more information on event decorators).

To  Read data, you should map the values from $dangerousInner* to projectSpecificData. Continuing with the vatId example:

public function afterCreate(AccountApi $accountApi, Account $account): ?Account
{
    $account->projectSpecificData['vatId'] = $account->dangerousInnerAccount['vatId'];
}

To Write data, you should map from projectSpecificData to rawApiInput. Again, with the vatId example:

public function beforeCreate(
   AccountApi $accountApi,
   Account $account,
   ?Cart $cart = null,
   string $locale = null
): void {
   $account->rawApiInput['vatId'] = $account->projectSpecificData['vatId'];
} 

If you’re using methods that use as a parameter a Query then you need to set the value of loadDangerousInner as true in before method(s). See the Product layer extension article for more information.


Please note, that we've changed the way in which we use custom fields since version 1.1.0. If you've previously used $custom on Account, Cart, or LineItem, you'll need to make sure that you're performing the following mapping in your event decorators:

To Read data:

public function afterCreate(AccountApi $accountApi, Account $account): ?Account
{
    $account->projectSpecificData['custom'] = $account->dangerousInnerAccount['custom'];
}

To Write data:

public function beforeCreate(
   AccountApi $accountApi,
   Account $account,
   ?Cart $cart = null,
   string $locale = null
): void {
   $account->rawApiInput['custom'] = $account->projectSpecificData['custom'];
}

Also, you'll need to make sure that, in any other scenario, you are using projectSpecificData instead of custom. Using Account as an example, before it would've looked like this:

$account->custom = 'foo';

But now it should look like this:

$account->projectSpecificData['custom']= 'foo';

‹ Back to article list

Next article ›

Manipulating HTML head

Still need help? Contact us Contact us