Vector<ShippingRegion> srVector = new Vector<ShippingRegion>();
while (iterator.hasNext()) {
ShippingRegion shippingRegion = (ShippingRegion) iterator.next();
srVector.add(shippingRegion);
JSONEscapeObject JSONEscapeObject = new JSONEscapeObject();
JSONEscapeObject.put("shippingRegionId", shippingRegion.getShippingRegionId().toString());
JSONEscapeObject.put("shippingRegionName", shippingRegion.getShippingRegionName());
jsonShippingRegions.add(JSONEscapeObject);
}
sql = "from ShippingRegion shippingRegion where shippingRegion.site.siteId = :siteId and shippingRegionName != :shippingRegionName order by shippingRegionName";
query = em.createQuery(sql);
query.setParameter("siteId", siteId);
query.setParameter("shippingRegionName", Constants.SHIPPINGREGION_OTHERS);
iterator = query.getResultList().iterator();
srVector = new Vector<ShippingRegion>();
while (iterator.hasNext()) {
ShippingRegion shippingRegion = (ShippingRegion) iterator.next();
srVector.add(shippingRegion);
JSONEscapeObject JSONEscapeObject = new JSONEscapeObject();
JSONEscapeObject.put("shippingRegionId", shippingRegion.getShippingRegionId().toString());
JSONEscapeObject.put("shippingRegionName", shippingRegion.getShippingRegionName());
boolean published = false;
for (ShippingMethodRegion shippingMethodRegion : shippingMethod.getShippingMethodRegions()) {
if (shippingMethodRegion.getShippingRegion().getShippingRegionId().equals(shippingRegion.getShippingRegionId())) {
if (shippingMethodRegion.getPublished() == Constants.VALUE_YES) {
published = true;
break;
}
}
}
JSONEscapeObject.put("published", published);
jsonShippingRegions.add(JSONEscapeObject);
}
ShippingRegion shippingRegions[] = new ShippingRegion[srVector.size()];
srVector.toArray(shippingRegions);
Vector<JSONEscapeObject> jsonShippingTypes = new Vector<JSONEscapeObject>();
for (int i = 0; i < shippingTypes.length; i++) {
JSONEscapeObject JSONEscapeObject = new JSONEscapeObject();
JSONEscapeObject.put("shippingTypeId", shippingTypes[i].getShippingTypeId());
JSONEscapeObject.put("shippingTypeName", shippingTypes[i].getShippingTypeName());
for (int j = 0; j < shippingRegions.length; j++) {
ShippingRate shippingRate = findRate(shippingMethod, shippingRegions[j], shippingTypes[i], user);
JSONEscapeObject jsonShippingRate = new JSONEscapeObject();
jsonShippingRate.put("shippingMethodId", shippingMethod.getShippingMethodId().toString());
jsonShippingRate.put("shippingRegionId", shippingRegions[j].getShippingRegionId().toString());
jsonShippingRate.put("shippingTypeId", shippingTypes[i].getShippingTypeId().toString());
if (shippingRate != null) {
JSONEscapeObject.put("exist", true);
if (shippingRate.getShippingRateCurrency() == null || shippingRate.getShippingRateCurrency().getShippingRateFee() == null) {
jsonShippingRate.put("shippingRateFee", "");
}
else {
jsonShippingRate.put("shippingRateFee", Format.getFloat(shippingRate.getShippingRateCurrency().getShippingRateFee()));
}
if (shippingRate.getShippingRatePercentage() == null) {
jsonShippingRate.put("shippingRatePercentage", "");
}
else {
jsonShippingRate.put("shippingRatePercentage", Format.getFloat(shippingRate.getShippingRatePercentage()));
}
if (shippingRate.getShippingRateCurrency() == null || shippingRate.getShippingRateCurrency().getShippingAdditionalRateFee() == null) {
jsonShippingRate.put("shippingAdditionalRateFee", "");
}
else {
jsonShippingRate.put("shippingAdditionalRateFee", Format.getFloat(shippingRate.getShippingRateCurrency().getShippingAdditionalRateFee()));
}
if (shippingRate.getShippingAdditionalRatePercentage() == null) {
jsonShippingRate.put("shippingAdditionalRatePercentage", "");
}
else {
jsonShippingRate.put("shippingAdditionalRatePercentage", Format.getFloat(shippingRate.getShippingAdditionalRatePercentage()));
}
JSONEscapeObject.put(shippingRegions[j].getShippingRegionId().toString(), jsonShippingRate);
}
else {
JSONEscapeObject.put("exist", false);
jsonShippingRate.put("shippingRateFee", "");
jsonShippingRate.put("shippingRatePercentage", "");
jsonShippingRate.put("shippingAdditionalRateFee", "");
jsonShippingRate.put("shippingAdditionalRatePercentage", "");
JSONEscapeObject.put(shippingRegions[j].getShippingRegionId().toString(), jsonShippingRate);
}
if (!form.isSiteCurrencyClassDefault()) {
if (shippingRate != null) {
ShippingRateCurrency shippingRateCurrency = new ShippingRateCurrency();
for (ShippingRateCurrency srCurrency : shippingRate.getShippingRateCurrencies()) {
if (srCurrency.getSiteCurrencyClass().getSiteCurrencyClassId().equals(form.getSiteCurrencyClassId())) {
shippingRateCurrency = srCurrency;
break;
}
}
if (shippingRateCurrency.getShippingRateFee() != null) {
jsonShippingRate.put("shippingRateFeeCurr", Format.getFloat(shippingRateCurrency.getShippingRateFee()));
jsonShippingRate.put("shippingRateFeeCurrFlag", true);
}
else {
jsonShippingRate.put("shippingRateFeeCurr", "");
jsonShippingRate.put("shippingRateFeeCurrFlag", false);
}
if (shippingRateCurrency.getShippingAdditionalRateFee() != null) {
jsonShippingRate.put("shippingAdditionalRateFeeCurr", Format.getFloat(shippingRateCurrency.getShippingAdditionalRateFee()));
jsonShippingRate.put("shippingAdditionalRateFeeCurrFlag", true);
}
else {
jsonShippingRate.put("shippingAdditionalRateFeeCurr", "");
jsonShippingRate.put("shippingAdditionalRateFeeCurrFlag", false);
}
}
else {
jsonShippingRate.put("shippingRateFeeCurr", "");
jsonShippingRate.put("shippingRateFeeCurrFlag", false);
jsonShippingRate.put("shippingAdditionalRateFeeCurr", "");
jsonShippingRate.put("shippingAdditionalRateFeeCurrFlag", false);
}
}
}
jsonShippingTypes.add(JSONEscapeObject);
}
JSONEscapeObject JSONEscapeObject = new JSONEscapeObject();
JSONEscapeObject.put("shippingRegions", jsonShippingRegions);
JSONEscapeObject.put("shippingTypes", jsonShippingTypes);
form.setJsonShippingTypes(JSONEscapeObject.toHtmlString());
}