Vector<ShoppingCartItemBean> vector = new Vector<ShoppingCartItemBean>();
Iterator<?> iterator = shoppingCart.getShoppingCartItems().iterator();
while (iterator.hasNext()) {
ShoppingCartItem shoppingCartItem = (ShoppingCartItem) iterator.next();
ShoppingCartItemBean bean = new ShoppingCartItemBean();
Item item = shoppingCartItem.getItem();
Item master = item;
if (item.getItemTypeCd().equals(Constants.ITEM_TYPE_SKU)) {
master = item.getItemSkuParent();
}
bean.setItemId(item.getItemId().toString());
bean.setItemNum(item.getItemNum());
bean.setItemNaturalKey(item.getItemNaturalKey());
bean.setItemQty(Format.getInt(shoppingCartItem.getItemQty()));
int tierQty = shoppingCartItem.getTierPrice().getItemTierQty();
float tierPrice = shoppingCartItem.getTierPrice().getItemTierPrice();
bean.setItemPrice(formatItemPrice(contentBean, tierQty, tierPrice));
bean.setItemSubTotal(formatter.formatCurrency(shoppingCartItem.getItemPriceTotal()));
bean.setItemQtyError("");
bean.setItemShortDesc(master.getItemLanguage().getItemShortDesc());
ItemImage itemImage = master.getItemLanguage().getImage();
if (itemImage != null) {
bean.setImageId(itemImage.getImageId().toString());
}
if (!contentBean.getContentSessionBean().isSiteProfileClassDefault()){
for (ItemLanguage itemLanguage : master.getItemLanguages()) {
if (itemLanguage.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClassId)) {
if (itemLanguage.getItemShortDesc() != null) {
bean.setItemShortDesc(itemLanguage.getItemShortDesc());
}
if (itemLanguage.getItemImageOverride().equals(String.valueOf(Constants.VALUE_YES))) {
bean.setImageId(itemLanguage.getImage().getImageId().toString());
}
break;
}
}
}
Vector<ShoppingCartItemAttributeBean> shoppingCartItemAttributes = new Vector<ShoppingCartItemAttributeBean>();
Iterator<?> itemAttributeInfoIterator = shoppingCartItem.getItemAttributeInfos().iterator();
while (itemAttributeInfoIterator.hasNext()) {
ItemAttributeInfo itemAttributeInfo = (ItemAttributeInfo) itemAttributeInfoIterator.next();
ShoppingCartItemAttributeBean attributeBean = new ShoppingCartItemAttributeBean();
ItemAttributeDetail itemAttributeDetail = (ItemAttributeDetail) em.find(ItemAttributeDetail.class, itemAttributeInfo.getItemAttribDetailId());
CustomAttribute customAttribute = itemAttributeDetail.getCustomAttributeDetail().getCustomAttribute();
if (customAttribute.getCustomAttribTypeCode() == Constants.CUSTOM_ATTRIBUTE_TYPE_USER_INPUT) {
continue;
}
if (customAttribute.getCustomAttribTypeCode() == Constants.CUSTOM_ATTRIBUTE_TYPE_USER_SELECT_DROPDOWN) {
continue;
}
attributeBean.setCustomAttribDesc(customAttribute.getCustomAttributeLanguage().getCustomAttribDesc());
if (!contentBean.getContentSessionBean().isSiteProfileClassDefault()) {
for (CustomAttributeLanguage language : customAttribute.getCustomAttributeLanguages()) {
if (language.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClassId)) {
if (language.getCustomAttribDesc() != null) {
attributeBean.setCustomAttribDesc(language.getCustomAttribDesc());
}
break;
}
}
}
if (customAttribute.getCustomAttribTypeCode() == Constants.CUSTOM_ATTRIBUTE_TYPE_CUST_INPUT) {
attributeBean.setCustomAttribValue(itemAttributeInfo.getItemAttribDetailValue());
}
else {
CustomAttributeOption customAttribOption = CustomAttributeOptionDAO.load(site.getSiteId(), itemAttributeInfo.getCustomAttribOptionId());
attributeBean.setCustomAttribValue(customAttribOption.getCustomAttributeOptionLanguage().getCustomAttribValue());
if (!contentBean.getContentSessionBean().isSiteProfileClassDefault()) {
for (CustomAttributeOptionLanguage language : customAttribOption.getCustomAttributeOptionLanguages()) {
if (language.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClassId)) {
if (language.getCustomAttribValue() != null) {
attributeBean.setCustomAttribValue(language.getCustomAttribValue());
}
break;
}
}
}
}
shoppingCartItemAttributes.add(attributeBean);
}
bean.setShoppingCartItemAttributes(shoppingCartItemAttributes);
vector.add(bean);
}
form.setShoppingCartItemInfos(vector);
Vector<ShoppingCartCouponBean> couponVector = new Vector<ShoppingCartCouponBean>();
iterator = shoppingCart.getShoppingCartCoupons().iterator();
while (iterator.hasNext()) {
ShoppingCartCoupon shoppingCartCoupon = (ShoppingCartCoupon) iterator.next();
Coupon coupon = shoppingCartCoupon.getCoupon();
ShoppingCartCouponBean bean = new ShoppingCartCouponBean();
bean.setCouponId(Format.getLong(coupon.getCouponId()));
bean.setCouponCode(coupon.getCouponCode());
bean.setCouponName(coupon.getCouponLanguage().getCouponName());
if (!contentBean.getContentSessionBean().isSiteProfileClassDefault()) {
for (CouponLanguage language : coupon.getCouponLanguages()) {
if (language.getSiteProfileClass().getSiteProfileClassId().equals(contentBean.getContentSessionKey().getSiteProfileClassId())) {
if (language.getCouponName() != null) {
bean.setCouponName(language.getCouponName());
}
break;
}
}
}
bean.setCouponAmount(formatter.formatCurrency(shoppingCartCoupon.getCouponAmount()));
couponVector.add(bean);
}
form.setShoppingCartCouponInfos(couponVector);
ItemTax taxes[] = shoppingCart.getTaxes();
Vector<ShoppingCartTaxInfo> taxVector = new Vector<ShoppingCartTaxInfo>();
if (taxes != null) {
for (int i = 0; i < taxes.length; i++) {
ShoppingCartTaxInfo taxInfo = new ShoppingCartTaxInfo();
Tax tax = taxes[i].getTax();
taxInfo.setTaxName(tax.getTaxLanguage().getTaxName());
if (!contentBean.getContentSessionBean().isSiteProfileClassDefault()) {
for (TaxLanguage language : tax.getTaxLanguages()) {
if (language.getSiteProfileClass().getSiteProfileClassId().equals(contentBean.getContentSessionKey().getSiteProfileClassId())) {
if (language.getTaxName() != null) {
taxInfo.setTaxName(language.getTaxName());
}
break;
}
}
}
taxInfo.setTaxAmount(formatter.formatCurrency(taxes[i].getTaxAmount()));
taxVector.add(taxInfo);
}
}
Collections.sort(taxVector);
form.setShoppingCartTaxInfos(taxVector);
form.setPriceTotal(formatter.formatCurrency(shoppingCart.getShoppingCartSubTotal()));
form.setTaxTotal(formatter.formatCurrency(shoppingCart.getTaxTotal()));
form.setShippingTotal(formatter.formatCurrency(shoppingCart.getShippingTotal()));
form.setShippingDiscountTotal(formatter.formatCurrency(shoppingCart.getShippingDiscountTotal()));
form.setShippingOrderTotal(formatter.formatCurrency(shoppingCart.getShippingOrderTotal()));
form.setOrderTotal(formatter.formatCurrency(shoppingCart.getOrderTotal()));
Vector<?> shippingMethodVector = shoppingCart.getShippingMethods();
Vector<LabelValueBean> smVector = new Vector<LabelValueBean>();
iterator = shippingMethodVector.iterator();
while (iterator.hasNext()) {
ShippingMethod shippingMethod = (ShippingMethod) iterator.next();
LabelValueBean bean = new LabelValueBean();
bean.setLabel(shippingMethod.getShippingMethodLanguage().getShippingMethodName());
bean.setValue(shippingMethod.getShippingMethodId().toString());
if (!contentBean.getContentSessionBean().isSiteProfileClassDefault()) {
for (ShippingMethodLanguage language : shippingMethod.getShippingMethodLanguages()) {
if (language.getSiteProfileClass().getSiteProfileClassId().equals(contentBean.getContentSessionKey().getSiteProfileClassId())) {
if (language.getShippingMethodName() != null) {
bean.setLabel(language.getShippingMethodName());
}
break;
}
}
}
smVector.add(bean);
}
LabelValueBean shippingMethods[] = new LabelValueBean[smVector.size()];
smVector.copyInto(shippingMethods);
form.setShippingMethods(shippingMethods);
SiteDomainLanguage siteDomainLanguage = contentBean.getContentSessionBean().getSiteDomain().getSiteDomainLanguage();
for (SiteDomainLanguage language : contentBean.getContentSessionBean().getSiteDomain().getSiteDomainLanguages()) {
if (language.getSiteProfileClass().getSiteProfileClassId().equals(contentBean.getContentSessionKey().getSiteProfileClassId())) {
siteDomainLanguage = language;
break;
}
}
SiteDomainParamBean siteDomainParamBean = SiteDomainDAO.getSiteDomainParamBean(contentBean.getContentSessionBean().getSiteDomain().getSiteDomainLanguage(), siteDomainLanguage);
form.setShoppingCartMessage(siteDomainParamBean.getCheckoutShoppingCartMessage());
PaymentEngine paymentEngine = shoppingCart.getPaymentEngine();
if (paymentEngine != null) {
form.setPaymentGatewayProvider(paymentEngine.getClass().getSimpleName());
}
form.setCashPaymentOrder(shoppingCart.isCashPaymentOrder());
form.setPayPal(shoppingCart.isPayPal());
form.setCreditCard(shoppingCart.isCreditCard());
form.setCashPayment(shoppingCart.isCashPayment());
boolean includeShippingPickUp = false;
if (siteDomainParamBean.getCheckoutIncludeShippingPickup() != null) {
includeShippingPickUp = siteDomainParamBean.getCheckoutIncludeShippingPickup().equals(String.valueOf(Constants.VALUE_YES));
}
form.setIncludeShippingPickUp(includeShippingPickUp);
shoppingCart.setIncludeShippingPickUp(includeShippingPickUp);
form.setShippingValid(shoppingCart.isShippingValid());
if (!shoppingCart.isShippingValid()) {
messages.add("shippingLocation", new ActionMessage("content.error.shippingLocation.unsupported"));
form.setAllowShippingQuote(false);
if (siteDomainParamBean.getCheckoutAllowsShippingQuote() != null && siteDomainParamBean.getCheckoutAllowsShippingQuote().equals(String.valueOf(Constants.VALUE_YES))) {
form.setAllowShippingQuote(true);
}
}
ContentApi contentApi = new ContentApi(request);
Vector<ItemInfo> crossSellItems = new Vector<ItemInfo>();
iterator = shoppingCart.getShoppingCartItems().iterator();
while (iterator.hasNext()) {
ShoppingCartItem shoppingCartItem = (ShoppingCartItem) iterator.next();
Item item = shoppingCartItem.getItem();
if (item.getItemTypeCd().equals(Constants.ITEM_TYPE_SKU)) {
item = item.getItemSkuParent();
}
Iterator<?> itemsCrossSell = item.getItemsCrossSell().iterator();
while (itemsCrossSell.hasNext()) {
Item upSellItem = (Item) itemsCrossSell.next();
if (isExist(crossSellItems, upSellItem)) {
continue;
}
ItemInfo itemInfo = contentApi.formatItem(upSellItem);
crossSellItems.add(itemInfo);