1 4 package com.openedit.store; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 9 import com.openedit.WebPageRequest; 10 import com.openedit.modules.email.PostMail; 11 import com.openedit.modules.email.Recipient; 12 import com.openedit.modules.email.TemplateWebEmail; 13 import com.openedit.page.Page; 14 import com.openedit.page.manage.PageManager; 15 16 20 public class EmailOrderArchive extends BaseOrderArchive implements OrderArchive 21 { 22 private static final Log log = LogFactory.getLog( EmailOrderArchive.class ); 23 protected PageManager fieldPageManager; 24 private PostMail postMail; 25 26 public PostMail getPostMail() { 27 return postMail; 28 } 29 30 public void setPostMail(PostMail postMail) { 31 this.postMail = postMail; 32 } 33 34 37 public void exportNewOrder( WebPageRequest inContext, Store inStore, 38 Order inOrder ) throws StoreException 39 { 40 try 41 { 42 Page clerkLayout= getPageManager().getPage(inStore.getOrderLayout() ); 44 if (!clerkLayout.exists()) { 45 throw new StoreException("Clerklayout" + clerkLayout + "does not exist or is invalid"); 46 } 47 Page customerLayout = getPageManager().getPage(inStore.getEmailLayout() ); 48 if (!customerLayout.exists()) { 49 throw new StoreException("Customerlayout" + customerLayout + "does not exist or is invalid"); 50 } 51 52 TemplateWebEmail mailer = postMail.getTemplateWebEmail(); 53 mailer.setFrom( inStore.getFromAddress() ); 54 mailer.setWebPageContext(inContext); 55 mailer.setSubject( inStore.getName() + " New Order Notification" ); 57 58 if ( inStore.getToAddresses().size() > 0) 59 { 60 mailer.setRecipientsFromStrings(inStore.getToAddresses()); 61 mailer.setMailTemplatePage(clerkLayout); 62 mailer.send(); 63 } 64 mailer.setSubject( inStore.getName() + " Order Confirmation" ); 66 String email = inOrder.getCustomer().getEmail(); 67 Recipient recipient = new Recipient(); 68 recipient.setEmailAddress(email); 69 recipient.setLastName(inOrder.getCustomer().getLastName()); 70 recipient.setFirstName(inOrder.getCustomer().getFirstName()); 71 mailer.setRecipient(recipient); 72 mailer.setMailTemplatePage(customerLayout); 73 mailer.send(); 74 75 inOrder.getOrderState().setOk(true); 77 78 } 79 catch ( Exception e ) 80 { 81 log.error( "Could not email this order request:\n" 82 + inOrder.getCustomer(), e ); 83 inOrder.getOrderState().setDescription("Order could not be sent " + e.getMessage()); 84 inOrder.getOrderState().setOk(false); 85 throw new StoreException( e ); 86 } 87 } 88 89 93 protected boolean requiresValidation(Order inOrder) 94 { 95 96 return inOrder.getPaymentMethod().requiresValidation(); 97 } 98 protected PageManager getPageManager() 99 { 100 return fieldPageManager; 101 } 102 public void setPageManager(PageManager inPageManager) 103 { 104 fieldPageManager = inPageManager; 105 } 106 107 108 } | Popular Tags |