Passing Context Map to Configurable Flow Wizard

In Backoffice Framework, there is a functionality that allows you to pass the context map to the Configurable Flow Wizard widget. Owing to the context mapping, the wizard opens with the fields defined in the mapping and already filled in basing on the base item.

You may want to pass a context map to a wizard in two cases:
  • to trigger the configurableFlowWizard from a custom action or a custom widget
  • to trigger the configurableFlowWizard from a reference editor

Triggering configurableFlowWizard from Custom Action or Widget

You might pass the context map to a wizard when it is triggered by a custom action or a custom widget. See the example how to configure it.

Context

For the purpose of this example, let's assume that you want to create a custom action responsible for opening the configurableFlowWizard with some populated fields.

The second assumption is that the action input socket is connected with a widget that provides ProductModel on this socket.

The goal is to create a context map that consists of a string, reference, and localized elements.

Procedure

  1. The custom action has to have a java.util.Map output socket type defined in the definition.xml:
    <output id="wizardContext" type="java.util.Map" />

    Thanks to this socket, you would be able to connect your action with configurableFlowWizard and it would be possible to pass a context map.

  2. Add the connection between the custom action and the configurableFlowWizard in the widgets.xml file:
    <widget-connection sourceWidgetId="STUB_com.hybris.wizard.widgets.action.OpenWizardAction" outputId="wizardContext" targetWidgetId="configurableFlow" inputId="context"/>

  1. Modify the public ActionResult<Object> perform(final ActionContext<Object> ctx) method of your action to define the context maps for string, reference, and localized elements as follows:
    @Override
    public ActionResult<Object> perform(final ActionContext<ProductModel> ctx)
    {
    	final ProductModel data = ctx.getData();
    	final Map<String, Object> contextMap = new HashMap<>();
    	contextMap.put(ConfigurableFlowContextParameterNames.TYPE_CODE.getName(), "Product");
     
    	contextMap.put("code", data.getCode());
    	contextMap.put("catalogVersion", data.getCatalogVersion());
         
    	final Map<Locale, String> localizedNames = new HashMap();
    	localizedNames.put(Locale.ENGLISH, data.getName(Locale.ENGLISH));
    	contextMap.put("name", localizedNames);
     
     
    	sendOutput("wizardContext", contextMap); 
    	return new ActionResult<>(ActionResult.SUCCESS);
    }
    Other parameters defined in the context map are:
    • the product code, which is of String type
    • the catalogVersion, which is of reference type
    • the name, which is of localized type. To pass localized values, you need to create an additional map, where the key is Locale object and the value is localized text.
  2. Add proper configuration to the cockpit-config.xml. Indicate which field from our context should be rewritten to the new context of the configurableFlowWizard. See the following snippet:
    <wz:prepare id="productPrepare">
    	<wz:initialize property="newProduct" type="ctx.TYPE_CODE"/>
    	<wz:assign property="newProduct.code" value="ctx.code"/>
    	<wz:assign property="newProduct.catalogVersion" value="ctx.catalogVersion"/>
    	<wz:assign property="newProduct.name" value="ctx.name"/>
    </wz:prepare>

Results

As a result, every time a wizard is opened by the action, the code, catalogVersion, and name properties are already prepopulated basing on the previously opened item.

Triggering configurableFlowWizard from Reference Editor

You might pass the context map to a wizard when it is triggered from a reference editor. See the example of how it is done.

Context

Defining a context map for the configurableFlowWizard when it is triggered from the reference editor is simpler than in the case when it is triggered from an action or a widget. The connection between a wizard and a reference editor is already done. Passing the context map to a wizard is done through the cockpit-config.xml file.

For the purpose of this example, let's assume that we want to open the configurableFlowWizard for VariantProducts. We want to populate:
  • code
  • catalogVersion
  • name
from the base product.

Procedure

Add the following code snippet to the cockpit-config.xmlfile:
<wz:prepare id="productPrepare">
	<wz:initialize property="newProduct" type="ctx.TYPE_CODE"/>  
	<wz:assign property="newProduct.code" value="ctx.parentObject.code"/>
	<wz:assign property="newProduct.catalogVersion" value="ctx.parentObject?.catalogVersion"/>
	<wz:assign property="newProduct.baseProduct" value="ctx.parentObject"/>
	<wz:assign property="newProduct.name" value="ctx.parentObject.name"/>
</wz:prepare>

As you can notice, the original context – ctx contains information about base product – parentObject. Owing to this, you can rewrite all of the properties of your interest (code, catalogVersion, and name) in an easy way.

Results

Now, when you trigger a wizard for a Variant Product, the wizard would pass the context from the base Product. All the fields are prepopulated basing on the last open item.