public ActionForward rate( ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Throwable { String itemNaturalKey = (String) request.getParameter("itemNaturalKey"); String value = (String) request.getParameter("rate"); ContentSessionBean contentSessionBean = getContentBean(request).getContentSessionBean(); Site site = contentSessionBean.getSiteDomain().getSite(); String siteId = site.getSiteId(); if (value != null) { EntityManager em = JpaConnection.getInstance().getCurrentEntityManager(); Item item = ItemDAO.loadNatural(siteId, itemNaturalKey); int itemRatingCount = item.getItemRatingCount().intValue(); float itemRating = item.getItemRating().floatValue(); int rate = Integer.parseInt(value); if (itemRatingCount != 0) { itemRating = ((itemRating * itemRatingCount) + rate) / (itemRatingCount + 1); itemRatingCount += 1; } else { itemRatingCount = 1; itemRating = rate; } item.setItemRating(new Float(itemRating)); item.setItemRatingCount(new Integer(itemRatingCount)); em.persist(item); } ActionForward forward = actionMapping.findForward("success"); forward = new ActionForward( forward.getPath() + contentSessionBean.getSiteDomain().getSiteDomainPrefix() + "/" + contentSessionBean .getSiteProfile() .getSiteProfileClass() .getSiteProfileClassName() + "/item/" + itemNaturalKey, forward.getRedirect()); return forward; }
public OrderEngine(ShoppingCart shoppingCart, User user) throws Exception { EntityManager em = JpaConnection.getInstance().getCurrentEntityManager(); this.shoppingCart = shoppingCart; this.user = user; isNew = true; String siteId = shoppingCart.getContentSessionKey().getSiteId(); ContentSessionKey contentSessionKey = shoppingCart.getContentSessionKey(); if (shoppingCart.getOrderNum() != null) { orderHeader = OrderHeaderDAO.load(siteId, shoppingCart.getOrderNum()); isNew = false; } else { orderHeader = new OrderHeader(); orderHeader.setOrderStatus(Constants.ORDERSTATUS_OPEN); } Customer customer = shoppingCart.getCustomer(); if (customer != null) { OrderAddress custAddress = null; if (orderHeader.getCustAddress() != null) { custAddress = orderHeader.getCustAddress(); } else { custAddress = new OrderAddress(); custAddress.setRecCreateBy(Constants.USERNAME_SYSTEM); custAddress.setRecCreateDatetime(new Date()); } CustomerAddress adddress = customer.getCustAddress(); custAddress.setCustUseAddress(Constants.CUST_ADDRESS_USE_OWN); custAddress.setCustPrefix(adddress.getCustPrefix()); custAddress.setCustFirstName(adddress.getCustFirstName()); custAddress.setCustMiddleName(adddress.getCustMiddleName()); custAddress.setCustLastName(adddress.getCustLastName()); custAddress.setCustSuffix(adddress.getCustSuffix()); custAddress.setCustAddressLine1(adddress.getCustAddressLine1()); custAddress.setCustAddressLine2(adddress.getCustAddressLine2()); custAddress.setCustCityName(adddress.getCustCityName()); custAddress.setCustStateName(adddress.getCustStateName()); custAddress.setCustStateCode(adddress.getCustStateCode()); custAddress.setCustCountryName(adddress.getCustCountryName()); custAddress.setCustCountryCode(adddress.getCustCountryCode()); custAddress.setCustStateName(adddress.getCustStateName()); custAddress.setCustZipCode(adddress.getCustZipCode()); custAddress.setCustPhoneNum(adddress.getCustPhoneNum()); custAddress.setCustFaxNum(adddress.getCustFaxNum()); custAddress.setRecUpdateBy(Constants.USERNAME_SYSTEM); custAddress.setRecUpdateDatetime(new Date()); Country country = CountryDAO.loadByCountryCode(siteId, adddress.getCustCountryCode()); custAddress.setCountry(country); if (adddress.getCustStateCode() != null) { State state = StateDAO.loadByStateCode(siteId, adddress.getCustStateCode()); custAddress.setState(state); } em.persist(custAddress); orderHeader.setCustAddress(custAddress); } CustomerAddress billingAddress = shoppingCart.getBillingAddress(); if (billingAddress != null) { OrderAddress address = null; if (orderHeader.getBillingAddress() != null) { address = orderHeader.getBillingAddress(); } else { address = new OrderAddress(); address.setRecCreateBy(Constants.USERNAME_SYSTEM); address.setRecCreateDatetime(new Date()); } address.setCustUseAddress(billingAddress.getCustUseAddress()); address.setCustPrefix(billingAddress.getCustPrefix()); address.setCustFirstName(billingAddress.getCustFirstName()); address.setCustMiddleName(billingAddress.getCustMiddleName()); address.setCustLastName(billingAddress.getCustLastName()); address.setCustSuffix(billingAddress.getCustSuffix()); address.setCustAddressLine1(billingAddress.getCustAddressLine1()); address.setCustAddressLine2(billingAddress.getCustAddressLine2()); address.setCustCityName(billingAddress.getCustCityName()); address.setCustStateName(billingAddress.getCustStateName()); address.setCustStateCode(billingAddress.getCustStateCode()); address.setCustCountryName(billingAddress.getCustCountryName()); address.setCustCountryCode(billingAddress.getCustCountryCode()); address.setCustStateName(billingAddress.getCustStateName()); address.setCustZipCode(billingAddress.getCustZipCode()); address.setCustPhoneNum(billingAddress.getCustPhoneNum()); address.setCustFaxNum(billingAddress.getCustFaxNum()); address.setRecUpdateBy(Constants.USERNAME_SYSTEM); address.setRecUpdateDatetime(new Date()); Country country = CountryDAO.loadByCountryCode(siteId, billingAddress.getCustCountryCode()); address.setCountry(country); if (billingAddress.getCustStateCode() != null) { State state = StateDAO.loadByStateCode(siteId, billingAddress.getCustStateCode()); address.setState(state); } em.persist(address); orderHeader.setBillingAddress(address); } CustomerAddress shippingAddress = shoppingCart.getShippingAddress(); if (shippingAddress != null) { OrderAddress address = null; if (orderHeader.getShippingAddress() != null) { address = orderHeader.getShippingAddress(); } else { address = new OrderAddress(); address.setRecCreateBy(Constants.USERNAME_SYSTEM); address.setRecCreateDatetime(new Date()); } address.setCustUseAddress(shippingAddress.getCustUseAddress()); address.setCustPrefix(shippingAddress.getCustPrefix()); address.setCustFirstName(shippingAddress.getCustFirstName()); address.setCustMiddleName(shippingAddress.getCustMiddleName()); address.setCustLastName(shippingAddress.getCustLastName()); address.setCustSuffix(shippingAddress.getCustSuffix()); address.setCustAddressLine1(shippingAddress.getCustAddressLine1()); address.setCustAddressLine2(shippingAddress.getCustAddressLine2()); address.setCustCityName(shippingAddress.getCustCityName()); address.setCustStateName(shippingAddress.getCustStateName()); address.setCustStateCode(shippingAddress.getCustStateCode()); address.setCustCountryName(shippingAddress.getCustCountryName()); address.setCustCountryCode(shippingAddress.getCustCountryCode()); address.setCustStateName(shippingAddress.getCustStateName()); address.setCustZipCode(shippingAddress.getCustZipCode()); address.setCustPhoneNum(shippingAddress.getCustPhoneNum()); address.setCustFaxNum(shippingAddress.getCustFaxNum()); address.setRecUpdateBy(Constants.USERNAME_SYSTEM); address.setRecUpdateDatetime(new Date()); Country country = CountryDAO.loadByCountryCode(siteId, shippingAddress.getCustCountryCode()); address.setCountry(country); if (shippingAddress.getCustStateCode() != null) { State state = StateDAO.loadByStateCode(siteId, shippingAddress.getCustStateCode()); address.setState(state); } em.persist(address); orderHeader.setShippingAddress(address); } if (customer != null) { orderHeader.setCustEmail(customer.getCustEmail()); } orderHeader.setShippingTotal(Float.valueOf(shoppingCart.getShippingOrderTotal())); orderHeader.setShippingDiscountTotal(shoppingCart.getShippingDiscountTotal()); orderHeader.setOrderTotal(Float.valueOf(shoppingCart.getOrderTotal())); orderHeader.setOrderDate(new Date()); orderHeader.setPaymentGatewayProvider(null); orderHeader.setCreditCardDesc(null); orderHeader.setCustCreditCardNum(null); if (!shoppingCart.isCashPaymentOrder()) { if (shoppingCart.getPaymentEngine() != null) { orderHeader.setPaymentGatewayProvider( shoppingCart.getPaymentEngine().getClass().getSimpleName()); } } CustomerCreditCard custCreditCard = shoppingCart.getCustCreditCard(); if (!shoppingCart.isCashPaymentOrder() && custCreditCard != null) { orderHeader.setCreditCardDesc(custCreditCard.getCreditCard().getCreditCardDesc()); orderHeader.setCustCreditCardNum(custCreditCard.getCustCreditCardNum()); creditCardInfo = new CreditCardInfo(); creditCardInfo.setCreditCardNum( AESEncoder.getInstance().decode(custCreditCard.getCustCreditCardNum())); creditCardInfo.setCreditCardFullName(custCreditCard.getCustCreditCardFullName()); creditCardInfo.setCreditCardVerNum(custCreditCard.getCustCreditCardVerNum()); creditCardInfo.setCreditCardExpiryMonth(custCreditCard.getCustCreditCardExpiryMonth()); creditCardInfo.setCreditCardExpiryYear(custCreditCard.getCustCreditCardExpiryYear()); } if (shoppingCart.getShippingMethod() != null) { orderHeader.setShippingMethodName( shoppingCart.getShippingMethod().getShippingMethodLanguage().getShippingMethodName()); if (!contentSessionKey.isSiteProfileClassDefault()) { for (ShippingMethodLanguage language : shoppingCart.getShippingMethod().getShippingMethodLanguages()) { if (language .getSiteProfileClass() .getSiteProfileClassId() .equals(contentSessionKey.getSiteProfileClassId())) { if (language.getShippingMethodName() != null) { orderHeader.setShippingMethodName(language.getShippingMethodName()); } break; } } } } orderHeader.setShippingPickUp(Constants.VALUE_NO); if (shoppingCart.isShippingPickUp()) { orderHeader.setShippingPickUp(Constants.VALUE_YES); String shippingMethodName = Languages.getLangTranValue(contentSessionKey.getLangId(), "content.text.shipping.pickUp"); orderHeader.setShippingMethodName(shippingMethodName); } // orderHeader.setOrderStatus(Constants.ORDERSTATUS_OPEN); orderHeader.setSiteDomain(shoppingCart.getSiteDomain()); orderHeader.setCustomer(customer); orderHeader.setSiteCurrency(shoppingCart.getSiteCurrency()); orderHeader.setSiteProfile(shoppingCart.getSiteProfile()); orderHeader.setShppingMethod(shoppingCart.getShippingMethod()); for (OrderItemDetail orderItemDetail : orderHeader.getOrderItemDetails()) { for (OrderDetailTax orderDetailTax : orderItemDetail.getOrderDetailTaxes()) { em.remove(orderDetailTax); } orderItemDetail.getOrderDetailTaxes().clear(); for (OrderAttributeDetail orderAttributeDetail : orderItemDetail.getOrderAttributeDetails()) { em.remove(orderAttributeDetail); } orderItemDetail.getOrderAttributeDetails().clear(); em.remove(orderItemDetail); } orderHeader.getOrderItemDetails().clear(); for (OrderOtherDetail orderOtherDetail : orderHeader.getOrderOtherDetails()) { em.remove(orderOtherDetail); } orderHeader.getOrderOtherDetails().clear(); for (OrderDetailTax orderTax : orderHeader.getOrderTaxes()) { em.remove(orderTax); } orderHeader.getOrderTaxes().clear(); Iterator<?> shoppingCartItems = shoppingCart.getShoppingCartItems().iterator(); int seqNum = 0; while (shoppingCartItems.hasNext()) { ShoppingCartItem shoppingCartItem = (ShoppingCartItem) shoppingCartItems.next(); OrderItemDetail orderItemDetail = new OrderItemDetail(); Item item = shoppingCartItem.getItem(); Item master = item; if (item.getItemTypeCd().equals(Constants.ITEM_TYPE_SKU)) { master = item.getItemSkuParent(); } orderItemDetail.setSeqNum(Integer.valueOf(seqNum++)); orderItemDetail.setItemNum(item.getItemNum()); orderItemDetail.setItemUpcCd(item.getItemUpcCd()); orderItemDetail.setItemSkuCd(item.getItemSkuCd()); orderItemDetail.setItemShortDesc(master.getItemLanguage().getItemShortDesc()); if (master.getItemLanguage().getItemShortDesc().length() > 128) { orderItemDetail.setItemShortDesc( master.getItemLanguage().getItemShortDesc().substring(0, 127)); } if (!contentSessionKey.isSiteProfileClassDefault()) { for (ItemLanguage language : master.getItemLanguages()) { if (language .getSiteProfileClass() .getSiteProfileClassId() .equals(contentSessionKey.getSiteProfileClassId())) { if (language.getItemShortDesc() != null) { orderItemDetail.setItemShortDesc(language.getItemShortDesc()); } break; } } } orderItemDetail.setItemTierQty(shoppingCartItem.getTierPrice().getItemTierQty()); orderItemDetail.setItemTierPrice(shoppingCartItem.getTierPrice().getItemTierPrice()); orderItemDetail.setItemOrderQty(shoppingCartItem.getItemQty()); orderItemDetail.setItemDetailAmount(shoppingCartItem.getItemPriceTotal()); orderItemDetail.setItemDetailDiscountAmount(shoppingCartItem.getItemDiscountAmount()); setDirty(shoppingCartItem.getItem().getItemSkuCd()); if (shoppingCartItem.getItem().getItemId() != -1L) { orderItemDetail.setItem(item); } orderItemDetail.setOrderHeader(orderHeader); Iterator<?> iterator = shoppingCartItem.getItemAttributeInfos().iterator(); while (iterator.hasNext()) { ItemAttributeInfo itemAttributeInfo = (ItemAttributeInfo) iterator.next(); ItemAttributeDetail itemAttributeDetail = (ItemAttributeDetail) em.find(ItemAttributeDetail.class, itemAttributeInfo.getItemAttribDetailId()); char customAttribTypeCode = itemAttributeDetail .getCustomAttributeDetail() .getCustomAttribute() .getCustomAttribTypeCode(); if (customAttribTypeCode == Constants.CUSTOM_ATTRIBUTE_TYPE_SKU_MAKEUP) { continue; } if (customAttribTypeCode == Constants.CUSTOM_ATTRIBUTE_TYPE_USER_INPUT) { continue; } if (customAttribTypeCode == Constants.CUSTOM_ATTRIBUTE_TYPE_USER_SELECT_DROPDOWN) { continue; } OrderAttributeDetail orderAttributeDetail = new OrderAttributeDetail(); orderAttributeDetail.setOrderItemDetail(orderItemDetail); orderAttributeDetail.setCustomAttributeDetail( itemAttributeDetail.getCustomAttributeDetail()); if (customAttribTypeCode == Constants.CUSTOM_ATTRIBUTE_TYPE_CUST_SELECT_DROPDOWN) { CustomAttributeOption customAttributeOption = (CustomAttributeOption) em.find(CustomAttributeOption.class, itemAttributeInfo.getCustomAttribOptionId()); orderAttributeDetail.setCustomAttributeOption(customAttributeOption); } if (customAttribTypeCode == Constants.CUSTOM_ATTRIBUTE_TYPE_CUST_INPUT) { orderAttributeDetail.setOrderAttribValue(itemAttributeInfo.getItemAttribDetailValue()); } orderItemDetail.getOrderAttributeDetails().add(orderAttributeDetail); } orderHeader.getOrderItemDetails().add(orderItemDetail); ItemTax taxes[] = shoppingCartItem.getTaxes(); for (int i = 0; i < taxes.length; i++) { OrderDetailTax orderDetailTax = new OrderDetailTax(); orderDetailTax.setTaxName(taxes[i].getTax().getTaxLanguage().getTaxName()); if (!contentSessionKey.isSiteProfileClassDefault()) { for (TaxLanguage language : taxes[i].getTax().getTaxLanguages()) { if (language .getSiteProfileClass() .getSiteProfileClassId() .equals(contentSessionKey.getSiteProfileClassId())) { if (language.getTaxName() != null) { orderDetailTax.setTaxName(language.getTaxName()); } break; } } } orderDetailTax.setTaxAmount(taxes[i].getTaxAmount()); orderDetailTax.setTax(taxes[i].getTax()); orderDetailTax.setOrderItemDetail(orderItemDetail); orderDetailTax.setOrderHeader(orderHeader); orderItemDetail.getOrderDetailTaxes().add(orderDetailTax); orderHeader.getOrderTaxes().add(orderDetailTax); } } Iterator<?> shoppingCartCoupons = shoppingCart.getShoppingCartCoupons().iterator(); seqNum = 0; while (shoppingCartCoupons.hasNext()) { ShoppingCartCoupon shoppingCartCoupon = (ShoppingCartCoupon) shoppingCartCoupons.next(); OrderOtherDetail orderOtherDetail = new OrderOtherDetail(); Coupon coupon = shoppingCartCoupon.getCoupon(); orderOtherDetail.setCoupon(coupon); orderOtherDetail.setSeqNum(seqNum++); orderOtherDetail.setOrderOtherDetailNum(coupon.getCouponCode()); orderOtherDetail.setOrderOtherDetailDesc(coupon.getCouponLanguage().getCouponName()); if (!contentSessionKey.isSiteProfileClassDefault()) { for (CouponLanguage language : coupon.getCouponLanguages()) { if (language .getSiteProfileClass() .getSiteProfileClassId() .equals(contentSessionKey.getSiteProfileClassId())) { if (language.getCouponName() != null) { orderOtherDetail.setOrderOtherDetailDesc(language.getCouponName()); } break; } } } orderOtherDetail.setOrderOtherDetailAmount(shoppingCartCoupon.getCouponAmount()); setDirty(coupon); orderHeader.getOrderOtherDetails().add(orderOtherDetail); } ItemTax shippingTaxes[] = shoppingCart.getShippingTaxes(); if (shippingTaxes != null) { for (int i = 0; i < shippingTaxes.length; i++) { OrderDetailTax orderDetailTax = new OrderDetailTax(); orderDetailTax.setTaxName(shippingTaxes[i].getTax().getTaxLanguage().getTaxName()); if (!contentSessionKey.isSiteProfileClassDefault()) { for (TaxLanguage language : shippingTaxes[i].getTax().getTaxLanguages()) { if (language .getSiteProfileClass() .getSiteProfileClassId() .equals(contentSessionKey.getSiteProfileClassId())) { if (language.getTaxName() != null) { orderDetailTax.setTaxName(language.getTaxName()); } break; } } } orderDetailTax.setTaxAmount(shippingTaxes[i].getTaxAmount()); orderDetailTax.setTax(shippingTaxes[i].getTax()); orderDetailTax.setOrderHeader(orderHeader); orderHeader.getOrderTaxes().add(orderDetailTax); } } // orderHeader.setOrderStatus(calcStatus(orderHeader)); }