Hybris reference editor - filter using catalog version

1.4k Views Asked by At

In my Hybris setup, I have a custom type where one of the fields is a collection of products. In a backoffice screen for the type, I have a multi-reference editor to select the relevant products for the collection. Now, I want to restrict the products to Online catalogue only (i.e. not show products from Staged product catalogue). The relevant documentation page indicates that I can use this syntax:

<editorArea:attribute qualifier="products">
    <editorArea:editor-parameter>
        <editorArea:name>referenceSearchCondition_catalogVersion</editorArea:name>
        <editorArea:value>{parentObject.catalogVersion}</editorArea:value>
    </editorArea:editor-parameter>
</editorArea:attribute>

In my case, however, the custom type does not have the catalogVersion attribute, so I would really like to do something like this instead:

<editorArea:attribute qualifier="products">
    <editorArea:editor-parameter>
        <editorArea:name>referenceSearchCondition_catalogVersion</editorArea:name>
        <editorArea:value>Online</editorArea:value>
    </editorArea:editor-parameter>
</editorArea:attribute>

This does not work (naturally), as the parentObject.catalogVersion is the PK. In my testing, if I specify the actual catalog version PK instead of Online, I do get the results I need, yet, obviously, hardcoding the PK is not an option. So, how can I use the referenceSearchCondition to compare with a field of catalog version, referred to by the field in my custom type?

3

There are 3 best solutions below

0
On

The only solution/workaround(not really ideal) that came to my mind right now after taking a look into the documentation and the accelerator code provided by SAP is doing the following:

  1. Create a dynamic attribute which retrieves the PK of the catalogVersion Online on the parent (Ex: name it catalogVersionOnlinePK).

  2. Then you can access the PK value directly:

     <editorArea:attribute qualifier="products">
        <editorArea:editor-parameter>
            <editorArea:name>referenceSearchCondition_catalogVersion</editorArea:name>
            <editorArea:value>{parentObject.catalogVersionOnlinePK}</editorArea:value>
        </editorArea:editor-parameter>
    </editorArea:attribute>
    
0
On

Not sure if it goes OTTB, but try this

<editorArea:attribute qualifier="products">
   <editorArea:editor-parameter>
       <editorArea:name>referenceSearchCondition_catalogVersion.version</editorArea:name>
       <editorArea:value>Online</editorArea:value>
   </editorArea:editor-parameter>
</editorArea:attribute>
0
On

I had nearly the same requirement and solved it this way:

<wz:editor-parameter>                                
    <wz:name>referenceSearchCondition_catalogVersion_in</wz:name>
    <wz:value>{@customCatalogVersionService.getOnlineCatalogVersions()}</wz:value>
</wz:editor-parameter>

in addition, i also needed to make the customCatalogVersionService available by adding this to the corresponding *backoffice-spring.xml:

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:cng="http://www.hybris.com/cockpitng/spring"
       xmlns="http://www.springframework.org/schema/beans"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.hybris.com/cockpitng/spring
            http://www.hybris.com/cockpitng/spring/cng-spring.xsd">

    ...

    <cng:list-extender bean="fixedBeanResolver" property="availableBeanNames">
        <cng:add value-type="java.lang.String">
            <value>customCatalogVersionService</value>
        </cng:add>
    </cng:list-extender>