Project specific data

📘

This is an article for advanced users of Frontastic.

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 project specific data that you need for your data sources, 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, 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 domain model question in our FAQs.

🚧

We've changed the way in which we use project specific data 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're 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';