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

Plug-in architecture

Plug-in architecture

Elastic Path Core Commerce uses a lightweight plug-in architecture based on Spring functionality. This architecture allows you to create plug-ins that work seamlessly with existing Core Commerce modules, without needing to make any changes to the core application code or configuration files.

The elastic-path-servlet.xml in the storefront web application contains the following statement:

<import resource="classpath*:META-INF/conf/ep-storefront-plugin.xml"/>

This statement causes the storefront to automatically include any JAR file on the classpath that contains a META-INF/conf/ep-storefront-plugin.xml file. Now, you just need to put your plug-in's JAR file in the storefront webapp's WEB-INF/lib directory and it will be deployed automatically at startup. The META-INF/conf/ep-storefront-plugin.xml file contains your plug-in's configuration (bean definitions, etc.).

Overriding Existing Bean Definitions

Replacing a Bean

To completely override an existing bean definition in your webapp extension, in your webapp JAR extension's plugin.xml, you define a new bean with the exact same bean id as the bean you are overriding.

For example, suppose you want to override the cartFormBeanFactory bean in ep-storefront\src\main\resources\spring\service\serviceSF.xml:

                  storefront/ep-storefront/src/main/resources/spring/service/serviceSF.xml
	<bean id="cartFormBeanFactoryTemplate" abstract="true"
		class="com.elasticpath.sfweb.controller.impl.ShoppingItemFormBeanContainerFactoryImpl" >
        <property name="productSkuLookup" ref="productSkuLookup" />
        <property name="productViewService" ref="productViewService" />
		<property name="storeProductService" ref="storeProductService" />
        <property name="priceLookupFacade" ref="priceLookupFacade" />
        <property name="jsonBundleFactory" ref="jsonBundleFactory"/>
        <property name="jsonBundleService" ref="jsonBundleService"/>
		<property name="loadProductAssociations" value="true"/>
		<property name="beanFactory" ref="coreBeanFactory" />
	 	<property name="shoppingItemAssembler" ref="shoppingItemAssembler" />
	 	<property name="cartDirector" ref="cartDirector" />
		<property name="cartDirectorService" ref="cartDirectorService" />
	 	<property name="requestHelper" ref="requestHelper"/>
	</bean>

	<bean id="cartFormBeanFactory" parent="cartFormBeanFactoryTemplate" />

               

In your storefront JAR extension's ep-storefront-plugin.xml, you would add the following:

<bean id="cartFormBeanFactory" parent="cartFormBeanFactoryTemplate"
    class="com.extensions.tshirt.sfweb.controller.impl.ExtShoppingItemFormBeanContainerFactoryImpl">

Extending an existing bean

However, you may want to change only the configuration parameters of an existing bean definition, or override just the implementation class. There is a way to so this without replacing the entire bean definition. To do this, you need to use the PluginBeanFactoryPostProcessor.

The com.elasticpath.commons.util.impl.PluginBeanFactoryPostProcessor class is an implementation of the Spring BeanFactoryPostProcessor interface. Spring invokes this after all of the configuration has been discovered and loaded in memory, but before the actual objects are created.

Below is a PluginBeanFactoryPostProcessor bean definition:

<bean class="com.elasticpath.commons.util.impl.PluginBeanFactoryPostProcessor">
  <property name="extensionBeanName">
    <value>EXTENSION_BEAN_NAME</value>
  </property>
  <property name="extensionClassName">
    <value>EXTENSION_CLASS_NAME</value>
  </property>
  <property name="propertyName">
    <value>PROPERTY_NAME</value>
  </property>
  <property name="propertyValue">
    <ref bean="PROPERTY_VALUE"/>
  </property>
</bean>

To override or extend an existing built-in bean, add a PluginBeanFactoryPostProcessor bean definition in your webapp JAR extension's plugin.xml and specify the following properties:

Property Description

extensionBeanName

The name of the bean you want to override.

extensionClassName

The class to set the overridden bean to use. (This property can be omitted if you don't need to change the bean class that was assigned in the original bean definition.)

propertyName

The name of the property to override or add. (This can be ommitted if you are not changing any properties)

propertyValue

The value you want to assign to the property.

For example, suppose the default configuration contains the following bean definition:

<bean id="authenticationProcessingFilter"
      class="com.elasticpath.sfweb.filters.EpAuthenticationProcessingFilter">
  <property name="webCustomerSessionService">
    <ref bean="webCustomerSessionService"/>
  </property>
  <property name="authenticationManager">
    <ref bean="authenticationManager"/>
  </property>
  <property name="authenticationFailureUrl">
    <value>/sign-in.ep?login_failed=1</value>
  </property>
  <property name="defaultTargetUrl">
    <value>/manage-account.ep</value>
  </property>
  <property name="filterProcessesUrl">
    <value>/j_acegi_security_check.ep</value>
  </property>
</bean>

The following bean definition can be included in a plugin.xml file to override the original bean definition of authenticationProcessingFilter:

<bean class="com.elasticpath.commons.util.impl.PluginBeanFactoryPostProcessor">
  <property name="extensionBeanName">
    <value>authenticationProcessingFilter</value>
  </property>
  <property name="extensionClassName">
    <value>com.elasticpath.plugins.custom_authenticator.filters.CustomAuthenticationProcessingFilter</value>
  </property>
  <property name="propertyName">
    <value>customerService</value>
  <property name="propertyValue">
    <ref bean="customerService"/>
  </property>
</bean>

In this example, the default EpAuthenticationProcessingFilter implementation is replaced by CustomAuthenticationProcessingFilter, which includes a new property named customerService.

Overriding multiple properties

To override multiple properties on a particular bean, use the propertiesMap property as follows:

<property name="propertiesMap">
  <map>
    <entry key="customerService">
      <ref bean="customerService"/>
    </entry>
    <entry key="elasticPath">
      <ref bean="elasticPath"/>
    </entry>
  </map>
</property>
Note:

Functionality can be added to this architecture by modifying the PluginBeanFactoryPostProcessor.postProcessBeanFactory() method implementation. For example, you could add an extendList property to allow a property value to add to a bean's list property rather than overwrite it.