Hybris 通过数据库在impex中包含数据

Hybris 通过数据库在impex中包含数据,hybris,impex,Hybris,Impex,这是我的弹劾: INSERT_UPDATE ReferenceProductAttributeValue;leaf(code,name[lang=de])[unique=true];newvalue(pk) 我必须输入newvalue(pk)单位的pk。p_code=“PCE”首先,我必须从我的数据库e中获取它。以下是我的查询,它在我的MySQL中运行得非常好: SELECT `units`.`PK` FROM `my_schema`.`units` WHERE `unit

这是我的弹劾:

    INSERT_UPDATE ReferenceProductAttributeValue;leaf(code,name[lang=de])[unique=true];newvalue(pk)
我必须输入newvalue(pk)单位的pk。p_code=“PCE”首先,我必须从我的数据库e中获取它。以下是我的查询,它在我的MySQL中运行得非常好:

      SELECT `units`.`PK` FROM `my_schema`.`units` WHERE `units`.`p_code`="PCE";
我试过这个:

    INSERT_UPDATE ReferenceProductAttributeValue;leaf(code,name[lang=de])[unique=true];newvalue(pk)
          ;001:Antiviren-Software (Client-Betriebssystem);
   "#% 
      impex.initDatabase( <myDburl>, <myUser>, <myPassword>, <MyDriver.class>);"
   "#% 
      impex.includeSQLData( 
      "" SELECT ""+
      "" units.PK ""+"" FROM my_schema.units ""+
      "" WHERE ""+
      "" units.p_code ='PCE'""
      );"
但它不起作用。有人能给我一个提示吗

新尝试:

     INSERT_UPDATE ReferenceProductAttributeValue;newvalue(pk);leaf(code,name[lang=de])[unique=true]
     #% beforeEach:
     #% import de.hybris.platform.core.model.product.UnitModel;
     #% import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
     #% import de.hybris.platform.jalo.flexiblesearch.* ;
     #% import de.hybris.platform.core.Registry;
     #% flexibleSearchService = Registry.getApplicationContext().getBean("flexibleSearchService");
     #% query = "SELECT {" + UnitModel.PK + "} FROM {" + UnitModel._TYPECODE + "} WHERE {" + UnitModel.CODE + "} = 'PCE' ";
     #% flexibleSearchQuery = new FlexibleSearchQuery(query);
     #% resultIterator = flexibleSearchService.search(flexibleSearchQuery).getResult().iterator().next();
     #% beforeEach: end \
     ;001:Antiviren-Software (Client-Betriebssystem)
现在我不再有任何错误,但仍然没有我在newvalue中搜索的pk。有人能帮我吗?谢谢

尝试使用代码

newvalue(code)[default='PCE']

因此,我的解决方案是,我制作了一个类似这样的翻译器(这只适用于像我这样的初学者,可能还有其他解决方案,但对我来说,这已经足够了,它确实有效。如果有经验的人希望改进代码,请……:

弹劾案是这样的:

INSERT_UPDATE ReferenceProductAttributeValue;leaf(code,name[lang=de])[unique=true];@newvalue[translator=com.myextension.core.impex.translators.UnitByCodeTranslator]
;001:AGP-Grafikkarte;PCE
INSERT_UPDATE ReferenceProductAttributeValue;leaf(code,name[lang=de][unique=true];newvalue(Unit.code); 
;001:AGP-Grafikkarte;PCE;
INSERT_UPDATE Unit;code[unique=true];$unitRef;
;pieces;PIECES_REF;
;cm;CM_REF;

解决方案取决于newValue的类型

如果其类型为Unit,您可以通过Unit类型的一个或多个属性来引用它,这些属性唯一地标识该项(例如代码):

如果它的类型更通用,比如Item,则需要使用该类型的唯一属性。项目的唯一唯一属性是PK。但是你不想通过PK来引用你的单位。因此,您可以通过在属性前面加上要引用的类型的typecode来定义应使用的类型:

newValue(Unit.code)
在一份完整的声明中,这将如下所示:

INSERT_UPDATE ReferenceProductAttributeValue;leaf(code,name[lang=de])[unique=true];@newvalue[translator=com.myextension.core.impex.translators.UnitByCodeTranslator]
;001:AGP-Grafikkarte;PCE
INSERT_UPDATE ReferenceProductAttributeValue;leaf(code,name[lang=de][unique=true];newvalue(Unit.code); 
;001:AGP-Grafikkarte;PCE;
INSERT_UPDATE Unit;code[unique=true];$unitRef;
;pieces;PIECES_REF;
;cm;CM_REF;

您还可以在使用&operator之前引用impex语句中使用的其他项。&运算符定义引用。您可以在标题中定义它们,如下所示:

INSERT_UPDATE ReferenceProductAttributeValue;leaf(code,name[lang=de])[unique=true];@newvalue[translator=com.myextension.core.impex.translators.UnitByCodeTranslator]
;001:AGP-Grafikkarte;PCE
INSERT_UPDATE ReferenceProductAttributeValue;leaf(code,name[lang=de][unique=true];newvalue(Unit.code); 
;001:AGP-Grafikkarte;PCE;
INSERT_UPDATE Unit;code[unique=true];$unitRef;
;pieces;PIECES_REF;
;cm;CM_REF;
然后,您可以稍后使用引用来引用值:

INSERT_UPDATE ReferenceProductAttributeValue;leaf(code,name[lang=de][unique=true];newvalue(&unitRef); 
;001:AGP-Grafikkarte;PIECES_REF;

:(,它不起作用,因为newvalueunit不是ReferenceProductAttributeValue的属性,我收到一个错误:“ImportScript ist ungültig:标题“INSERT_UPDATE ReferenceProductAttributeValue”中的未知属性“newvalueunit”.Code with value='PCE'是一个单位属性,我必须像newvalue中的pk一样放入类型为Item的属性和ReferenceProductAttributeValue的属性。最好在问题中添加数据模型详细信息(*items.xm)。使用此impex.HybrisHelp只是使用了错误的属性名称:INSERT_UPDATE ReferenceProductAttributeValue;leaf(code,name[lang=de])[unique=true];newvalue(code);;001:AGP-Grafikkarte;PCE;@JohannesNolte-谢谢,让我更正属性名(newvalue)!!这太复杂了。这要简单得多:INSERT_UPDATE ReferenceProductAttributeValue;leaf(code,name[lang=de])[unique=true];newvalue(code);001:AGP-Grafikkarte;PCE;这并不容易,我已经尝试过了。newvalue是一个项目,我不允许更改它,这就是为什么我第一次尝试在impex中实现它,但我不知道为什么它不起作用。在这种情况下,尝试:INSERT_UPDATE ReferenceProductAttributeValue;leaf(代码,名称[lang=de])[unique=true];newvalue(Unit.code);;001:AGP-Grafikkarte;PCE;nop…它不起作用。我反复尝试了。newvalue只接受pk。