Page 1 of 1

shipping mod executed multiple time

Posted: Fri May 02, 2008 3:52 am
by boboxx
Hello guys,

I built a new shipping module for Canada Post, everything is working but the problem I have is that checkout_confirm is really slow.... after looking a bit, I it looks like the shipping module is being executed about 14 time!! Why is that?

My problem is that this is executing the Canada post web service way to many times. I tried to see where these where being called, but can figure it out.

Thanks

Re: shipping mod executed multiple time

Posted: Fri May 02, 2008 7:50 am
by bruce
It is impossible to even speculate on what is wrong.

You will need to post the shipping module code and any other changes you made to controller files or templates etc.

Re: shipping mod executed multiple time

Posted: Fri May 02, 2008 9:20 am
by boboxx
heheh yes I'm sure that would help!

here it is:
http://www.charetx2.com/oc/canadapost.zip

Re: shipping mod executed multiple time

Posted: Fri May 02, 2008 9:32 am
by bruce
I will have a look over the weekend.

Re: shipping mod executed multiple time

Posted: Mon May 05, 2008 4:35 pm
by Luvz2drv
hey boboxx    instead of looping thru all the products in the cart  use this

$cart_weight = $this->cart->getWeight();

it returns the value of the weight in the stores default weight (with quantity taken into account)..  you will need to custom it form there ..  remember each product can have its own weight type... :)     

also in my lib folder in the cart for weight.php  i added 2 new functions there  to help me out...

Code: Select all

function getID($unit) {
  		$id = $this->getDefaultID();
    	
    	//lets check the database for that unit -- language doen't matter as they all share the same id 
    	$results = $this->database->getRows("select weight_class_id from weight_class where unit = '$unit'");
    	if (count($results) >= 1) {
    		//just take the first one
			$id = $results[0]['weight_class_id'];
			return $id;
		} else {
			//no rows in the data - return the stores default
			return $id;
		}
    	
  	}
  	function getDefaultID() {
  		$weight_id_db = $this->database->getRows("SELECT value FROM `setting` WHERE `group` = 'config' and `key` = 'config_weight_class_id'");
		$weight_id = $weight_id_db[0]['value'];
		return $weight_id;
	}
came in handy as my stores weight default is in kg  -- but i needed to for my USPS to give me lb and oz

ussage i used....

Code: Select all

$cart_weight = $this->cart->getWeight();

$cart_weight_total = $this->weight->convert($cart_weight, $this->weight->getDefaultID(), $this->weight->getID('lb'));
			
$cart_weight_lbs = floor($cart_weight_total);
			
$cart_weight_oz_as_lbs = ($cart_weight_total - $cart_weight_lbs);
			
$cart_weight_oz = $this->weight->convert($cart_weight_oz_as_lbs, $this->weight->getID('lb'), $this->weight->getID('oz') );
			
hope some of that helps..

Jonathon

Re: shipping mod executed multiple time

Posted: Mon May 05, 2008 9:29 pm
by bruce
You are perfectly correct. The code is being called 14 times. In fact, it turns out that all shipping methods will have this problem but since yours involves going to another web site for info and takes some time, you are the first person to notice.

Have a look in the file library\cart\shipping.php and you will see that it makes no attempt to persist its data and that each of the utility functions call the quote function redundantly after checkout_shipping.

However, you can get around this by persisting the results of the quote function in your shipping extension in the session object. Hence, if the quote value exists AND the cart has not changed, then use the session value instead of calling canadapost again. To compare with the cart, your shipping extension also needs to persist it's own definition of the cart contents. eg: products, quantities, dimensions and weight.

You will also have to persist the shipping address geo zone that was used to calculate the quote and compare that with the current shipping address geo zone.

Re: shipping mod executed multiple time

Posted: Thu May 22, 2008 5:20 am
by Bijou
So, from what's being said here, I guess there's currently no Canada Post shipping module that works?

Re: shipping mod executed multiple time

Posted: Thu May 22, 2008 7:32 am
by Luvz2drv
i have one that is about 65% done and not having this issue

also working on USPS one too