if (language.getSiteProfileClass().getSiteProfileClassId().equals(form.getSiteProfileClassDefaultId())) {
defaultItemLanguage = language;
}
}
ItemPriceCurrency regularPrice = item.getItemPrice();
ItemPriceCurrency specialPrice = item.getItemSpecPrice();
MessageResources resources = this.getResources(request);
form.setItemId(Format.getLong(item.getItemId()));
form.setItemNum(item.getItemNum());
form.setItemUpcCd(item.getItemUpcCd());
form.setItemSkuCd(item.getItemSkuCd());
form.setItemSellable(item.getItemSellable() == 'Y' ? true : false);
form.setItemTypeCd(item.getItemTypeCd());
form.setItemTypeDesc(resources.getMessage("item.typeCode." + item.getItemTypeCd()));
form.setItemShortDesc(defaultItemLanguage.getItemShortDesc());
form.setItemDesc(defaultItemLanguage.getItemDesc());
form.setPageTitle(defaultItemLanguage.getPageTitle());
form.setMetaKeywords(defaultItemLanguage.getMetaKeywords());
form.setMetaDescription(defaultItemLanguage.getMetaDescription());
form.setItemCost(Format.getFloatObj(item.getItemCost()));
form.setItemPrice(Format.getFloatObj(regularPrice.getItemPrice()));
form.setItemSpecPrice("");
form.setItemSpecPublishOn("");
form.setItemSpecExpireOn("");
if (specialPrice != null) {
form.setItemSpecPrice(Format.getFloatObj(specialPrice.getItemPrice()));
form.setItemSpecPublishOn(Format.getDate(specialPrice.getItemPricePublishOn()));
form.setItemSpecExpireOn(Format.getDate(specialPrice.getItemPriceExpireOn()));
}
form.setItemPublishOn(Format.getDate(item.getItemPublishOn()));
form.setItemExpireOn(Format.getDate(item.getItemExpireOn()));
form.setPublished(item.getPublished() == 'Y' ? true : false);
if (item.getCustomAttributeGroup() != null) {
form.setCustomAttribGroupId(Format.getLong(item.getCustomAttributeGroup().getCustomAttribGroupId()));
form.setCustomAttribGroupName(item.getCustomAttributeGroup().getCustomAttribGroupName());
}
form.setRemoveImages(null);
form.setRemoveMenus(null);
form.setMenuWindowMode("");
ShippingType shippingType = item.getShippingType();
if (shippingType != null) {
form.setShippingTypeId(shippingType.getShippingTypeId().toString());
}
ProductClass productClass = item.getProductClass();
if (productClass != null) {
form.setProductClassId(productClass.getProductClassId().toString());
}
form.setRecUpdateBy(item.getRecUpdateBy());
form.setRecUpdateDatetime(Format.getFullDatetime(item.getRecUpdateDatetime()));
form.setRecCreateBy(item.getRecCreateBy());
form.setRecCreateDatetime(Format.getFullDatetime(item.getRecCreateDatetime()));
if (!form.isSiteProfileClassDefault()) {
form.setItemImageOverride(false);
form.setItemShortDescLangFlag(false);
form.setItemDescLangFlag(false);
form.setPageTitleLangFlag(false);
form.setMetaKeywordsLangFlag(false);
form.setMetaDescriptionLangFlag(false);
form.setItemShortDescLang(defaultItemLanguage.getItemShortDesc());
form.setItemDescLang(defaultItemLanguage.getItemDesc());
form.setPageTitleLang(defaultItemLanguage.getPageTitle());
form.setMetaKeywordsLang(defaultItemLanguage.getMetaKeywords());
form.setMetaDescriptionLang(defaultItemLanguage.getMetaDescription());
Iterator<?> iterator = item.getItemLanguages().iterator();
boolean found = false;
ItemLanguage itemLanguage = null;
Long siteProfileClassId = form.getSiteProfileClassId();
while (iterator.hasNext()) {
itemLanguage = (ItemLanguage) iterator.next();
if (itemLanguage.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClassId)) {
found = true;
break;
}
}
if (found) {
if (itemLanguage.getItemShortDesc() != null) {
form.setItemShortDescLangFlag(true);
form.setItemShortDescLang(itemLanguage.getItemShortDesc());
}
if (itemLanguage.getItemDesc() != null) {
form.setItemDescLangFlag(true);
form.setItemDescLang(itemLanguage.getItemDesc());
}
if (itemLanguage.getPageTitle() != null) {
form.setPageTitleLangFlag(true);
form.setPageTitleLang(itemLanguage.getPageTitle());
}
if (itemLanguage.getMetaKeywords() != null) {
form.setMetaKeywordsLangFlag(true);
form.setMetaKeywordsLang(itemLanguage.getMetaKeywords());
}
if (itemLanguage.getMetaDescription() != null) {
form.setMetaDescriptionLangFlag(true);
form.setMetaDescriptionLang(itemLanguage.getMetaDescription());
}
if (itemLanguage.getItemImageOverride().equalsIgnoreCase(String.valueOf(Constants.VALUE_YES))) {
form.setItemImageOverride(true);
}
}
}
if (!form.isSiteCurrencyClassDefault()) {
ItemPriceCurrency regularPriceCurr = null;
ItemPriceCurrency specialPriceCurr = null;
for (ItemPriceCurrency itemPriceCurrency : item.getItemPriceCurrencies()) {
if (!itemPriceCurrency.getSiteCurrencyClass().getSiteCurrencyClassId().equals(form.getSiteCurrencyClassId())) {
continue;
}
if (itemPriceCurrency.getItemPriceTypeCode() == Constants.ITEM_PRICE_TYPE_CODE_REGULAR) {
regularPriceCurr = itemPriceCurrency;
}
if (itemPriceCurrency.getItemPriceTypeCode() == Constants.ITEM_PRICE_TYPE_CODE_SPECIAL) {
specialPriceCurr = itemPriceCurrency;
}
}
form.setItemPriceCurrFlag(false);
form.setItemSpecPriceCurrFlag(false);
form.setItemPriceCurr(form.getItemPrice());
form.setItemSpecPriceCurr(form.getItemSpecPrice());
if (regularPriceCurr != null) {
form.setItemPriceCurr(Format.getFloatObj(regularPriceCurr.getItemPrice()));
form.setItemPriceCurrFlag(true);
}
if (specialPriceCurr != null) {
form.setItemSpecPriceCurr(Format.getFloatObj(specialPriceCurr.getItemPrice()));
form.setItemSpecPriceCurrFlag(true);
}
}
String sql = "select customerClass " +
"from CustomerClass customerClass " +
"left join customerClass.site site " +
"where site.siteId = :siteId " +
"order by customerClass.custClassName ";
Query query = em.createQuery(sql);
query.setParameter("siteId", item.getSite().getSiteId());
Iterator<?> iterator = query.getResultList().iterator();
Vector<LabelValueBean> custClassList = new Vector<LabelValueBean>();
custClassList.add(new LabelValueBean("", ""));
while (iterator.hasNext()) {
CustomerClass customerClass = (CustomerClass) iterator.next();
LabelValueBean bean = new LabelValueBean(customerClass.getCustClassName(), customerClass.getCustClassId().toString());;
custClassList.add(bean);
}
LabelValueBean custClasses[] = new LabelValueBean[custClassList.size()];
custClassList.copyInto(custClasses);
form.setCustClasses(custClasses);
Vector<ItemAttributeDetailDisplayForm> itemAttributeDetails = new Vector<ItemAttributeDetailDisplayForm>();
if (item.getCustomAttributeGroup() != null) {
sql = "select customAttributeDetail " +
"from CustomAttributeGroup customAttributeGroup " +
"join customAttributeGroup.customAttributeDetails customAttributeDetail " +
"where customAttributeGroup.customAttribGroupId = :customAttribGroupId " +
"order by customAttributeDetail.seqNum ";
query = em.createQuery(sql);
query.setParameter("customAttribGroupId", item.getCustomAttributeGroup().getCustomAttribGroupId());
iterator = query.getResultList().iterator();
boolean itemAttributeLangFlag = false;
while (iterator.hasNext()) {
CustomAttributeDetail customAttributeDetail = (CustomAttributeDetail) iterator.next();
CustomAttribute customAttribute = customAttributeDetail.getCustomAttribute();
ItemAttributeDetailDisplayForm displayForm = new ItemAttributeDetailDisplayForm();
displayForm.setCustomAttribId(customAttribute.getCustomAttribId().toString());
displayForm.setCustomAttribDetailId(customAttributeDetail.getCustomAttribDetailId().toString());
displayForm.setCustomAttribName(customAttribute.getCustomAttribName());
displayForm.setCustomAttribTypeCode(String.valueOf(customAttribute.getCustomAttribTypeCode()));
boolean attributeExist = false;
Iterator<?> details = item.getItemAttributeDetails().iterator();
ItemAttributeDetail itemAttributeDetail = null;
while (details.hasNext()) {
itemAttributeDetail = (ItemAttributeDetail) details.next();
if (itemAttributeDetail.getCustomAttributeDetail().getCustomAttribDetailId().equals(customAttributeDetail.getCustomAttribDetailId())) {
attributeExist = true;
break;
}
}
if (attributeExist) {
displayForm.setItemAttribDetailId(itemAttributeDetail.getItemAttribDetailId().toString());
if (customAttribute.getCustomAttribTypeCode() == Constants.CUSTOM_ATTRIBUTE_TYPE_USER_INPUT) {
displayForm.setItemAttribDetailValue(itemAttributeDetail.getItemAttributeDetailLanguage().getItemAttribDetailValue());
}
CustomAttributeOption customAttributeOption = itemAttributeDetail.getCustomAttributeOption();
if (customAttributeOption != null) {
displayForm.setCustomAttribOptionId(customAttributeOption.getCustomAttribOptionId().toString());
if (customAttribute.getCustomAttribDataTypeCode() == Constants.CUSTOM_ATTRIBUTE_DATA_TYPE_CURRENCY) {
displayForm.setItemAttribDetailValue(customAttributeOption.getCustomAttributeOptionCurrency().getCustomAttribValue());
}
else {
displayForm.setItemAttribDetailValue(customAttributeOption.getCustomAttributeOptionLanguage().getCustomAttribValue());
}
}
if (!form.isSiteProfileClassDefault()) {
boolean found = false;
Long siteProfileClassId = form.getSiteProfileClassId();
ItemAttributeDetailLanguage itemAttributeDetailLanguage = null;
Iterator<?> detailLanguages = itemAttributeDetail.getItemAttributeDetailLanguages().iterator();
while (detailLanguages.hasNext()) {
itemAttributeDetailLanguage = (ItemAttributeDetailLanguage) detailLanguages.next();
if (itemAttributeDetailLanguage.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClassId)) {
found = true;
break;
}
}
displayForm.setItemAttribDetailValueLangFlag(false);
displayForm.setItemAttribDetailValueLang(displayForm.getItemAttribDetailValue());
if (found) {
itemAttributeLangFlag = true;
displayForm.setItemAttribDetailValueLangFlag(false);
if (itemAttributeDetailLanguage.getItemAttribDetailValue() != null) {
displayForm.setItemAttribDetailValueLangFlag(true);
displayForm.setItemAttribDetailValueLang(itemAttributeDetailLanguage.getItemAttribDetailValue());
}
}
}
}
else {
displayForm.setItemAttribDetailId("");
displayForm.setItemAttribDetailValue("");
displayForm.setCustomAttribOptionId("");
}
itemAttributeDetails.add(displayForm);
}
form.setItemAttribDetailValueLangFlag(itemAttributeLangFlag);
}
ItemAttributeDetailDisplayForm[] itemAttributeDetailDisplayForms = new ItemAttributeDetailDisplayForm[itemAttributeDetails.size()];
itemAttributeDetails.copyInto(itemAttributeDetailDisplayForms);
form.setItemAttributeDetails(itemAttributeDetailDisplayForms);
if (!form.isSiteCurrencyClassDefault()) {
form.setItemPriceCurrFlag(false);
form.setItemPriceCurr(Format.getFloat(regularPrice.getItemPrice()));
form.setItemSpecPriceCurrFlag(false);
if (specialPrice != null) {
form.setItemSpecPriceCurr(Format.getFloat(specialPrice.getItemPrice()));
}
ItemPriceCurrency regularPriceCurrency = null;
ItemPriceCurrency specialPriceCurrency = null;
for (ItemPriceCurrency itemPriceCurrency : item.getItemPriceCurrencies()) {
if (!itemPriceCurrency.getSiteCurrencyClass().getSiteCurrencyClassId().equals(siteCurrencyClassId)) {
continue;
}
if (itemPriceCurrency.getItemPriceTypeCode() == Constants.ITEM_PRICE_TYPE_CODE_REGULAR) {
regularPriceCurrency = itemPriceCurrency;
}
if (itemPriceCurrency.getItemPriceTypeCode() == Constants.ITEM_PRICE_TYPE_CODE_SPECIAL) {
specialPriceCurrency = itemPriceCurrency;
}
}
if (regularPriceCurrency != null) {
form.setItemPriceCurrFlag(true);
form.setItemPriceCurr(Format.getFloat(regularPriceCurrency.getItemPrice()));
}
if (specialPriceCurrency != null) {
form.setItemSpecPriceCurrFlag(true);
form.setItemSpecPriceCurr(Format.getFloat(specialPriceCurrency.getItemPrice()));
}
}
form.setItemSkusExist(false);
if (item.getItemTypeCd().equals(Constants.ITEM_TYPE_TEMPLATE)) {