thought I would update you on my progress. I decided to go back to scratch. I restarted by taking the TotalDiscount order total module and renaming it to ChompOnDeal. I didn't change anything at first. I just wanted to see it work on it's own. That worked.
Then I added the necessary ChompOn data I needed in the konakartadmin module part. I also changed the konakart module to calculate the order total value based on the ChompOn coupon value. In truth, I cut and pasted the same code as my first attempt into place.
For some reason, that worked perfectly. I am not sure what is different about the old code that makes it fail. I've copied the code below in case anyone is curious.
konakart ChompOnDeal class:
//
// (c) 2006 DS Data Systems UK Ltd, All rights reserved.
//
// DS Data Systems and KonaKart and their respective logos, are
// trademarks of DS Data Systems UK Ltd. All rights reserved.
//
// The information in this document is free software; you can redistribute
// it and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
package com.konakart.bl.modules.ordertotal.chompondeal;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import org.apache.torque.TorqueException;
import com.carawaytea.chompon.ChompOnImpl;
import com.carawaytea.chompon.domain.Coupon;
import com.carawaytea.chompon.domain.Deal;
import com.konakart.app.KKConfiguration;
import com.konakart.app.KKException;
import com.konakart.app.Order;
import com.konakart.app.OrderTotal;
import com.konakart.app.Promotion;
import com.konakart.appif.KKEngIf;
import com.konakart.bl.modules.BaseModule;
import com.konakart.bl.modules.ordertotal.BaseOrderTotalModule;
import com.konakart.bl.modules.ordertotal.OrderTotalInterface;
import com.workingdogs.village.DataSetException;
/**
* Module that creates an OrderTotal object for applying a percentage discount
* or an amount discount on the order. The discount may be applied on the total
* value of the order before or after tax.
*
* The promotion may be activated only if:
* <ul>
* <li>The total amount of the order is greater than a minimum amount</li>
* <li>The total number of products ordered is greater than a minimum amount</li>
* <li>The total number of a single product ordered is greater than a minimum
* amount</li>
* </ul>
*
* There may be multiple valid promotions applicable for an order. If this is
* the case, the logic applied is the following: All cumulative promotions are
* summed into one order total object. Then we loop through the order total
* objects and choose the one that offers the largest discount.
*/
public class ChompOnDeal extends BaseOrderTotalModule implements
OrderTotalInterface {
private static int sortOrder = -1;
private static String code = "ot_chompon_deal";
private static String pid = "";
private static String auth = "";
private static String bundleName = BaseModule.basePackage
+ ".ordertotal.chompondeal.ChompOnDeal";
private static HashMap<Locale, ResourceBundle> resourceBundleMap = new HashMap<Locale, ResourceBundle>();
private static String mutex = "otChompOnDealMutex";
// Configuration Keys
private final static String MODULE_ORDER_TOTAL_CHOMPON_DEAL_SORT_ORDER = "MODULE_ORDER_TOTAL_CHOMPON_DEAL_SORT_ORDER";
private final static String MODULE_ORDER_TOTAL_CHOMPON_DEAL_STATUS = "MODULE_ORDER_TOTAL_CHOMPON_DEAL_STATUS";
// Message Catalogue Keys
// private final static String MODULE_ORDER_TOTAL_CHOMPON_DEAL_TITLE = "module.order.total.chompondeal.title";
private final static String MODULE_ORDER_TOTAL_CHOMPON_COUPON_PID = "MODULE_ORDER_TOTAL_CHOMPON_COUPON_PID";
private final static String MODULE_ORDER_TOTAL_CHOMPON_COUPON_AUTH = "MODULE_ORDER_TOTAL_CHOMPON_COUPON_AUTH";
/**
* Constructor
*
* @param eng
*
* @throws DataSetException
* @throws KKException
* @throws TorqueException
*
*/
public ChompOnDeal(KKEngIf eng) throws TorqueException, KKException,
DataSetException {
super.init(eng);
// Create the static maps from the configuration info
if (sortOrder == -1) {
synchronized (mutex) {
if (sortOrder == -1) {
setStaticVariables();
}
}
}
}
/**
* Sets some static variables during setup
*
* @throws KKException
*
*/
public void setStaticVariables() throws KKException {
KKConfiguration conf;
conf = getEng().getConfiguration(
MODULE_ORDER_TOTAL_CHOMPON_DEAL_SORT_ORDER);
if (conf == null) {
sortOrder = 0;
} else {
sortOrder = new Integer(conf.getValue()).intValue();
}
conf = getEng().getConfiguration(MODULE_ORDER_TOTAL_CHOMPON_COUPON_PID);
if (conf == null) {
pid = "";
} else {
pid = conf.getValue();
}
conf = getEng()
.getConfiguration(MODULE_ORDER_TOTAL_CHOMPON_COUPON_AUTH);
if (conf == null) {
auth = "";
} else {
auth = conf.getValue();
}
}
/**
* Returns true or false
*
* @throws KKException
*/
public boolean isAvailable() throws KKException {
return isAvailable(getEng(), MODULE_ORDER_TOTAL_CHOMPON_DEAL_STATUS);
}
/**
* Create and return an OrderTotal object for the discount amount.
*
* @param order
* @param dispPriceWithTax
* @param locale
* @return Returns an OrderTotal object for this module
* @throws Exception
*/
public OrderTotal getOrderTotal(Order order, boolean dispPriceWithTax,
Locale locale) throws Exception {
OrderTotal ot;
// Get the resource bundle
ResourceBundle rb = getResourceBundle(mutex, bundleName,
resourceBundleMap, locale);
if (rb == null) {
throw new KKException(
"A resource file cannot be found for the country "
+ locale.getCountry());
}
// First see if the user even entered a chompon coupon
String couponId = order.getCustom1();
if ("".equals(couponId))
return null;
ChompOnImpl chompon = new ChompOnImpl();
Coupon coupon = chompon.getCouponInfo(pid, auth, couponId);
// If the coupon doesn't exist or is no longer valid then return
if (coupon == null || !coupon.isValid())
return null;
// Get the promotions
Promotion[] promArray = getPromMgr().getPromotions(code, order);
// List to contain an order total for each promotion
List<OrderTotal> orderTotalList = new ArrayList<OrderTotal>();
if (promArray != null) {
for (int i = 0; i < promArray.length; i++) {
Promotion promotion = promArray;
//If the deal does not match the ChompOn Coupon Deal then continue
String dealID = getCustomString(promotion.getCustom7(), 7);
if (dealID == null || !dealID.equals(coupon.getDealID()))
continue;
/*
* Get the configuration parameters from the promotion
*/
// Minimum value for order
BigDecimal minTotalOrderVal = getCustomBigDecimal(
promotion.getCustom1(), 1);
// Minimum total quantity of products ordered
int minTotalQuantity = getCustomInt(promotion.getCustom2(), 2);
// Need to order at least this quantity of a single product for
// promotion to apply
int minProdQuantity = getCustomInt(promotion.getCustom3(), 3);
// Actual discount. Could be a percentage or an amount.
BigDecimal discountApplied = getCustomBigDecimal(
promotion.getCustom4(), 4);
// If set to true it is a percentage. Otherwise it is an amount.
// boolean percentageDiscount = getCustomBoolean(
// promotion.getCustom5(), 5);
// If set to true, discount is applied to pre-tax value. Only
// relevant for
// percentage discount.
boolean applyBeforeTax = getCustomBoolean(
promotion.getCustom6(), 6);
// Don't bother going any further if there is no discount
if (discountApplied == null
|| discountApplied.equals(new BigDecimal(0))) {
continue;
}
// Get the order value
BigDecimal orderValue = null;
if (applyBeforeTax) {
orderValue = order.getSubTotalExTax();
} else {
orderValue = order.getSubTotalIncTax();
}
// If promotion doesn't cover any of the products in the order
// then go on to the
// next promotion
if (promotion.getApplicableProducts() == null
|| promotion.getApplicableProducts().length == 0) {
continue;
}
ot = new OrderTotal();
ot.setSortOrder(sortOrder);
ot.setClassName(code);
ot.setPromotions(new Promotion[] { promotion });
// Does promotion only apply to a min order value ?
if (minTotalOrderVal != null) {
if (orderValue.compareTo(minTotalOrderVal) < 0) {
// If we haven't reached the minimum amount then
// continue to the next
// promotion
continue;
}
}
// Does promotion only apply to a minimum number of products
// ordered ?
if (minTotalQuantity > 0) {
int total = 0;
for (int j = 0; j < promotion.getApplicableProducts().length; j++) {
total += order.getOrderProducts()[j].getQuantity();
}
if (total < minTotalQuantity) {
// If we haven't reached the minimum total then continue
// to the next
// promotion
continue;
}
}
// Does promotion only apply to a minimum number of single
// products ordered ?
if (minProdQuantity > 0) {
boolean foundMin = false;
for (int j = 0; j < promotion.getApplicableProducts().length; j++) {
if (order.getOrderProducts()[j].getQuantity() >= minProdQuantity) {
foundMin = true;
}
}
if (!foundMin) {
// If we haven't reached the minimum total then continue
// to the next
// promotion
continue;
}
}
Deal deal = chompon.getDeal(pid, auth, coupon.getDealID());
if (deal != null) {
BigDecimal discount = new BigDecimal(deal.getValue());
ot.setValue(discount);
int scale = new Integer(order.getCurrency().getDecimalPlaces())
.intValue();
ot.setValue(ot.getValue().setScale(scale,
BigDecimal.ROUND_HALF_UP));
ot.setText("-"
+ getCurrMgr().formatPrice(ot.getValue(),
order.getCurrencyCode()));
ot.setTitle("ChompOn Coupon:");
}
orderTotalList.add(ot);
}
} else {
// Return null if there are no promotions
return null;
}
// Call a helper method to decide which OrderTotal we should return
OrderTotal retOT = getDiscountOrderTotalFromList(order, orderTotalList);
return retOT;
}
public int getSortOrder() {
return sortOrder;
}
public String getCode() {
return code;
}
}
konakartadmin code:
//
// (c) 2006 DS Data Systems UK Ltd, All rights reserved.
//
// DS Data Systems and KonaKart and their respective logos, are
// trademarks of DS Data Systems UK Ltd. All rights reserved.
//
// The information in this document is free software; you can redistribute
// it and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
package com.konakartadmin.modules.ordertotal.chompondeal;
import java.util.Date;
import com.konakart.util.Utils;
import com.konakartadmin.app.KKConfiguration;
import com.konakartadmin.bl.KKAdminBase;
import com.konakartadmin.modules.ModuleInterface;
import com.konakartadmin.modules.OrderTotalModule;
/**
* ChompOn Deal order total module
*
*/
public class ChompOnDeal extends OrderTotalModule
{
/**
* @return the config key stub
*/
public String getConfigKeyStub()
{
if (configKeyStub == null)
{
setConfigKeyStub(super.getConfigKeyStub() + "_CHOMPON_DEAL");
}
return configKeyStub;
}
public String getModuleTitle()
{
return getMsgs().getString("MODULE_ORDER_TOTAL_CHOMPON_DEAL_TEXT_TITLE");
}
/**
* @return the implementation filename
*/
public String getImplementationFileName()
{
return "ChompOnDeal";
}
/**
* @return the module sub-type
*/
public int getModuleSubType()
{
return ModuleInterface.MODULE_SUB_TYPE_PROMOTION;
}
/**
* @return the module code
*/
public String getModuleCode()
{
return "ot_chompon_deal";
}
/**
* @return an array of configuration values for this order total module
*/
public KKConfiguration[] getConfigs()
{
if (configs == null)
{
configs = new KKConfiguration[11];
}
if (configs[0] != null && !Utils.isBlank(configs[0].getConfigurationKey()))
{
return configs;
}
Date now = KKAdminBase.getKonakartTimeStampDate();
int i = 0;
int groupId = 6;
configs = new KKConfiguration(
/* title */"Total ChompOn Deal Module Status",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_STATUS",
/* value */"true",
/* description */"If set to false, all of the ChompOn Deal promotions will be unavailable",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"",
/* setFun */"tep_cfg_select_option(array('true', 'false'), ",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Sort order of display",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_SORT_ORDER",
/* value */"20",
/* description */"Sort Order of ChompOn Deal module on the UI. Lowest is displayed first.",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"",
/* setFun */"",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Publisher ID",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_COUPON_PID",
/* value */"22",
/* description */"Chompon publisher id.",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"",
/* setFun */"",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Authorization Key",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_COUPON_AUTH",
/* value */"22",
/* description */"Chompon authorization key.",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"",
/* setFun */"",
/* dateAdd */now);
/*
* We don't want the following to be visible since they are used to map data onto the custom
* fields of the promotion object
*/
configs = new KKConfiguration(
/* title */"Minimum Order Value",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_MIN_ORDER_VALUE",
/* value */"custom1",
/* description */"The discount only applies if the total of the order,"
+ " equals or is greater than this minimum value",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"double(0,null)",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Min total quantity",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_MIN_TOTAL_QUANTITY",
/* value */"custom2",
/* description */"The discount only applies if the number of products ordered,"
+ " equals or is greater than this minimum value",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"integer(0,null)",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Min quantity for a product",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_MIN_SINGLE_PROD_QUANTITY",
/* value */"custom3",
/* description */"The discount only applies on the total if the quantity of at least one"
+ " single product, equals or is greater than this minimum value.",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"integer(0,null)",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Discount",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL",
/* value */"custom4",
/* description */"The actual discount for the promotion"
+ " It may represent a percentage discount or an amount discount.",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"double(0,null)",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Percent / Amount",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_PERCENT",
/* value */"custom5",
/* description */"If true, the discount is a percentage." + " Otherwise it is an amount",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"tep_cfg_select_option(array('true', 'false'), ",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Apply discount before tax",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_APPLY_BEFORE_TAX",
/* value */"custom6",
/* description */"Determines whether all calculations are"
+ " done on amounts before or after tax.",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"tep_cfg_select_option(array('true', 'false'), ",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"ChompOn Deal ID",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_COUPON_DEAL_ID",
/* value */"custom7",
/* description */"ChompOn Deal ID",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"",
/* dateAdd */now);
return configs;
}
}
Then I added the necessary ChompOn data I needed in the konakartadmin module part. I also changed the konakart module to calculate the order total value based on the ChompOn coupon value. In truth, I cut and pasted the same code as my first attempt into place.
For some reason, that worked perfectly. I am not sure what is different about the old code that makes it fail. I've copied the code below in case anyone is curious.
konakart ChompOnDeal class:
//
// (c) 2006 DS Data Systems UK Ltd, All rights reserved.
//
// DS Data Systems and KonaKart and their respective logos, are
// trademarks of DS Data Systems UK Ltd. All rights reserved.
//
// The information in this document is free software; you can redistribute
// it and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
package com.konakart.bl.modules.ordertotal.chompondeal;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import org.apache.torque.TorqueException;
import com.carawaytea.chompon.ChompOnImpl;
import com.carawaytea.chompon.domain.Coupon;
import com.carawaytea.chompon.domain.Deal;
import com.konakart.app.KKConfiguration;
import com.konakart.app.KKException;
import com.konakart.app.Order;
import com.konakart.app.OrderTotal;
import com.konakart.app.Promotion;
import com.konakart.appif.KKEngIf;
import com.konakart.bl.modules.BaseModule;
import com.konakart.bl.modules.ordertotal.BaseOrderTotalModule;
import com.konakart.bl.modules.ordertotal.OrderTotalInterface;
import com.workingdogs.village.DataSetException;
/**
* Module that creates an OrderTotal object for applying a percentage discount
* or an amount discount on the order. The discount may be applied on the total
* value of the order before or after tax.
*
* The promotion may be activated only if:
* <ul>
* <li>The total amount of the order is greater than a minimum amount</li>
* <li>The total number of products ordered is greater than a minimum amount</li>
* <li>The total number of a single product ordered is greater than a minimum
* amount</li>
* </ul>
*
* There may be multiple valid promotions applicable for an order. If this is
* the case, the logic applied is the following: All cumulative promotions are
* summed into one order total object. Then we loop through the order total
* objects and choose the one that offers the largest discount.
*/
public class ChompOnDeal extends BaseOrderTotalModule implements
OrderTotalInterface {
private static int sortOrder = -1;
private static String code = "ot_chompon_deal";
private static String pid = "";
private static String auth = "";
private static String bundleName = BaseModule.basePackage
+ ".ordertotal.chompondeal.ChompOnDeal";
private static HashMap<Locale, ResourceBundle> resourceBundleMap = new HashMap<Locale, ResourceBundle>();
private static String mutex = "otChompOnDealMutex";
// Configuration Keys
private final static String MODULE_ORDER_TOTAL_CHOMPON_DEAL_SORT_ORDER = "MODULE_ORDER_TOTAL_CHOMPON_DEAL_SORT_ORDER";
private final static String MODULE_ORDER_TOTAL_CHOMPON_DEAL_STATUS = "MODULE_ORDER_TOTAL_CHOMPON_DEAL_STATUS";
// Message Catalogue Keys
// private final static String MODULE_ORDER_TOTAL_CHOMPON_DEAL_TITLE = "module.order.total.chompondeal.title";
private final static String MODULE_ORDER_TOTAL_CHOMPON_COUPON_PID = "MODULE_ORDER_TOTAL_CHOMPON_COUPON_PID";
private final static String MODULE_ORDER_TOTAL_CHOMPON_COUPON_AUTH = "MODULE_ORDER_TOTAL_CHOMPON_COUPON_AUTH";
/**
* Constructor
*
* @param eng
*
* @throws DataSetException
* @throws KKException
* @throws TorqueException
*
*/
public ChompOnDeal(KKEngIf eng) throws TorqueException, KKException,
DataSetException {
super.init(eng);
// Create the static maps from the configuration info
if (sortOrder == -1) {
synchronized (mutex) {
if (sortOrder == -1) {
setStaticVariables();
}
}
}
}
/**
* Sets some static variables during setup
*
* @throws KKException
*
*/
public void setStaticVariables() throws KKException {
KKConfiguration conf;
conf = getEng().getConfiguration(
MODULE_ORDER_TOTAL_CHOMPON_DEAL_SORT_ORDER);
if (conf == null) {
sortOrder = 0;
} else {
sortOrder = new Integer(conf.getValue()).intValue();
}
conf = getEng().getConfiguration(MODULE_ORDER_TOTAL_CHOMPON_COUPON_PID);
if (conf == null) {
pid = "";
} else {
pid = conf.getValue();
}
conf = getEng()
.getConfiguration(MODULE_ORDER_TOTAL_CHOMPON_COUPON_AUTH);
if (conf == null) {
auth = "";
} else {
auth = conf.getValue();
}
}
/**
* Returns true or false
*
* @throws KKException
*/
public boolean isAvailable() throws KKException {
return isAvailable(getEng(), MODULE_ORDER_TOTAL_CHOMPON_DEAL_STATUS);
}
/**
* Create and return an OrderTotal object for the discount amount.
*
* @param order
* @param dispPriceWithTax
* @param locale
* @return Returns an OrderTotal object for this module
* @throws Exception
*/
public OrderTotal getOrderTotal(Order order, boolean dispPriceWithTax,
Locale locale) throws Exception {
OrderTotal ot;
// Get the resource bundle
ResourceBundle rb = getResourceBundle(mutex, bundleName,
resourceBundleMap, locale);
if (rb == null) {
throw new KKException(
"A resource file cannot be found for the country "
+ locale.getCountry());
}
// First see if the user even entered a chompon coupon
String couponId = order.getCustom1();
if ("".equals(couponId))
return null;
ChompOnImpl chompon = new ChompOnImpl();
Coupon coupon = chompon.getCouponInfo(pid, auth, couponId);
// If the coupon doesn't exist or is no longer valid then return
if (coupon == null || !coupon.isValid())
return null;
// Get the promotions
Promotion[] promArray = getPromMgr().getPromotions(code, order);
// List to contain an order total for each promotion
List<OrderTotal> orderTotalList = new ArrayList<OrderTotal>();
if (promArray != null) {
for (int i = 0; i < promArray.length; i++) {
Promotion promotion = promArray;
//If the deal does not match the ChompOn Coupon Deal then continue
String dealID = getCustomString(promotion.getCustom7(), 7);
if (dealID == null || !dealID.equals(coupon.getDealID()))
continue;
/*
* Get the configuration parameters from the promotion
*/
// Minimum value for order
BigDecimal minTotalOrderVal = getCustomBigDecimal(
promotion.getCustom1(), 1);
// Minimum total quantity of products ordered
int minTotalQuantity = getCustomInt(promotion.getCustom2(), 2);
// Need to order at least this quantity of a single product for
// promotion to apply
int minProdQuantity = getCustomInt(promotion.getCustom3(), 3);
// Actual discount. Could be a percentage or an amount.
BigDecimal discountApplied = getCustomBigDecimal(
promotion.getCustom4(), 4);
// If set to true it is a percentage. Otherwise it is an amount.
// boolean percentageDiscount = getCustomBoolean(
// promotion.getCustom5(), 5);
// If set to true, discount is applied to pre-tax value. Only
// relevant for
// percentage discount.
boolean applyBeforeTax = getCustomBoolean(
promotion.getCustom6(), 6);
// Don't bother going any further if there is no discount
if (discountApplied == null
|| discountApplied.equals(new BigDecimal(0))) {
continue;
}
// Get the order value
BigDecimal orderValue = null;
if (applyBeforeTax) {
orderValue = order.getSubTotalExTax();
} else {
orderValue = order.getSubTotalIncTax();
}
// If promotion doesn't cover any of the products in the order
// then go on to the
// next promotion
if (promotion.getApplicableProducts() == null
|| promotion.getApplicableProducts().length == 0) {
continue;
}
ot = new OrderTotal();
ot.setSortOrder(sortOrder);
ot.setClassName(code);
ot.setPromotions(new Promotion[] { promotion });
// Does promotion only apply to a min order value ?
if (minTotalOrderVal != null) {
if (orderValue.compareTo(minTotalOrderVal) < 0) {
// If we haven't reached the minimum amount then
// continue to the next
// promotion
continue;
}
}
// Does promotion only apply to a minimum number of products
// ordered ?
if (minTotalQuantity > 0) {
int total = 0;
for (int j = 0; j < promotion.getApplicableProducts().length; j++) {
total += order.getOrderProducts()[j].getQuantity();
}
if (total < minTotalQuantity) {
// If we haven't reached the minimum total then continue
// to the next
// promotion
continue;
}
}
// Does promotion only apply to a minimum number of single
// products ordered ?
if (minProdQuantity > 0) {
boolean foundMin = false;
for (int j = 0; j < promotion.getApplicableProducts().length; j++) {
if (order.getOrderProducts()[j].getQuantity() >= minProdQuantity) {
foundMin = true;
}
}
if (!foundMin) {
// If we haven't reached the minimum total then continue
// to the next
// promotion
continue;
}
}
Deal deal = chompon.getDeal(pid, auth, coupon.getDealID());
if (deal != null) {
BigDecimal discount = new BigDecimal(deal.getValue());
ot.setValue(discount);
int scale = new Integer(order.getCurrency().getDecimalPlaces())
.intValue();
ot.setValue(ot.getValue().setScale(scale,
BigDecimal.ROUND_HALF_UP));
ot.setText("-"
+ getCurrMgr().formatPrice(ot.getValue(),
order.getCurrencyCode()));
ot.setTitle("ChompOn Coupon:");
}
orderTotalList.add(ot);
}
} else {
// Return null if there are no promotions
return null;
}
// Call a helper method to decide which OrderTotal we should return
OrderTotal retOT = getDiscountOrderTotalFromList(order, orderTotalList);
return retOT;
}
public int getSortOrder() {
return sortOrder;
}
public String getCode() {
return code;
}
}
konakartadmin code:
//
// (c) 2006 DS Data Systems UK Ltd, All rights reserved.
//
// DS Data Systems and KonaKart and their respective logos, are
// trademarks of DS Data Systems UK Ltd. All rights reserved.
//
// The information in this document is free software; you can redistribute
// it and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
package com.konakartadmin.modules.ordertotal.chompondeal;
import java.util.Date;
import com.konakart.util.Utils;
import com.konakartadmin.app.KKConfiguration;
import com.konakartadmin.bl.KKAdminBase;
import com.konakartadmin.modules.ModuleInterface;
import com.konakartadmin.modules.OrderTotalModule;
/**
* ChompOn Deal order total module
*
*/
public class ChompOnDeal extends OrderTotalModule
{
/**
* @return the config key stub
*/
public String getConfigKeyStub()
{
if (configKeyStub == null)
{
setConfigKeyStub(super.getConfigKeyStub() + "_CHOMPON_DEAL");
}
return configKeyStub;
}
public String getModuleTitle()
{
return getMsgs().getString("MODULE_ORDER_TOTAL_CHOMPON_DEAL_TEXT_TITLE");
}
/**
* @return the implementation filename
*/
public String getImplementationFileName()
{
return "ChompOnDeal";
}
/**
* @return the module sub-type
*/
public int getModuleSubType()
{
return ModuleInterface.MODULE_SUB_TYPE_PROMOTION;
}
/**
* @return the module code
*/
public String getModuleCode()
{
return "ot_chompon_deal";
}
/**
* @return an array of configuration values for this order total module
*/
public KKConfiguration[] getConfigs()
{
if (configs == null)
{
configs = new KKConfiguration[11];
}
if (configs[0] != null && !Utils.isBlank(configs[0].getConfigurationKey()))
{
return configs;
}
Date now = KKAdminBase.getKonakartTimeStampDate();
int i = 0;
int groupId = 6;
configs = new KKConfiguration(
/* title */"Total ChompOn Deal Module Status",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_STATUS",
/* value */"true",
/* description */"If set to false, all of the ChompOn Deal promotions will be unavailable",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"",
/* setFun */"tep_cfg_select_option(array('true', 'false'), ",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Sort order of display",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_SORT_ORDER",
/* value */"20",
/* description */"Sort Order of ChompOn Deal module on the UI. Lowest is displayed first.",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"",
/* setFun */"",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Publisher ID",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_COUPON_PID",
/* value */"22",
/* description */"Chompon publisher id.",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"",
/* setFun */"",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Authorization Key",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_COUPON_AUTH",
/* value */"22",
/* description */"Chompon authorization key.",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"",
/* setFun */"",
/* dateAdd */now);
/*
* We don't want the following to be visible since they are used to map data onto the custom
* fields of the promotion object
*/
configs = new KKConfiguration(
/* title */"Minimum Order Value",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_MIN_ORDER_VALUE",
/* value */"custom1",
/* description */"The discount only applies if the total of the order,"
+ " equals or is greater than this minimum value",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"double(0,null)",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Min total quantity",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_MIN_TOTAL_QUANTITY",
/* value */"custom2",
/* description */"The discount only applies if the number of products ordered,"
+ " equals or is greater than this minimum value",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"integer(0,null)",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Min quantity for a product",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_MIN_SINGLE_PROD_QUANTITY",
/* value */"custom3",
/* description */"The discount only applies on the total if the quantity of at least one"
+ " single product, equals or is greater than this minimum value.",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"integer(0,null)",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Discount",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL",
/* value */"custom4",
/* description */"The actual discount for the promotion"
+ " It may represent a percentage discount or an amount discount.",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"double(0,null)",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Percent / Amount",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_PERCENT",
/* value */"custom5",
/* description */"If true, the discount is a percentage." + " Otherwise it is an amount",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"tep_cfg_select_option(array('true', 'false'), ",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"Apply discount before tax",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_DEAL_APPLY_BEFORE_TAX",
/* value */"custom6",
/* description */"Determines whether all calculations are"
+ " done on amounts before or after tax.",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"tep_cfg_select_option(array('true', 'false'), ",
/* dateAdd */now);
configs = new KKConfiguration(
/* title */"ChompOn Deal ID",
/* key */"MODULE_ORDER_TOTAL_CHOMPON_COUPON_DEAL_ID",
/* value */"custom7",
/* description */"ChompOn Deal ID",
/* groupId */groupId,
/* sortO */i++,
/* useFun */"invisible",
/* setFun */"",
/* dateAdd */now);
return configs;
}
}