Page 1 of 1

checkout workflow

Posted: Mon Jan 13, 2014 2:34 am
by nanix84
Im currently working on a checkout activity that is within the checkout workflow.

here's the checkout workflow modification:

Code: Select all

<bean id="blCheckoutWorkflow" class="org.broadleafcommerce.core.workflow.SequenceProcessor">
        <property name="processContextFactory">
            <bean class="org.broadleafcommerce.core.checkout.service.workflow.CheckoutProcessContextFactory"/>
        </property>
        <property name="activities">
            <list>
                <ref bean="blVerifyCustomerMaxOfferUsesActivity" />
                <ref bean="blPaymentServiceActivity" />
                <ref bean="blRecordOfferUsageActivity" />
                <ref bean="blCommitTaxActivity" />
                <ref bean="blCompleteOrderActivity" />
                <ref bean="ServiceCreateOrderActivity" />
                <ref bean="ServiceValidateOrderActivity" />
            </list>
        </property>
        <property name="defaultErrorHandler" ref="blDefaultErrorHandler"/>
    </bean>

I have added two activities that performs Create/Validate order from broadleaf to an external web service.

Code: Select all

public class ServiceCreateOrderActivity extends BaseActivity<CheckoutContext> {

   @Override
   public CheckoutContext execute(CheckoutContext context) throws Exception {
             CheckoutSeed seed = context.getSeedData();
        Order cart = seed.getOrder();
             try {
                  // perform the create order to be sent to a webservice
             } catch(AxisFault e) {
                  e.printStackTrace();
                  context.stopProcess();
                  throw new MyOrderResponseFailedException("Unable to process request. Service Response failed.");
             }
        }

when an exception has occured, it will just throw the Exception I created and handle it on the site project.
under CheckoutController

Code: Select all

@RequestMapping(value = "/complete", method = RequestMethod.POST)
    public ModelAndView completeSecureCreditCardCheckout(@Context HttpServletRequest request, HttpServletResponse response, Model model,
            @ModelAttribute("orderInfoForm") OrderInfoForm orderInfoForm,
            @ModelAttribute("shippingInfoForm") ShippingInfoForm shippingForm,
            @ModelAttribute("billingInfoForm") BillingInfoForm billingForm,
            BindingResult result) throws CheckoutException, PricingException, ServiceException {
        prepopulateCheckoutForms(CartState.getCart(), null, shippingForm, billingForm);
        System.out.println("complete secure card checkout");
        String csCCC = "";
        try {
           csCCC = super.completeSecureCreditCardCheckout(request, response, model, billingForm, result);
        } catch (CheckoutException e) {
           System.out.println(e.getCause().getMessage());
           model.addAttribute("hasActivityError", true);
           model.addAttribute("error", e.getCause().getMessage());
           csCCC = getCheckoutPageRedirect();
        }
        return new ModelAndView(csCCC);
    }

The main problem I am encountering is that, It has no more cart items coz it redirects to cart complete.
How will I make it "not" discard the cart items? Is there some kind of rollback functionality? Because I think broadleaf handles the rollback state part but im not sure how to do it.

Thanks

Re: checkout workflow

Posted: Mon Jan 13, 2014 1:52 pm
by phillipuniverse
Sounds like you need to put your activities that communicate with the web service prior to the blCompleteOrderActivity. That activity should always be last; it changes the order status to SUBMITTED. In your case, there might be some exception that gets thrown with the web service communication so that needs to come before the complete order activity.

Also, dunno if you've actually declared this in your XML file, but you don't need to redeclare the entire workflow as of BLC 2.3+. You can simply redeclare the workflow with your new activities and a specific order so that they will be merged together. See http://docs.broadleafcommerce.org/core/ ... activities.