String customfields the right way

Written by Max Milbers on .

The customfield of type S "String" is one of the most used customfields in VirtueMart.

As Specs

It can be very practical to present typical specifications of your product in a standardized way. Remember that it's easy to override your product display with your own layout positions. There are two settings in the customfield prototype that offer a big advantage over a normal product description.

  • You can set the customfield to "searchable" so that the custom field S becomes a tag.
  • You can set the customfield "cart attribute" to display the attribute in the cart as a mandatory specification.

As Variant

The other very important function is the creation of simple product variants. This type of variant simply adds the variant information to the product as a user-defined field. Simply set the customfield to "is input".

This type of customfield requires at least two alternatives, otherwise it would not be a variant. So the easiest way to create a variant is to add the same customfield prototype S with "is input" at least twice. This creates a drop-down menu or radio box for the product. That was the idea at the beginning.

But we developed the whole idea further and so the customfield S has the additional parameter "is a list" with the options:

  • No
  • Yes
  • as adminlist

The list is defined in the "Default value" field, separated by semicolons. A customfield set to "Yes" with red;blue;green will automatically create a drop-down menu in the product view with the options red, blue, green. If it is set to adminlist, it creates drop-down lists from which you can choose in the ‘Product Edit’ view. This is very useful to avoid typos. Also, if the shop editor has made a general mistake like a typo in the list, it can be fixed by using the "Transform list" parameter.

Use of Pattern products

Most people think that using an additional parent or even child variant consumes a lot of resources. Of course, simple logic means that loading products is resource-intensive and loading child products is slow.

But the opposite is true. The more a child product uses the same specifications as the parent product (category, manufacturer, customfields), the better the cache can work and the faster the products load. This also works for the customfield with "is input" and "is adminlist". It takes less time to define all variants in the pattern and then disable or overwrite the unwanted variants in the child products as long as you disable/override fewer custom fields than it would take to add the specifications to the childs.