Page 1 of 1

Customizing checkout with additional fields

Posted: Tue May 20, 2014 7:20 am
by ArloL
Hey guys,

I am trying to customize the existing checkout by adding two additional string inputs that the user has to fill out. I couldnt really find any information/documentation pointing me in the right direction. Does anyone else have an idea where I can find some info?

Thanks in advance!

Re: Customizing checkout with additional fields

Posted: Wed May 21, 2014 2:22 am
by prabhat.kataria
You can look into "com.mycompany.controller.checkout" package to make changes. In this package you will find classes which has entry point of checkout actions.

Re: Customizing checkout with additional fields

Posted: Wed Jun 04, 2014 5:06 am
by ArloL
Thanks prabhat.kataria. I had already looked there but didn't find something helpful.

Nonetheless I found a solution:

I extended OnePageCheckoutProcessor to include another CheckoutSectionViewType. Add a VehicleInfoForm holding the values for the new form and added a partial in templates/checkout/partials/vehicleInfoForm.html. This I also included in checkout.html. I had to add a @ModelAttribute("vehicleInfoForm") VehicleInfoForm vehicleInfoForm to all methods where the other forms where parameters in CheckoutController and BillingInfoController. Make sure it's not the last parameter.

I then added another method to CheckoutController:

@RequestMapping(
value = "/checkout/savevehicle",
method = RequestMethod.POST)
public String saveVehicleDetails(
HttpServletRequest request,
Model model,
@ModelAttribute("shippingInfoForm") ShippingInfoForm shippingForm,
@ModelAttribute("billingInfoForm") BillingInfoForm billingForm,
@ModelAttribute("giftCardInfoForm") GiftCardInfoForm giftCardInfoForm,
@ModelAttribute("orderInfoForm") OrderInfoForm orderInfoForm,
@ModelAttribute("vehicleInfoForm") VehicleInfoForm vehicleInfoForm,
BindingResult result) throws ServiceException {
Order cart = CartState.getCart();

vehicleInfoFormValidator.validate(vehicleInfoForm, result);
if (result.hasErrors()) {
return getCheckoutView();
}

OrderAttribute vehicleIdentification =
getOrderAttribute(cart, "vehicleIdentification");
OrderAttribute numberPlate = getOrderAttribute(cart, "numberPlate");

try {
vehicleIdentification.setValue(vehicleInfoForm
.getVehicleIdentification());
numberPlate.setValue(vehicleInfoForm.getNumberPlate());
orderService.save(cart, false);
} catch (PricingException pe) {
LOG.error(
"Error when saving the vehicle identification for order confirmation to the cart",
pe);
}

return getCheckoutPageRedirect();
}