init(request);
ContentBean contentBean = getContentBean(request);
Site site = contentBean.getContentSessionBean().getSiteDomain().getSite();
ShoppingCartActionForm form = (ShoppingCartActionForm) actionForm;
ShoppingCart shoppingCart = ShoppingCart.getSessionInstance(request, true);
ActionMessages messages = new ActionMessages();
try {
String itemAttribDetailIds[] = form.getItemAttribDetailIds();
Vector<ItemAttributeInfo> itemAttributeInfos = new Vector<ItemAttributeInfo>();
if (itemAttribDetailIds != null) {
String customAttribValues[] = form.getCustomAttribValues();
String customAttribTypeCodes[] = form.getCustomAttribTypeCodes();
for (int i = 0; i < itemAttribDetailIds.length; i++) {
ItemAttributeInfo itemAttributeInfo = new ItemAttributeInfo();
itemAttributeInfo.setCustomAttribTypeCode(customAttribTypeCodes[i]);
itemAttributeInfo.setItemAttribDetailId(Format.getLong(itemAttribDetailIds[i]));
if (customAttribTypeCodes[i].equals(String.valueOf(Constants.CUSTOM_ATTRIBUTE_TYPE_CUST_INPUT))) {
itemAttributeInfo.setItemAttribDetailValue(customAttribValues[i]);
}
else {
itemAttributeInfo.setCustomAttribOptionId(Format.getLong(customAttribValues[i]));
}
itemAttributeInfos.add(itemAttributeInfo);
}
}
Language language = contentBean.getContentSessionBean().getSiteProfile().getSiteProfileClass().getLanguage();
String itemNauralKeys[] = form.getItemNaturalKeys();
if (itemNauralKeys != null) {
for (int i = 0; i < itemNauralKeys.length; i++) {
Item item = DataApi.getInstance().getItem(site.getSiteId(), itemNauralKeys[i]);
try {
if (item.getItemTypeCd().equals(Constants.ITEM_TYPE_RECOMMAND_BUNDLE)) {
for (Item child : item.getChildren()) {
shoppingCart.setItemQty(child, 1, itemAttributeInfos, contentBean, false);
}
}
else if (item.getItemTypeCd().equals(Constants.ITEM_TYPE_TEMPLATE)) {
item = getItem(form, site.getSiteId());
shoppingCart.setItemQty(item, 1, itemAttributeInfos, contentBean, false);
}
else {
shoppingCart.setItemQty(item, 1, itemAttributeInfos, contentBean, false);
}
} catch (ItemNotAvailiableException itemNotAvailiableException) {
String value = Languages.getLangTranValue(language.getLangId(), "content.text.itemQuatityNotAvailable");
ShoppingCartItemBean itemInfo = (ShoppingCartItemBean) form.getShoppingCartItemInfos().elementAt(i);
itemInfo.setItemQtyError(value);
}
}
}
else {
/*
* Only intended to be used with older version of templates.
*/
String itemIds[] = form.getItemIds();
if (itemIds != null) {
for (int i = 0; i < itemIds.length; i++) {
Item item = DataApi.getInstance().getItem(site.getSiteId(), Format.getLong(itemIds[i]));
if (item.getItemTypeCd().equals(Constants.ITEM_TYPE_RECOMMAND_BUNDLE)) {
for (Item child : item.getChildren()) {
shoppingCart.setItemQty(child, 1, itemAttributeInfos, contentBean, false);
}
}
else if (item.getItemTypeCd().equals(Constants.ITEM_TYPE_TEMPLATE)) {
item = getItem(form, site.getSiteId());
shoppingCart.setItemQty(item, 1, itemAttributeInfos, contentBean, false);
}
else {
shoppingCart.setItemQty(item, 1, itemAttributeInfos, contentBean, false);
}
}
}
}
} catch (ItemNotAvailiableException itemNotAvailiableException) {