Types 我的hybris车型属于哪种类型?

Types 我的hybris车型属于哪种类型?,types,model,hybris,Types,Model,Hybris,在我的hybris事件监听器中,我有一个项目的PK,而不是模型项目。如何判断此PK所属项目的类型 在hybris wiki中,他们给出了以下示例,以便您知道某个项目属于Product类型: //The product deployment code is "1" if (1 == pk.getTypeCode()) { final ProductModel product = modelService.get(pk); //Put your business code here

在我的hybris事件监听器中,我有一个项目的PK,而不是模型项目。如何判断此PK所属项目的类型

在hybris wiki中,他们给出了以下示例,以便您知道某个项目属于Product类型:

//The product deployment code is "1"
if (1 == pk.getTypeCode())
{
    final ProductModel product = modelService.get(pk);
    //Put your business code here
}

但是我不喜欢硬编码我要处理的类型的类型代码。

要不硬编码源代码中的类型代码,您必须首先在数据库中找到您的项目,然后您可以通过两种不同的方式找到它的类型:

final ItemModel item = modelService.get(pk);

if (ProductModel._TYPECODE.equals(item.getItemtype()))
{
    LOG.debug("ProductModel being edited");
}

//or

if (item instanceof ProductModel) {
    LOG.debug("ProductModel being edited");
}

虽然这可能会减慢AfterSaveEvent侦听器中的速度,但因为在hybris服务器中编辑、创建或删除的每个对象都会调用此侦听器

HAC可用于查找Hybris系统中定义类型的类型代码:

转到::/hac/维护/部署

这将为您提供以下信息:

  • 类型码
  • 桌子
  • 类型
  • 延伸

  • 下面是在hybris 4.x中执行此操作的示例groovy脚本

    import de.hybris.platform.core.PK;
    import de.hybris.platform.jalo.type.TypeManager; // this class is deprecated though
    
    def pkString = 8796093054980; // PK of admin
    def typeService = ctx.getBean("typeService");
    def modelService= ctx.getBean("modelService");
    
    def composedType = TypeManager.getInstance().getRootComposedType(PK.fromLong(pkString).getTypeCode());
    def composedTypeModel = modelService.toModelLayer(composedType);
    out.println typeService.getModelClass(composedTypeModel);
    
    结果:类de.hybris.platform.core.model.user.UserModel