try
{
tx = s.beginTransaction( );
/* Customer */
Customer cst = ( Customer ) s.load( Customer.class, getUserId( ) );
/* Order + Items*/
Order order = new Order( cst );
Map cart = getCart( );
Iterator it = cart.keySet( ).iterator( );
while ( it.hasNext( ) )
{
String itemId = ( String ) it.next( );
Item item = ( Item ) s.load( Item.class, itemId );
Integer quantity = ( Integer ) cart.get( itemId );
order.add( item, quantity.intValue( ) );
}
/* Save */
s.save( order );
tx.commit( );
/* Empty the cart */
getCart( ).clear( );
/* send the email */
String subject = "[xpetstore] Order Confimation";
String body = "Your order has been submitted.\nThe order number is: " + order.getOrderId( );
try
{
MailUtil.send( cst.getEmail( ), subject, body );
}
catch ( Exception e )
{
_log.error( "Unexpected error while sending email", e );
}