• Welcome to KonaKart Community Forum. Please login or sign up.
 

Table Rate Shipping, posible bug?

Started by ejaen, August 11, 2009, 09:15:48 am

Previous topic - Next topic

ejaen

..
BigDecimal cost = new BigDecimal(0);
if (mode.equalsIgnoreCase(weight))
  {
            // Go through the weight cost list and figure out the cost

            /*
             * There is a list of weights since the total order weight may exceed the maximum weight
             * for a single package and so it has already been split up by the manager calling this
             * module.
             */
            for (Iterator<BigDecimal> iter = info.getOrderWeightList().iterator(); iter.hasNext();)
            {
                BigDecimal totalWeight = iter.next().add(info.getBoxWeight());
                for (Iterator<WeightCost> iter1 = weightCostList.iterator(); iter1.hasNext();)
                {
                    WeightCost wc = iter1.next();
                    if (totalWeight.compareTo(wc.getWeight()) == -1)
                    {
                        cost = cost.add(wc.getCost());
                        break;
                    }
                }
            }
     } else if (mode.equalsIgnoreCase(price))
        {
            if (order.getTotalIncTax() == null)
            {
                order.calculateTotals();
            }
            for (Iterator<WeightCost> iter1 = weightCostList.iterator(); iter1.hasNext();)
            {
                WeightCost wc = iter1.next();
                if (order.getTotalIncTax().compareTo(wc.getWeight()) == -1)
                {
                    cost = wc.getCost();
                    possible break?¿?¿
                }
            }
        } else
        {
            throw new KKException(
                    "The mode (MODULE_SHIPPING_TABLE_MODE) must be set to price or weight");
        }
..
..

This method evaluate table method. If table method equals weight , iterate with weightCostList and when found cost, break the for iteration .
But when te method equals price, iterate but never break. Cause, cost is te last iteracion.
This is a bug or is a correct function?
Thk's in advance, sorry for mi english

ejaen

Sorry the complet message is:


Hi, i'm working in a new ecommerce site with konakart solution. I try to configure Table Rate Shipping module with Price Table Method.
Appear not working and i try to debug com.konakart.bl.modules.shipping.table.Table class. In this class, have a method "getQuote"  with this code:

..
..
BigDecimal cost = new BigDecimal(0);
if (mode.equalsIgnoreCase(weight))
  {
            // Go through the weight cost list and figure out the cost

            /*
             * There is a list of weights since the total order weight may exceed the maximum weight
             * for a single package and so it has already been split up by the manager calling this
             * module.
             */
            for (Iterator<BigDecimal> iter = info.getOrderWeightList().iterator(); iter.hasNext();)
            {
                BigDecimal totalWeight = iter.next().add(info.getBoxWeight());
                for (Iterator<WeightCost> iter1 = weightCostList.iterator(); iter1.hasNext();)
                {
                    WeightCost wc = iter1.next();
                    if (totalWeight.compareTo(wc.getWeight()) == -1)
                    {
                        cost = cost.add(wc.getCost());
                        break;
                    }
                }
            }
     } else if (mode.equalsIgnoreCase(price))
        {
            if (order.getTotalIncTax() == null)
            {
                order.calculateTotals();
            }
            for (Iterator<WeightCost> iter1 = weightCostList.iterator(); iter1.hasNext();)
            {
                WeightCost wc = iter1.next();
                if (order.getTotalIncTax().compareTo(wc.getWeight()) == -1)
                {
                    cost = wc.getCost();
                    possible break??
                }
            }
        } else
        {
            throw new KKException(
                    "The mode (MODULE_SHIPPING_TABLE_MODE) must be set to price or weight");
        }


This method evaluate table method. If table method equals weight , iterate with weightCostList and when found cost, break the for iteration .
But when te method equals price, iterate but never break. Cause, cost is te last iteracion.
This is a bug or is a correct function?
Thk's in advance, sorry for mi english

julie

I think that it should function correctly. I suppose that the break could improve performance though.

It loops through the weightCostList (although in this mode the weight is being compared to the total order price). While the total price is less than the weight value in the list it sets cost to wc.getCost(). When it becomes equal or greater, it no longer sets cost so it should use the last value that it set which may not be the last iteration.


ejaen

For example  I've this  Shipping Table configuration:
25:8.50,50:5.50,10000:0.00

$0-$24.99 = $8.50
$24.99-$49.99 = $5.50
$50.00 and up Free ($0)

and mi order total  is  $26

and execute this code:

for (Iterator<WeightCost> iter1 = weightCostList.iterator(); iter1.hasNext();)
  {
        WeightCost wc = iter1.next();
        if (order.getTotalIncTax().compareTo(wc.getWeight()) == -1)
         {
              cost = wc.getCost();
         }
}


Iteration 1:
     order.getTotalIncTax()=26
     wc.getWeight()=25
     order.getTotalIncTax().compareTo(wc.getWeight()) == -1-->false , 26 not less than 25
     cost=0

Iteration 2:
     order.getTotalIncTax()=26
     wc.getWeight()=50
     order.getTotalIncTax().compareTo(wc.getWeight()) == -1-->true , 26 less than 50
     cost=$5.5

Iteration 3 (last iteration):
     order.getTotalIncTax()=26
     wc.getWeight()=10000
     order.getTotalIncTax().compareTo(wc.getWeight()) == -1-->true , 26 less than 10000
     cost=$0


and then cost have the last value of the iteration.
I'm wrong in the example?
Thk's in advance

julie

It looks like that in your case you definitely need the break. I suppose it all depends on the order of the list. i.e. If it were 10000:0.00,50:5.50,25:8.50 then it would work the way it is. One of the reasons we supply the source code of all of the modules (and an easy way of building them) is to allow you quickly customize them and match them to your needs.

However, our example setting is in ascending order so we'll put in a break for the next release to avoid confusion. ;)

ejaen

 :)  Thk's in advance Julie.
I'm guide from the weigth Table Method example and i was wrong. I think that is more cleared if Weigth Table Method and Price Table Method work same.
Thank u very much for u time.