Skip to main content

Product

A search input field for selecting a product from the catalog. Data can be searched by product name or reference. Useful for linking related products or adding product references in custom forms. This field can be combined with a repeater field to configure product galleries.

Screenshots

Field render in form:

field preview field preview

Field render in field group:

field preview

Configuration

  • Settings:

    • Name: The label for the field.
    • Slug: The unique technical identifier.
    • Allow virtual products: Option to include virtual products in the search results.
    • Allow packs: Option to include product packs in the search results.
  • Validation:

    • Require: Determines if the field must be filled out.
  • Design:

    • Instructions: Text displayed alongside the field providing details about the data needed.
    • Width: The width of the field in the form.
    • Classes: Custom CSS classes for styling the field.
    • ID: Custom ID attribute for the field.
    • Text before: Additional text displayed before the field.
    • Text after: Additional text displayed after the field.

Return format

  • Type: Object (RelationFieldValue) or null
  • Object methods:
// Return related entity object
$product = $relationFieldValue->getEntity();

// Return related entity field groups
$fieldGroups = $relationFieldValue->getFieldGroups();

// Add presenter vars
$relationFieldValue->addPresenterVars([
'some_var' => 'some_value'
]);

// Return related entity presenter
$productPresenter = $relationFieldValue->getPresenter();
info

The field value returns an object instead of an array to perform lazy loading of sub-values (object, field groups, and presenter for certain entities) and ensure process performance.

Usage

/some-template.tpl
{* Object or Entity and Id *}
{assign var="data" value=$modules.customfieldgroups.data->get($product)}
{assign var="data" value=$modules.customfieldgroups.data->get('product', $product.id)}

{if $data.field_group_slug.field_slug}
<span>{$data.field_group_slug.field_slug->getEntity()->id}</span>

{* Entity related field groups *}
{assign var="entity_field_groups" value=$data.field_group_slug.field_slug->getFieldGroups()}
<span>{entity_field_groups.field_group_slug.field_slug}</span>
{/if}
/SomeClass.php
function someMethod()
{
$dataRetriever = DataRetrieverFacade::getInstance();

$data = $dataRetriever->get($object); // Object
$data = $dataRetriever->get('product', $idProduct); // Entity and id

$productData = $data['field_group_slug']['field_slug'];
$productObject = $productData ? $productData->getEntity() : null;
$productFieldGroups = $productData ? $productData->getFieldGroups() : [];
$productPresenter = $productData ? $productData->getPresenter() : null;
}