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 wanted to use this specific data, you can set it from the frontend using accountData.projectSpecificData.vatId. An Event Decorator will then map the vatId from projectSpecificData into rawApiInput

To add in the field, you need to go to your commerce backend FrontendBundle folder and edit the RawDataService php file to add in the relevant contant. Continuing with our example, we would go to ..\FrontendBundle\Domain\Commercetools\RawDataService and within COMMERCETOOLS_ACCOUNT_FIELDS we would add vatId. We also need to specify the action name that this field needs in order to be set, so we use setVatId. Below is how this would look:

	'vatId' => [

Then this will be stored within rawApiInput and will be posted along with the rest of the mapped account data. For example:

$account = $this->mapAccount($this->client->post(
	            'email' => $account->email,
	            'firstName' => $account->firstName,
	            'lastName' => $account->lastName,
	            // ...

If you want to create a new Event Decorator, you need to map to or from the projectSpecificData depending on the type of action that you want to achieve, Read or Write.

To Read, the data from $dangerousInner<dataObjectName> needs to be mapped to projectSpecificData. Continuing with the vatId example:

$account->projectSpecificData['vatId'] = $dangerousInnerAccount['vatId'];

To Write, the data from projectSpecificData needs to be mapped to rawApiInput. Again, with the vatId example:

$account->rawApiInput['vatId'] = $accountData['projectSpecificData']['vatId'];

Please note, that we've changed the way in which we do this. If you've previously used $custom or any other Custom Fields, please follow the below steps to ensure it's backwards compatible:

Open your service.xml file then add the below snippet:

<service id="Frontastic\Catwalk\FrontendBundle\Domain\Commercetools\RawDataService">

<service id="Frontastic\\Catwalk\\FrontendBundle\\Domain\\Commercetools\\LifecycleEventDecorator\\MapAccountDataDecorator">
    <argument type="service" id="Frontastic\\Catwalk\\ApiCoreBundle\\Domain\\CommerceTools\\ClientFactory" />
    <argument type="service" id="Frontastic\\Catwalk\\FrontendBundle\\Domain\\Commercetools\\RawDataService" />

    <tag name="accountApi.lifecycleEventListener" />

<service id="Frontastic\\Catwalk\\FrontendBundle\\Domain\\Commercetools\\LifecycleEventDecorator\\MapCartDataDecorator">
    <argument type="service" id="Frontastic\\Catwalk\\FrontendBundle\\Domain\\Commercetools\\RawDataService" />

    <tag name="cartApi.lifecycleEventListener" />

‹ Back to Article List

Next Article ›

Manipulating HTML Head

Still need help? Contact Us Contact Us