One of Shopware 6′ the most useful features for shop owners is the ability to add custom fields to almost any entity. Some benefits of custom fields are:
- Can be defined and edited via admin out-of-the-box
- Allow almost any field format
- Can be grouped in logical groups
However, there is no standard mechanism that would make a custom field available for display in the storefront. You will need to extend your theme’s Twig templates to make custom fields visible for shop users. This is a straight-forward task, described very well in the docs: https://developer.shopware.com/docs/guides/plugins/plugins/storefront/using-custom-fields-storefront
In this post, I am going to demonstrate how you can add a custom field to a form, so that a user would even be able to submit additional data.
Continue reading “Adding Custom Fields to Forms”
Shopware 6′ custom fields is a very powerful yet easy to use mechanism to customize the standard data model and functionality. Custom fields for an entity are stored in a pre-defined json field with that entity. This mechanism is very flexible, and allows even out-of-the-box translations for custom fields, however it has two major flaws:
First, it creates some inevitable performance overhead. If you need to search that field (say an ERP product id) from a PHP script, be aware that, since it is wrapped in an SQL json field, there is no related database index.
Second, it relies on a pre-defined json field being defined for that entity. If the makers of Shopware decided to leave that off for an entity, that’s it – no custom fields for this entity.
Luckily, there is a simple alternative to custom fields provided in Shopware’s Data Access Layer (DAL) entity extensions. While it needs a litte bit more code than a simple custom field, there is no big magic behind it. Read and learn here how to create additional fields for any entity in Shopware 6.___STEADY_PAYWALL___
Continue reading “Adding a Custom Field as Extension”