是否可以从 local.properties 配置文件中定义的环境变量中获取一个值并通过 impex 文件访问它?
前任。
$someMacro=<some variable from config>
谢谢!
您可以将其添加到您的 impex 中:
# Import config properties into impex macros
UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]
来自 local.properties 等的所有配置现在都已加载,可以通过$config-
前缀使用,例如:
本地属性
your.config.property=322
所以你的 impex 看起来像:
# Import config properties into impex macros
UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]
$variable=$config-your.config.property
INSERT_UPDATE SampleItem;code[unique=true];name
;sample1;$variable
# OR you can just directly use the config macro
INSERT_UPDATE SampleItem;code[unique=true];name
;sample1;$config-your.config.property
希望这对你有用。
编辑:另请注意,如果没有找到此类属性,则存储在上述样本中的值应为:$config-your.config.property
。
要完成@Atsusa Kai answer,可以避免单独带有标题的行。
这行只是为了加载属性是相当丑陋的......但这实际上是ConfigPropertyImportProcessor
类注释中提到的:
/**
* Impex ImportProcessor that injects all config properties as impex definitions.
* All defined configuration properties are added as impex macro definitions with
* the prefix of "config-". For example the config key <tt>mail.smtp.server</tt>
* can be accessed via the macro <tt>$config-mail.smtp.server</tt>.
* In order to use this import processor and to load the configuration properties
* the following must be added to the top of the impex file:
*
* <tt>UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]</tt>
*/
另一种方法是使用为此类操作量身定制的 beanshell 命令。
您可以将 UPDATE GenericItem 行替换为
#%new de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor().init(impex)
但您需要启用代码执行。