4 - Wiring in custom beans
4 - Wiring in custom beans
After extending a number of Storefront classes, you need to tell Storefront to use your extension classes instead of the out of the box classes. To do this, you need to replace some Java Bean definitions.
- In ext-storefront/src/main/resources/META-INF/conf/ep-storefront-plugin.xml,
insert the following beans under
the <beans> tag:
CoreTutorial2/tutorial2-ext-storefront/src/main/resources/META-INF/conf/ep-storefront-plugin.xml <bean id="cartFormBeanFactory" parent="cartFormBeanFactoryTemplate" class="com.extensions.tshirt.sfweb.controller.impl.ExtShoppingItemFormBeanContainerFactoryImpl"/commerce-legacy/> <bean id="shoppingItemDtoMapper" class="com.extensions.tshirt.sfweb.controller.impl.ExtShoppingItemDtoMapperImpl"/commerce-legacy/> <bean id="shoppingItemFormBean" class="com.extensions.tshirt.sfweb.formbean.impl.ExtShoppingItemFormBeanImpl"/commerce-legacy/> <bean id="tshirtProductConfigController" parent="defaultProductConfigController"> <property name="shoppingItemValidator" ref="tshirtFormBeanValidator"/commerce-legacy/> </bean> <bean id="tshirtFormBeanValidator" class="com.extensions.tshirt.sfweb.formbean.validator.impl.TshirtFormBeanValidator" parent="productFormBeanValidator"> <property name="errorCodeMap"> <map> <entry key="errorFrontTextSize" value="errors.tshirt.front.text.too.long"/commerce-legacy/> <entry key="errorBackTextSize" value="errors.tshirt.back.text.too.long"/commerce-legacy/> </map> </property> </bean> <bean id="shoppingItemConfigController" parent="shoppingItemConfigControllerTemplate"> <!-- This property contains the map from type names to the ProductConfigController which handles the specialisation. --> <property name="productTypeNameControllerMap"> <map merge="true"> <entry> <!-- product type name --> <key> <value>T-shirt</value> </key> <ref bean="tshirtProductConfigController"/commerce-legacy/> </entry> </map> </property> <property name="bindingConfig"> <list merge="true"> <binding-config:binding pattern="cartItems[*].tshirtFields.frontText" policy="ignore"/commerce-legacy/> <binding-config:binding pattern="cartItems[*].tshirtFields.backText" policy="ignore"/commerce-legacy/> </list> </property> </bean>
- These beans wire in the custom TshirtFormBean and the TshirtFormBeanValidator, wire in your extensions to the out of the box Storefront classes, and binds the data submitted in the t-shirt form fields.
- In ext-storefront/src/main/resources/META-INF/conf/ep-storefront-plugin.xml, add the definition for the binding-config property by replacing the <beans> tag with the following:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:binding-config="http://www.elasticpath.com/schema/binding-config" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.elasticpath.com/schema/binding-config http://www.elasticpath.com/schema/binding-config/binding-config.xsd">
Building the Extensions
After wiring in your Storefront extension classes, you are ready to build and deploy the Storefront extension:
- With the command prompt, navigate to the ext-storefront project directory and run:
mvn install
- Navigate to ext-storefront-webapp and run:
mvn install
- Deploy your extended storefront WAR to your web server.