创建Addon扩展
在cmd命令提示符窗口,切换到YOURPATH\bin\platform,使用以下命令从platform的build.xml中运行extgen
ant extgen
输入模板yaddon,输入扩展名(例如:randomimageaddon)和包名de.hybris.platform.addons.randomimageaddon
extgen:
[input]
[input] Please choose a template for generation.
[input] Press [Enter] to use the default value ([yempty], yatddtests, yscala, ygroovy, yacceleratorfulfilmentprocess, merchandisefulfilmentprocess, ychinaacceleratorstorefront, yaddon, ycommercewebservices, ycommercewebservicestest, ycommercewebserviceshmc, ycockpit, ybackoffice)
yaddon
[input]
[input] Please choose the name of your extension. It has to start with a letter followed by letters and/or numbers.
[input] Press [Enter] to use the default value [training]
randomimageaddon
[input]
[input] Please choose the package name of your extension. It has to fulfill java package name convention.
[input] Press [Enter] to use the default value [org.training]
de.hybris.platform.addons.randomimageaddon
上述操作,将在YOURPATH\bin下自动生成如下1个自定义扩展
/custom/randomimageaddon
按照extgen output说明,完成localextensions.xml配置
[echo]
[echo] Next steps:
[echo]
[echo] 1) Add your extension to your E:\test\hybris\config/localextensions.xml
[echo]
[echo] <extension dir="E:\test\hybris\bin/custom/randomimageaddon"/>
[echo]
[echo] 2) Please remove all template extensions (again) before you proceed.
[echo]
[echo] 3) Make sure the applicationserver is stopped before you build the extension the first time.
[echo]
[echo] 4) Perform 'ant' in your hybris/platform directory.
[echo]
[echo] 5) Restart the applicationserver
[echo]
[echo]
修改Model定义
在/custom/randomimageaddon/resources/randomimageaddon-items.xml中添加CMS组件定义
修改资源文件/custom/randomimageaddon/resources/localization/randomimageaddon-locales_*.properties
在/custom/randomimageaddon/extensioninfo.xml中添加依赖
注意:完成上述操作之后,需做一次sytem update(勾选Update running system和Localize types即可),将更改推送到数据库,否则hmc中将不能查到该itemtype
定义组件视图
创建视图
/custom/randomimageaddon/acceleratoraddon/web/webroot/WEB-INF/views/desktop/cms/randomimageparagraphcomponent.jsp
定义组件Renderer
为AddOn CMS Component Renderer声明renderer和mapping bean
<bean id="randomImageParagraphComponentRenderer" parent="addOnJspIncludeCMSComponentRenderer" />
<bean id="randomImageParagraphComponentRendererMapping" parent="addonCmsComponentRendererMapping">
<property name="typeCode" value="RandomImageParagraphComponent" />
<property name="renderer" ref="randomImageParagraphComponentRenderer" />
</bean>
Build新加组件
使merchandisestorefront可以使用该新加组件,执行以下命令行
ant addoninstall -Daddonnames="randomimageaddon" -DaddonStorefront.yacceleratorstorefront="merchandisestorefront"
以上命令将会在/custom/merchandise/merchandisestorefront/extensioninfo.xml中添加对randomimageaddon的依赖
<requires-extension name="randomimageaddon"/>
同时在/custom/randomimageaddon/project.properties文件中提供额外的web-spring配置定义
merchandisestorefront.additionalWebSpringConfigs.randomimageaddon=classpath:/randomimageaddon/web/spring/randomimageaddon-web-spring.xml
再者,它还会复制web application content到storefront(需执行ant all命令,执行完成后,可在merchandisestorefront/web/webroot/WEB-INF/views/addons/randomimageaddon/desktop/cms下看到同样的.jsp文件)