1 5 package com.dotmarketing.portlets.order_manager.action; 6 7 import java.net.URLDecoder ; 8 import java.util.Date ; 9 import java.util.List ; 10 11 import javax.portlet.ActionRequest; 12 import javax.portlet.ActionResponse; 13 import javax.portlet.PortletConfig; 14 import javax.servlet.http.HttpServletRequest ; 15 import javax.servlet.http.HttpSession ; 16 17 import org.apache.commons.beanutils.BeanUtils; 18 import org.apache.struts.Globals; 19 import org.apache.struts.action.ActionForm; 20 import org.apache.struts.action.ActionMapping; 21 import org.apache.struts.action.ActionMessage; 22 import org.apache.struts.action.ActionMessages; 23 24 import com.dotmarketing.beans.Host; 25 import com.dotmarketing.beans.UserProxy; 26 import com.dotmarketing.cms.factories.PublicAddressFactory; 27 import com.dotmarketing.db.DotHibernate; 28 import com.dotmarketing.factories.HostFactory; 29 import com.dotmarketing.factories.InodeFactory; 30 import com.dotmarketing.factories.UserProxyFactory; 31 import com.dotmarketing.portal.struts.DotPortletAction; 32 import com.dotmarketing.util.Config; 33 import com.dotmarketing.util.CreditCardProcessor; 34 import com.dotmarketing.util.CreditCardProcessorException; 35 import com.dotmarketing.util.CreditCardProcessorResponse; 36 import com.dotmarketing.util.Logger; 37 import com.dotmarketing.util.Mailer; 38 import com.dotmarketing.util.UtilMethods; 39 import com.dotmarketing.util.WebKeys; 40 import com.liferay.portal.ejb.UserLocalManagerUtil; 41 import com.liferay.portal.model.Address; 42 import com.liferay.portal.model.User; 43 import com.liferay.portal.util.Constants; 44 import com.liferay.portlet.ActionRequestImpl; 45 import com.dotmarketing.cms.product.model.Holder; 46 import com.dotmarketing.cms.product.model.ShoppingCart; 47 import com.dotmarketing.portlets.discountcode.model.DiscountCode; 48 import com.dotmarketing.portlets.order_manager.factories.OrderFactory; 49 import com.dotmarketing.portlets.order_manager.factories.OrderItemFactory; 50 import com.dotmarketing.portlets.order_manager.model.Order; 51 import com.dotmarketing.portlets.order_manager.model.OrderItem; 52 import com.dotmarketing.portlets.order_manager.struts.OrderForm; 53 import com.dotmarketing.portlets.organization.model.Organization; 54 import com.dotmarketing.portlets.product.factories.ProductFormatFactory; 55 import com.dotmarketing.portlets.product.model.ProductFormat; 56 import com.dotmarketing.portlets.product.model.ProductPrice; 57 import com.dotmarketing.util.CalculateShippingAndHandling; 58 import com.dotmarketing.viewtools.ProductWebAPI; 59 60 64 public class ViewCheckOutAction extends DotPortletAction { 65 public void processAction( 66 ActionMapping mapping, ActionForm form, PortletConfig config, 67 ActionRequest req, ActionResponse res) 68 throws Exception { 69 Logger.debug(this,"START LOAD PRODUCTS ACTION"); 70 String cmd = (req.getParameter(Constants.CMD)!=null)? req.getParameter(Constants.CMD) : ""; 71 String referrer = req.getParameter("referrer"); 72 OrderForm orderForm = (OrderForm) form; 73 74 75 if ((referrer!=null) && (referrer.length()!=0)) 76 { 77 referrer = URLDecoder.decode(referrer,"UTF-8"); 78 } 79 80 DotHibernate.startTransaction(); 81 82 if ((cmd != null) && cmd.equals(Constants.VIEW)) { 83 try 84 { 85 _retrieveCheckOut(req, res, config, form); 86 } 87 catch (Exception ae) 88 { 89 _handleException(ae, req); 90 } 91 } 92 95 else if ((cmd != null) && cmd.equals(Constants.UPDATE)) { 96 try 97 { 98 _loadAmount(req,res,config,form); 99 } 100 catch (Exception ae) 101 { 102 _handleException(ae, req); 103 } 104 } 105 else if ((cmd != null) && cmd.equals(Constants.ADD)) { 106 try 107 { 108 ActionMessages ae = orderForm.validateBackEnd(); 109 if(ae != null && ae.size() > 0) 110 { 111 HttpServletRequest httpServletRequest = ((ActionRequestImpl) req).getHttpServletRequest(); 112 HttpSession session = httpServletRequest.getSession(); 113 session.setAttribute(WebKeys.SHOPPING_CART_ERRORS, ae); 114 generateToken(httpServletRequest); 115 saveToken(httpServletRequest); 116 saveErrors(httpServletRequest,ae); 117 setForward(req,"portlet.ext.order_manager.view_checkOut"); 118 } 119 else 120 { 121 if (_saveOrder(req,res,config,form)) 122 return; 123 } 124 } 125 catch (Exception ae) 126 { 127 _handleException(ae, req); 128 } 129 } 130 131 DotHibernate.commitTransaction(); 132 133 OrderForm orderFormAux = new OrderForm(); 134 BeanUtils.copyProperties(orderFormAux,orderForm); 135 136 req.setAttribute("orderFormAux",orderFormAux); 137 138 setForward(req, "portlet.ext.order_manager.view_checkOut"); 139 Logger.debug(this,"END LOAD PRODUCTS ACTION"); 140 } 141 142 private void _retrieveCheckOut(ActionRequest request,ActionResponse res,PortletConfig config,ActionForm form) 143 { 144 try 145 { 146 HttpSession session = ((ActionRequestImpl)request).getHttpServletRequest().getSession(); 147 ShoppingCart shoppingCart = (ShoppingCart)session.getAttribute(WebKeys.SHOPPING_CART); 148 149 User userSession = shoppingCart.getUser(); 150 OrderForm orderForm = (OrderForm) form; 151 153 String userId = userSession.getUserId(); 154 String companyId = com.dotmarketing.cms.factories.PublicCompanyFactory.getDefaultCompany().getCompanyId(); 155 User user = UserLocalManagerUtil.getUserById(companyId, userId); 157 List addresses = PublicAddressFactory.getAddressesByUserId(user.getUserId()); 158 int posAux = -1; 159 for (int i=0; i<addresses.size();i++){ 160 Address address = (Address) addresses.get(i); 161 if ((address.getDescription() != null) && (address.getDescription().toLowerCase().equals("home"))){ 162 orderForm.setHomeAddress1(address.getStreet1()); 163 orderForm.setHomeAddress2(address.getStreet2()); 164 orderForm.setHomeCity(address.getCity()); 165 orderForm.setHomeCountry(address.getCountry()); 166 if (address.getCountry()==null || address.getCountry().equals(Config.getStringProperty("DEFAULT_COUNTRY_CODE"))) { 167 orderForm.setHomeCountry(Config.getStringProperty("DEFAULT_COUNTRY_CODE")); 168 orderForm.setHomeState(address.getState()); 169 } 170 else{ 171 orderForm.setHomeState("otherCountry"); 172 orderForm.setHomeStateOtherCountryText(address.getState()); 173 } 174 orderForm.setHomeZip(address.getZip()); 175 orderForm.setHomeContactName(user.getFullName()); 176 orderForm.setHomeContactPhone(address.getPhone()); 177 orderForm.setHomeContactEmail(user.getEmailAddress()); 178 orderForm.setHomePhone(address.getPhone()); 179 orderForm.setHomeFax(address.getFax()); 180 } 181 if ((address.getDescription() != null) && (address.getDescription().toLowerCase().equals("work"))){ 182 posAux = i; 183 orderForm.setWorkAddress1(address.getStreet1()); 184 orderForm.setWorkAddress2(address.getStreet2()); 185 orderForm.setWorkCity(address.getCity()); 186 orderForm.setWorkCountry(address.getCountry()); 187 if (address.getCountry()==null || address.getCountry().equals(Config.getStringProperty("DEFAULT_COUNTRY_CODE"))) { 188 orderForm.setWorkCountry(Config.getStringProperty("DEFAULT_COUNTRY_CODE")); 189 orderForm.setWorkState(address.getState()); 190 } 191 else{ 192 orderForm.setWorkState("otherCountry"); 193 orderForm.setWorkStateOtherCountryText(address.getState()); 194 } 195 orderForm.setWorkZip(address.getZip()); 196 orderForm.setWorkContactName(user.getFullName()); 197 orderForm.setWorkContactPhone(address.getPhone()); 198 orderForm.setWorkContactEmail(user.getEmailAddress()); 199 orderForm.setWorkPhone(address.getPhone()); 200 orderForm.setWorkFax(address.getFax()); 201 } 202 } 203 Address address; 204 if (posAux > -1) 206 address = (Address) addresses.get(posAux); 207 else 208 address = (Address) addresses.get(0); 209 orderForm.setBillingAddressType(address.getDescription()); 211 orderForm.setBillingAddress1(address.getStreet1()); 212 orderForm.setBillingAddress2(address.getStreet2()); 213 orderForm.setBillingCity(address.getCity()); 214 orderForm.setBillingCountry(address.getCountry()); 215 if (address.getCountry()==null || address.getCountry().equals(Config.getStringProperty("DEFAULT_COUNTRY_CODE"))) { 216 orderForm.setBillingCountry(Config.getStringProperty("DEFAULT_COUNTRY_CODE")); 217 orderForm.setBillingState(address.getState()); 218 } 219 else{ 220 orderForm.setBillingState("otherCountry"); 221 orderForm.setBillingStateOtherCountryText(address.getState()); 222 } 223 orderForm.setBillingZip(address.getZip()); 224 orderForm.setBillingContactName(user.getFullName()); 225 orderForm.setBillingContactPhone(address.getPhone()); 226 orderForm.setBillingContactEmail(user.getEmailAddress()); 227 orderForm.setBillingPhone(address.getPhone()); 228 orderForm.setBillingFax(address.getFax()); 229 230 orderForm.setShippingAddressType(address.getDescription()); 232 orderForm.setShippingAddress1(address.getStreet1()); 233 orderForm.setShippingAddress2(address.getStreet2()); 234 orderForm.setShippingCity(address.getCity()); 235 if (address.getCountry()==null || address.getCountry().equals(Config.getStringProperty("DEFAULT_COUNTRY_CODE"))){ 236 orderForm.setShippingCountry(Config.getStringProperty("DEFAULT_COUNTRY_CODE")); 237 orderForm.setShippingState(address.getState()); 238 } 239 else{ 240 orderForm.setShippingState("otherCountry"); 241 orderForm.setShippingStateOtherCountryText(address.getState()); 242 orderForm.setShippingCountry(address.getCountry()); 243 } 244 orderForm.setShippingZip(address.getZip()); 245 orderForm.setShippingPhone(address.getPhone()); 246 orderForm.setShippingFax(address.getFax()); 247 String addressType = address.getDescription(); 248 if (addressType != null) 249 if (addressType.equals("work")){ 250 UserProxy up = UserProxyFactory.getUserProxy(userId); 251 Organization org = (Organization) InodeFactory.getParentOfClass(up, Organization.class); 252 if (org.getInode() > 0){ 253 orderForm.setShippingLabel(org.getTitle()!=null?org.getTitle():""); 254 } 255 } 256 _loadAmount(request,res,config,form); 257 } 258 catch(Exception ex) 259 { 260 Logger.debug(this,ex.toString()); 261 } 262 } 263 264 public boolean _saveOrder(ActionRequest request,ActionResponse response,PortletConfig config,ActionForm form) 265 { 266 HttpServletRequest httpServletRequest = ((ActionRequestImpl) request).getHttpServletRequest(); 267 HttpSession session = httpServletRequest.getSession(); 268 if(!isTokenValid(httpServletRequest)) 269 { 270 int i = 0; 271 for(i = 0;i < 120;i++) 272 { 273 if (session.getAttribute(WebKeys.SHOPPING_CART_ERRORS) != null) 274 { 275 generateToken(httpServletRequest); 276 saveToken(httpServletRequest); 277 saveErrors(httpServletRequest,(ActionMessages)session.getAttribute(WebKeys.SHOPPING_CART_ERRORS)); 278 279 setForward(request,"portlet.ext.order_manager.view_checkOut"); 280 return true; 281 } 282 if (session.getAttribute(WebKeys.SHOPPING_CART_ORDER_FORM) != null) 283 { 284 setForward(request,"portlet.ext.order_manager.view_invoice"); 285 return true; 286 } 287 try 288 { 289 Thread.sleep(1000); 290 } 291 catch(Exception ex) 292 { 293 Logger.debug(this,ex.toString()); 294 } 295 } 296 if (i == 120) 298 { 299 ActionMessages ae = new ActionMessages(); 300 ae.add(Globals.ERROR_KEY, new ActionMessage("error.cc_processing.timeout")); 301 session.setAttribute(WebKeys.SHOPPING_CART_ERRORS, ae); 302 generateToken(httpServletRequest); 303 saveToken(httpServletRequest); 304 setForward(request,"portlet.ext.order_manager.view_checkOut"); 305 return true; 306 } 307 } 308 OrderForm orderForm = (OrderForm) form; 309 DotHibernate.startTransaction(); 311 try 312 { 313 session.setAttribute(WebKeys.SHOPPING_CART_ERRORS,null); 314 session.setAttribute(WebKeys.SHOPPING_CART_ORDER_FORM,null); 315 ShoppingCart shoppingCart = (ShoppingCart) session.getAttribute(WebKeys.SHOPPING_CART); 316 User user = (User) shoppingCart.getUser(); 317 UserProxy userProxy = UserProxyFactory.getUserProxy(user); 318 Date now = new Date (); 319 320 Order order = new Order(); 322 order.setUserInode(userProxy.getInode()); 323 order.setDatePosted(now); 324 order.setLastModDate(now); 325 User backendUser = _getUser(request); 326 if (backendUser != null) 327 order.setBackendUser(backendUser.getUserId()); 328 order.setBillingAddress1(orderForm.getBillingAddress1()); 330 order.setBillingAddress2(orderForm.getBillingAddress2()); 331 order.setBillingCity(orderForm.getBillingCity()); 332 if (orderForm.getBillingState().equals("otherCountry")) 333 order.setBillingState(orderForm.getBillingStateOtherCountryText()); 334 else 335 order.setBillingState(orderForm.getBillingState()); 336 order.setBillingZip(orderForm.getBillingZip()); 337 order.setBillingCountry(orderForm.getBillingCountry()); 338 order.setBillingPhone(orderForm.getBillingPhone()); 339 order.setBillingFax(orderForm.getBillingFax()); 340 order.setBillingContactName(orderForm.getBillingContactName()); 341 order.setBillingContactPhone(orderForm.getBillingContactPhone()); 342 order.setBillingContactEmail(orderForm.getBillingContactEmail()); 343 order.setShippingAddress1(orderForm.getShippingAddress1()); 345 order.setShippingAddress2(orderForm.getShippingAddress2()); 346 order.setShippingLabel(orderForm.getShippingLabel()); 347 order.setShippingCity(orderForm.getShippingCity()); 348 if (orderForm.getShippingState().equals("otherCountry")) 349 order.setShippingState(orderForm.getShippingStateOtherCountryText()); 350 else 351 order.setShippingState(orderForm.getShippingState()); 352 order.setShippingZip(orderForm.getShippingZip()); 353 order.setShippingCountry(orderForm.getShippingCountry()); 354 order.setShippingPhone(orderForm.getShippingPhone()); 355 order.setShippingFax(orderForm.getShippingFax()); 356 if (orderForm.getPaymentType().equals("cc")) 360 { 361 order.setNameOnCard(orderForm.getNameOnCard()); 362 String cardType = orderForm.getCardType(); 363 String [] creditCardTypes = Config.getStringArrayProperty("EREG_CREDIT_CARD_TYPES"); 364 if (cardType.equals("vs")) 365 { 366 cardType = creditCardTypes[0]; 367 } 368 else if (cardType.equals("mc")) 369 { 370 cardType = creditCardTypes[1]; 371 } 372 else if (cardType.equals("dc")) 373 { 374 cardType = creditCardTypes[2]; 375 } 376 else if (cardType.equals("ae")) 377 { 378 cardType = creditCardTypes[3]; 379 } 380 order.setCardType(cardType); 381 order.setCardNumber(UtilMethods.obfuscateCreditCard(orderForm.getCardNumber())); order.setCardExpMonth(orderForm.getCardExpMonth()); 383 order.setCardExpYear(orderForm.getCardExpYear()); 384 order.setCardVerificationValue(""); 386 order.setOrderTotalPaid(orderForm.getOrderTotal()); 387 order.setOrderTotalDue(0); 388 int paymentStatus = Config.getIntProperty("ECOM_PAY_PAID"); 389 order.setPaymentStatus(paymentStatus); 390 order.setPaymentType(Config.getStringProperty("ECOM_CREDIT_CARD")); 391 392 CreditCardProcessorResponse ccResponse = CreditCardProcessor.processCreditCardOrderProducts(order.getInode(), 393 null, 394 (orderForm.getOrderTax() != 0 ? false : true), 395 request.getRemoteUser(), 396 orderForm.getOrderSubTotalDiscount(), 397 orderForm.getOrderTax() !=0 ? (Float )orderForm.getOrderTax() : null, 398 orderForm.getOrderShipping(), 399 orderForm.getOrderTotal(), 400 orderForm.getCardNumber(), 401 orderForm.getCardExpMonth() + 1, 402 orderForm.getCardExpYear(), 403 orderForm.getCardVerificationValue(), 404 user.getFullName(), 405 null, 406 orderForm.getBillingAddress1(), 407 orderForm.getBillingAddress2(), 408 orderForm.getBillingCity(), 409 orderForm.getBillingState(), 410 orderForm.getBillingZip(), 411 Config.getStringProperty("US_COUNTRY_CODE"), 412 orderForm.getBillingContactPhone(), 413 null, 414 orderForm.getBillingContactEmail(), 415 Config.getStringProperty("WEB_EVENT_REGISTRATION_COMMENTS"), 416 ""); 417 418 if (!ccResponse.orderApproved()) { 419 ActionMessages ae = new ActionMessages(); 422 ae.add(Globals.ERROR_KEY, new ActionMessage( 423 "error.cc_processing.card.denied", ccResponse.getError())); 424 session.setAttribute(WebKeys.SHOPPING_CART_ERRORS,ae); 425 generateToken(httpServletRequest); 426 saveToken(httpServletRequest); 427 saveErrors(httpServletRequest, ae); 428 setForward(request,"portlet.ext.order_manager.view_checkOut"); 429 return false; 430 } 431 } 432 else if (orderForm.getPaymentType().equals("ch")) 433 { 434 order.setCheckNumber(orderForm.getCheckNumber()); 436 order.setCheckBankName(orderForm.getCheckBankName()); 437 438 order.setOrderTotalPaid(0); 439 order.setOrderTotalDue(orderForm.getOrderTotal()); 440 int paymentStatus = Config.getIntProperty("ECOM_PAY_WAITING"); 441 order.setPaymentStatus(paymentStatus); 442 order.setPaymentType(Config.getStringProperty("ECOM_CHECK")); 443 } 444 else if (orderForm.getPaymentType().equals("po")) 445 { 446 order.setPoNumber(orderForm.getPoNumber()); 448 449 order.setOrderTotalPaid(0); 450 order.setOrderTotalDue(orderForm.getOrderTotal()); 451 int paymentStatus = Config.getIntProperty("ECOM_PAY_INVOICED"); 452 order.setPaymentStatus(paymentStatus); 453 order.setPaymentType(Config.getStringProperty("ECOM_PURCHASE_ORDER")); 454 } 455 456 int orderStatus = Config.getIntProperty("ECOM_ORDER_PLACED"); 457 order.setOrderStatus(orderStatus); 458 order.setTaxExemptNumber(orderForm.getTaxExemptNumber()); 460 order.setOrderSubTotal(orderForm.getOrderSubTotal()); 462 order.setOrderDiscount(orderForm.getOrderDiscount()); 463 order.setOrderShipping(orderForm.getOrderShipping()); 464 order.setOrderShipType(orderForm.getOrderShipType()); 465 order.setOrderTax(orderForm.getOrderTax()); 466 order.setOrderTotal(orderForm.getOrderTotal()); 467 468 List <DiscountCode> discounts = shoppingCart.getDiscountCodes(); 470 String discountCodes = ""; 471 for(DiscountCode discount : discounts) 472 { 473 discountCodes += discount.getCodeId() + ":"; 474 } 475 if (UtilMethods.isSet(discountCodes)) 476 { 477 discountCodes = discountCodes.substring(0,discountCodes.lastIndexOf(":")); 478 } 479 order.setDiscountCodes(discountCodes); 480 481 OrderFactory.saveOrder(order); 483 orderForm.setInode(order.getInode()); 484 486 List <Holder> holders = shoppingCart.getHolders(); 488 for(Holder holder : holders) 489 { 490 ProductFormat format = holder.getFormat(); 491 492 OrderItem orderItem = new OrderItem(); 493 orderItem.setOrderInode(order.getInode()); 494 orderItem.setProductInode(format.getInode()); 495 orderItem.setItemQty(holder.getQuantity()); 496 orderItem.setItemPrice(holder.getPrice()); 497 OrderItemFactory.saveOrderItem(orderItem); 498 int inventoryQuantity = format.getInventoryQuantity(); 499 format.setInventoryQuantity(inventoryQuantity - holder.getQuantity()); 500 ProductFormatFactory.saveProductFormat(format); 501 } 502 504 session.setAttribute(WebKeys.SHOPPING_CART_ORDER_FORM,form); 505 DotHibernate.commitTransaction(); 506 try 508 { 509 String to = user.getEmailAddress(); 510 String from = user.getEmailAddress(); 511 String subject = "Thanks for ordering with Dotmarketing"; 512 setForward(request,"portlet.ext.order_manager.view_checkOut"); 514 String path = "/application/products/invoice_email.dot"; 515 Host host = HostFactory.getCurrentHost(request); 516 String hostName = host.getHostname(); 517 String URL = "http://" + hostName + path + "?"; 519 URL += "orderInode=" + order.getInode(); 520 StringBuffer writer = UtilMethods.getURL(URL); 521 String body = writer.toString().trim(); 522 sendEmail(to,from,subject,body); 523 } 524 catch(Exception ex) 525 { 526 Logger.debug(this,ex.toString()); 527 } 528 setForward(request,"portlet.ext.order_manager.view_invoice"); 529 } 530 catch (CreditCardProcessorException e) 531 { 532 Logger.warn(this,"Credit card processor exception placing a credit card order: "+ e.getMessage(), e); 534 DotHibernate.rollbackTransaction(); 535 ActionMessages ae = new ActionMessages(); 536 switch (e.getCode()) 537 { 538 case CreditCardProcessorException.DATA_MISSING: 539 ae.add(Globals.ERROR_KEY, new ActionMessage("error.cc_processing.invalid.card.data")); 540 break; 541 case CreditCardProcessorException.COMMUNICATION_ERROR: 542 ae.add(Globals.ERROR_KEY, new ActionMessage("error.cc_processing.communication.error")); 543 break; 544 default: 545 ae.add(Globals.ERROR_KEY, new ActionMessage("error.cc_processing.unknown")); 546 } 547 saveErrors(httpServletRequest, ae); 549 session.setAttribute(WebKeys.SHOPPING_CART_ERRORS,ae); 550 generateToken(httpServletRequest); 552 saveToken(httpServletRequest); 553 setForward(request,"portlet.ext.order_manager.view_checkOut"); 555 return false; 556 } 557 catch (Exception e) 558 { 559 Logger.error(this,"Unknown Error placing a credit card order: "+ e.getMessage(), e); 561 DotHibernate.rollbackTransaction(); 562 ActionMessages ae = new ActionMessages(); 563 ae.add(Globals.ERROR_KEY, new ActionMessage("error.cc_processing.unknown")); 564 saveErrors(httpServletRequest, ae); 566 session.setAttribute(WebKeys.SHOPPING_CART_ERRORS, ae); 567 generateToken(httpServletRequest); 569 saveToken(httpServletRequest); 570 setForward(request,"portlet.ext.order_manager.view_invoice"); 572 } 573 return true; 574 } 575 576 private void _loadAmount(ActionRequest request,ActionResponse response,PortletConfig config,ActionForm form) 577 { 578 HttpSession session = ((ActionRequestImpl)request).getHttpServletRequest().getSession(); 579 ShoppingCart shoppingCart = (ShoppingCart)session.getAttribute(WebKeys.SHOPPING_CART); 580 581 User userSession = shoppingCart.getUser(); 582 OrderForm orderForm = (OrderForm) form; 583 585 String userId = userSession.getUserId(); 586 587 UserProxy up = UserProxyFactory.getUserProxy(userId); 590 Organization org = (Organization) InodeFactory.getParentOfClass(up, Organization.class); 591 boolean isPartner = ((org.getPartnerKey() != null && !org.getPartnerKey().equals("") )? true : false); 592 593 List <Holder> holders = shoppingCart.getHolders(); 594 List <DiscountCode> discounts = shoppingCart.getDiscountCodes(); 595 float orderSubTotal = 0F; 597 for(Holder holder : holders) 598 { 599 ProductFormat format = holder.getFormat(); 600 int quantity = holder.getQuantity(); 601 ProductPrice productPrice = format.getQuantityPrice(quantity,discounts); 602 float price = (isPartner) ? productPrice.getPartnerPrice() : productPrice.getRetailPrice(); 603 holder.setPrice(price); 605 float lineTotal = quantity * price; 606 orderSubTotal += lineTotal; 607 holder.setLineTotal(lineTotal); 608 } 609 orderForm.setOrderSubTotal(orderSubTotal); 610 611 float orderDiscount = 0; 613 ProductWebAPI pwa = new ProductWebAPI(); 614 orderDiscount = pwa.getTotalApplicableDiscount(holders,discounts,isPartner); 615 orderForm.setOrderDiscount(orderDiscount); 616 617 float orderSubTotalDiscount = orderSubTotal - orderDiscount; 619 orderSubTotalDiscount = (orderSubTotalDiscount < 0 ? 0 : orderSubTotalDiscount); 620 orderForm.setOrderSubTotalDiscount(orderSubTotalDiscount); 621 orderForm.setOrderSubTotalDiscount(orderSubTotal); 622 623 float orderTax = 0; 625 if (orderForm.getBillingState() != null){ 626 if (orderForm.getBillingState().equals("FL") && !UtilMethods.isSet(orderForm.getTaxExemptNumber())) 627 { 628 orderTax = ((float) Math.round(orderSubTotalDiscount * 6.5)) / ((float) 100); 629 } 630 } 631 orderForm.setOrderTax(orderTax); 632 request.setAttribute("orderTax",orderTax); 633 float orderShippingValue = 0; 634 orderForm.setIsShippingZero(false); 635 if (orderForm.getShippingCountry() != null){ 637 if (orderForm.getShippingCountry().equals(Config.getStringProperty("DEFAULT_COUNTRY_CODE"))) 638 orderShippingValue = CalculateShippingAndHandling.calculateShippingAndHandling(shoppingCart, orderForm.getOrderShipType(),orderForm.getShippingZip()); 639 else 640 { 641 orderShippingValue = CalculateShippingAndHandling.calculateHandling(shoppingCart); 642 orderForm.setIsShippingZero(true); 643 } 644 } 645 else 646 orderShippingValue = CalculateShippingAndHandling.calculateShippingAndHandling(shoppingCart, orderForm.getOrderShipType(),orderForm.getShippingZip()); 647 648 orderForm.setOrderShipping(orderShippingValue); 649 request.setAttribute("orderShipping",orderShippingValue); 650 651 float orderTotal = orderSubTotalDiscount + orderTax + orderShippingValue; 653 orderForm.setOrderTotal(orderTotal); 654 655 HttpServletRequest httpServletRequest = ((ActionRequestImpl) request).getHttpServletRequest(); 657 generateToken(httpServletRequest); 658 saveToken(httpServletRequest); 659 660 setForward(request,"portlet.ext.order_manager.view_checkOut"); 661 } 662 663 protected static boolean sendEmail(String to, String from, String subject, String body) 664 { 665 Mailer m = new Mailer(); 666 m.setToEmail(to); 667 m.setFromEmail(from); 668 m.setSubject(subject); 669 m.setHTMLBody(body); 670 return m.sendMessage(); 671 } 672 673 protected User _getUser(ActionRequest req) { 674 675 User user = null; 677 try { 678 user = com.liferay.portal.util.PortalUtil.getUser(req); 679 } catch (Exception e) { 680 _handleException(e, req); 681 } 682 return user; 683 684 } 685 686 } 687 | Popular Tags |