Skip to main content

CustomField Service

The Econsor CustomField Service will from now on be our standard way to add CustomFields. The reason for this is that this way we have a consistent, uniform and most of all easy way to do all of this, while eliminating the need for weird Database checks regarding the existence of specific CustomField groups.

Usage

To use the Service, update your shops EconsorSetup Plugin (if needed). We're specifically looking for the new Namespace Econsor\\Shopware\\Setup and the CustomFieldService.php File. Some shops do not have this yet.

Import

use Econsor\\Shopware\\Setup\\Services\\CustomFieldService;

Add a Custom Field

To get the Id of the CustomFieldSet you want to add a CustomField to, use the addCustomFieldSet method. This will create a CustomFieldSet for you (according to our standards) or, more importantly, return the Id of the one that already exists.

You call this method with 3 params. The name of the Entity you want to add the CustomField to (i.e. products), the CustomFieldSet Repository and the Context.

Since you add a customField usually in the Install method, our call would look something like this:

$cFieldSetRepo = $this->container->get('custom_field_set.repository');
$customFieldSetId = $customFieldService->addCustomFieldSet(
'product_manufacturer',
$cFieldSetRepo,
$installContext
);

With this fieldset Id you can now create a CustomField like usual.

Add a Customfield entity to the Service

We haven't implemented all entities yet. If you need one of the ones that aren't there yet, or to see which ones are already there, navigate to the Service Class.

Here you can add a new case to the switch at the bottom.

Don't forget to keep the naming scheme and don't forget to push it into the repository!