Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

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.

  1. 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"/>
    
    	<bean id="shoppingItemDtoMapper"
    		class="com.extensions.tshirt.sfweb.controller.impl.ExtShoppingItemDtoMapperImpl"/>
    
    	<bean id="shoppingItemFormBean"
    		class="com.extensions.tshirt.sfweb.formbean.impl.ExtShoppingItemFormBeanImpl"/>
    
    	<bean id="tshirtProductConfigController" parent="defaultProductConfigController">
    		<property name="shoppingItemValidator" ref="tshirtFormBeanValidator"/>
    	</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"/>
    				<entry key="errorBackTextSize" value="errors.tshirt.back.text.too.long"/>
    			</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"/>
    				</entry>
    			</map>
    		</property>
    
    		<property name="bindingConfig">
    			<list merge="true">
    				<binding-config:binding pattern="cartItems[*].tshirtFields.frontText" policy="ignore"/>
    				<binding-config:binding pattern="cartItems[*].tshirtFields.backText" policy="ignore"/>
    			</list>
    		</property>
    	</bean>
    
                
  2. 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.
  3. 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:

  1. With the command prompt, navigate to the ext-storefront project directory and run:
    mvn install
  2. Navigate to ext-storefront-webapp and run:
    mvn install
  3. Deploy your extended storefront WAR to your web server.