Documentation Home

1.6 to 2.0 Order Service Migration

Migrating to the new workflow pattern

If possible, we recommend leveraging this pattern as it is much more customizable and leads to providing self-contained units of work. If you choose this route, your configuration will resemble the following.

Note: By default, using the workflow pattern will also affect Fulfillment Group Items. Please see the fulfillment group strategy migration notes for more information.

First, you need to override a certain workflow. In this example, we'll override blAddItemWorkflow. You would likely also want to override the update cart and remove item workflows. To do this, we will copy the default workflow from Broadleaf and put it in our applicationContext.xml so that we are able to modify the activities within.

<bean id="blAddItemWorkflow" class="org.broadleafcommerce.core.workflow.SequenceProcessor">
    <property name="processContextFactory">
        <bean class="org.broadleafcommerce.core.order.service.workflow.CartOperationProcessContextFactory"/>
    </property>
    <property name="activities">
        <list>
            <bean class="org.broadleafcommerce.core.order.service.workflow.add.ValidateAddRequestActivity"/>
            <bean class="org.broadleafcommerce.core.order.service.workflow.CheckAvailabilityActivity"/>
            <bean class="org.broadleafcommerce.core.order.service.workflow.add.AddOrderItemActivity"/>
            <bean class="org.broadleafcommerce.core.order.service.workflow.add.AddFulfillmentGroupItemActivity"/>
            <bean class="org.broadleafcommerce.core.order.service.workflow.VerifyFulfillmentGroupItemsActivity"/>
        </list>
    </property>
    <property name="defaultErrorHandler" ref="blSilentErrorHandler"/>
</bean>

You can find the default workflows in the following place in the Broadleaf codebase: core/broadleaf-framework/src/main/resources/bl-framework-applicationContext-workflow.xml

Next, you will want to evaluate whether the new default activities make sense in your application. We recommend not removing any activities unless you have an explicit need to do so.

Finally, you will want to determine if you need to create any additional activities to handle your specific business logic. We've provided a tutorial on creating activities for your reference.

Using the legacy order services

  • Any classes that extend OrderService or CartService must be updated to extend the legacy versions

  • You must tell Broadleaf that you want to use the legacy services by overriding the blOrderService bean. This is done in the same way normal service extension happens, by placing the following line in your applicationContext.xml file:

<bean id="blOrderService" class="org.broadleafcommerce.core.order.service.legacy.LegacyCartServiceImpl" />

Note: If you are extending LegacyCartServiceImpl, you should instead use the fully qualified name of your class.