What is the enum type, How to use and define in Hybris ?

What is the enum in Hybris ?

SAP Commerce enables us to use attributes with pre-defined values, called enumeration. Enum types are used for defining constant values. but Dynamic in Enum is different from Dynamic attributes, can add dynamic value at run time for dynamic Enum type.

Type of enum and How to define in item.xml?

There are two type of enum type Static and Dynamic in Hybris 

A. Declare the static enum type

<enumtype code="Color" autocreate="true" generate="true">
            <value code="BLACK"/>
            <value code="RED"/>
</enumtype>

B. Declare the Dynamic enum type 

<enumtype code="Color" autocreate="true" generate="true">
            <value code="BLACK"/>
            <value code="RED"/>
</enumtype>

Need to add autocreate and generate as true to generate the Enum type and Enum class. and "dynamic=true" to generate the dynamic enum type.

How to use enum in hybris code?

We can use the enum in code as per below. 

ProductModel productModel = new ProductModel();
product.setColor(Color.BLACK);

How to set the value for dynamic enum. we can use script to add new Color type.

import de.hybris.platform.core.model.enumeration.EnumerationValueModel;
 
 EnumerationValueModel model = (EnumerationValueModel)modelService.create("TestForEnum");
 model.setCode("WHITE");
 model.setName("White");
 modelService.save(model);

Query to get detail for particular enum 

SELECT * FROM {enumerationvalue} WHERE {code}='White'

10 thoughts on “What is the enum type, How to use and define in Hybris ?”

  1. Перевозки грузов осуществляют ключевую задачу в хозяйстве любой страны.
    Эти услуги поддерживают стабильное обеспечение торговых точек и заводов всеми нужными материалами.
    Надёжная транспортировка способствует уменьшать сроки и расходы на перемещение продукции, что увеличивает прибыльность предприятий.
    В итоге, грузоперевозки являются неотъемлемым элементом нынешней инфраструктуры.
    https://perevozimgruz.by/

  2. Плановый диагностика является важной процедурой для обеспечения исправности машины.
    В ходе осмотра находятся скрытые неисправности, что могут вызвать аварии на трассе.
    Регулярное прохождение ТО дает возможность избежать серьёзных вложений на сложный восстановление позже.
    Помимо этого технически годный транспорт обеспечивает безопасность вашу и пассажиров на пути.
    Официальный техосмотр

  3. [2468]grab333 Official Login | Best Online Slots in Malaysia,grab333 offers the best online slots in Malaysia with a seamless app download and fast payouts for every winner. Join now to start your gaming journey. visit: grab333

  4. [1610]starbucks888 Official Login | Best Online Slots in Malaysia,starbucks888 offers a secure experience with fast payouts. Download the APK for mobile access and learn how to play baccarat today. Join the action now! visit: starbucks888

Leave a Comment

Your email address will not be published. Required fields are marked *