cancel
Showing results for 
Search instead for 
Did you mean: 

How do I push a localized enum name to a variant product page?

Former Member
0 Kudos

I've setup a practice shop based off of the accelerator and am trying to achieve the following goals:

  1. Create a new Product model

  2. Create a variant product with an enumerated value

  3. Display a localized enumerated value via a drop-down list on the product page.

Currently, I have my product created and am able to see a drop-down list of values for the variant products, but the drop-down does not appear to be localized. Here are the relevant (I think) code snippets.

         <enumtype code="emergencyResponseEnum" autocreate="true" dynamic="true" generate="true">
             <value code="NONE"/>
             <value code="FIFTEEN_MINUTES"/>
             <value code="THIRTY_MINUTES"/>
             <value code="SIXTY_MINUTES"/>
             <value code="SIX_HOURS"/>
         </enumtype>
 ...
     <maptypes>
         <maptype code="localized:emergencyResponseEnum" argumenttype="Language" returntype="emergencyResponseEnum" autocreate="true" generate="false" />
     </maptypes>
 
 ...
         <itemtype code="ServiceProduct" extends="Product"
                   autocreate="true" generate="true">
             <description>Service Products represent our core packages of development, support, and monitoring</description>
             <deployment table="ServiceProducts" typecode="11337"/>
             <attributes>
                 <attribute qualifier="emergencyResponse" type="localized:emergencyResponseEnum">
                     <description>Rapid response for critical errors in the service.</description>
                     <modifiers/>
                     <persistence type="property"/>
                 </attribute>
             </attributes>
         </itemtype>
 ...
 <itemtype code="EmergencyResponseVariantProduct" extends="VariantProduct"
                   autocreate="true" generate="true"
                   jaloclass="de.hybris.merchandise.core.jalo.EmergencyResponseVariantProduct">
             <description>Emergency Response variant offering guaranteed times for response.
             </description>
             <attributes>
                 <attribute qualifier="emergencyResponseEnum" type="localized:emergencyResponseEnum"
                            metatype="VariantAttributeDescriptor">
                     <description>Guaranteed response time in event of a critical issue.</description>
                     <modifiers/>
                     <persistence type="property"/>
                 </attribute>
             </attributes>
         </itemtype>

In core-locales_en.properties, I've tried the following:

 type.emergencyResponseEnum.NONE.name=None  
 type.EmergencyResponseVariantProduct.emergencyResponseEnum.NONE.name=None  
 type.ServiceProduct.emergencyResponseEnum.NONE.name=None  

And in my products.impex file:

 INSERT_UPDATE ServiceProduct;code[unique=true];$supercategories;manufacturerName;manufacturerAID;unit(code);varianttype(code);ean;$catalogVersion;$approved;$taxGroup
 
  ;1100;310;Core Support Team;SUPPORT-1;pieces;EmergencyResponseVariantProduct
 
 # Create EmergencyResponseVariantProduct variants
 INSERT_UPDATE EmergencyResponseVariantProduct;code[unique=true];$catalogVersion;$baseProduct;unit(code);emergencyResponseEnum(code);supercategories(code,$catalogVersion);$approved
 ;1100_NONE;;1100;pieces;NONE;310;

Finally, in productVariantSelector.tag, I'm attempting to access the value through the list of variantOptions and then using the variantOptionQualifier.name field, which currently displays NONE rather than None.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Solved, I think. As far as I can tell, the process of actually localizing the value in the drop-down menu is as follows:

1) Define your enum and product model in items.xml

 <enumtype code="emergencyResponseEnum" autocreate="true" dynamic="true" generate="true">
                 <value code="NONE"/>
                 <value code="FIFTEEN_MINUTES"/>
                 <value code="THIRTY_MINUTES"/>
                 <value code="SIXTY_MINUTES"/>
                 <value code="SIX_HOURS"/>
             </enumtype>
 
      <itemtype code="ServiceProduct" extends="Product"
                       autocreate="true" generate="true">
     ...

2) Define your variant product in items.xml with a localized string and the enum. Give the string the metatype of VariantAttributeDescriptor

         <itemtype code="EmergencyResponseVariantProduct" extends="VariantProduct"
                   autocreate="true" generate="true"
                   jaloclass="de.hybris.merchandise.core.jalo.EmergencyResponseVariantProduct">
             <description>Emergency Response variant offering guaranteed times for response.
             </description>
             <attributes>
                 <attribute qualifier="emergencyResponse" type="localized:java.lang.String"
                            metatype="VariantAttributeDescriptor">
                     <description>Guaranteed response time in event of a critical issue.</description>
                     <modifiers/>
                     <persistence type="property"/>
                 </attribute>
                 <attribute qualifier="emergencyResponseEnum" type="emergencyResponseEnum">
                     <description>Enum mapping for the emergency response time.</description>
                     <modifiers/>
                     <persistence type="property"/>
                 </attribute>
             </attributes>
         </itemtype>

3) In products.impex, insert_update your product and associate it with the variant type

 INSERT_UPDATE ServiceProduct;code[unique=true];$supercategories;manufacturerName;manufacturerAID;unit(code);varianttype(code);ean;$catalogVersion;$approved;$taxGroup
 
  ;1100;310;Core Support Team;SUPPORT-1;pieces;EmergencyResponseVariantProduct

4) Also in products.impex, insert_update your variant products and associate them with the correct enum value.

 INSERT_UPDATE EmergencyResponseVariantProduct;code[unique=true];$catalogVersion;$baseProduct;unit(code);emergencyResponseEnum(code);supercategories(code,$catalogVersion);$approved
 ;1100_NONE;;1100;pieces;NONE;310;
 ;1100_15M;;1100;pieces;FIFTEEN_MINUTES;310;
 ;1100_30M;;1100;pieces;THIRTY_MINUTES;310;
 ;1100_60M;;1100;pieces;SIXTY_MINUTES;310;
 ;1100_6H;;1100;pieces;SIX_HOURS;310;

5) In products_en.impex, update product for your variant products and associate it with the localized string.

 UPDATE Product; code[unique = true]; $catalogVersion; name[lang = $lang]; summary[lang = $lang]; description[lang = $lang]; EmergencyResponseVariantProduct.emergencyResponse[lang = $lang]
 ;1100_NONE;;Core Support - No ER;;Whatever;None
 ;1100_15M;;Core Support - 15m ER;;Whatever;15 minutes
 ;1100_30M;;Core Support - 30m ER;;Whatever;30 minutes
 ;1100_60M;;Core Support - 60m ER;;Whatever;60 minutes
 ;1100_6H;;Core Support - 6h ER;;Whatever;6 hours

6) ant all and update/localize the running system (or reinitialize). Results are shown below.

Before (ignore the ER Time string):

After:

Answers (1)

Answers (1)

former_member387866
Active Contributor
0 Kudos

Hi Alex,

Have you tried just localising the base Enum and ignoring the Variant Types? Or have you already tried this approach?

The Localising Section on the Working with Enums documentation page may be relevant.

Regards,
Luke

Former Member
0 Kudos

Hey Luke, indeed I have; in my post, I included the brief excerpt from my locales_en.properties file, which has the different approaches I tried (among many others).

I'm sure it always works this way, but after two days and posting this question, I actually just solved it. I reexamined the ApparelStyleVariantProduct example and realized that they don't actually localize the enum, but instead associate a localized string and give it the metatype of VariantAttributeDescriptor.

former_member387866
Active Contributor
0 Kudos

Coolbeans Alex.

Glad you found, and detailed, your answer.