Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

canada.post.rest.rate.service.oscommerce.V2.3


imageanative

Recommended Posts

@Druid6900 ok.. this issue with the width... For some reason we have (lines 412 to 414)

	$weight = $this->item_weight[$index];
	$price = round($this->item_price[$index],2);
	$width = $this->item_weight[$index];

Notice line 414 $width = is referencing item_weight

This should be

	$weight = $this->item_weight[$index];
	$price = round($this->item_price[$index],2);
	$width = $this->item_width[$index];

Still looking at the weight issue... trying to find where LBS and IN defined in admin (I don't think it is).

	 if($this->unit_weight == 'LBS') {
	 	//change to kilograms
	 	$weight = round($weight/2.2,3);
     }
    if($this->unit_length == 'IN') {
		//change to centimeters 	  
		$width = round($width * 2.54,1);
		$height = round($height * 2.54,1);
		$length = round($length * 2.54,1);
	}

 

Link to comment
Share on other sites

Quote

Still looking at the weight issue... trying to find where LBS and IN defined in admin (I don't think it is).

Ok looks like this is added with the configuration_shipping.sql for dimensional support....

How is your defind? LBS or KG? IN or CM?

Link to comment
Share on other sites

The items are all in Kgs and Cms and all weights and sizes are packages and ready-to-ship.

Should I make that width change in canadapost.php?

The file is unmodified from v 1.2

Edited by Druid6900

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

OK, if this helps any, it seems to pick up weights of 2 KGs and 15.5 KGs correctly, so, there must be some cut-off point below where it doesn't get the weights right and I'm guessing it's below 1 KG.

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

@Druid6900 can you test this for the weight issue? I just want to change the default from LBS and IN to KG and CM (as it should be for a Canadian based module).

And a question - are you using EDGE for GOLD... and do you know if are using

Change

// for those who will undoubtedly forget or not know how to run the configuration_shipping.sql
// we will set the default to pounds (LBS) and inches (IN)
          $this->unit_weight = 'LBS';
        }
        if (defined('SHIPPING_UNIT_LENGTH')) {
          $this->unit_length = SHIPPING_UNIT_LENGTH;
        } else {
          $this->unit_length = 'IN';
        }

To

// for those who will undoubtedly forget or not know how to run the configuration_shipping.sql
// we will set the default to pounds (KG) and inches (CM)
          $this->unit_weight = 'KG';
        }
        if (defined('SHIPPING_UNIT_LENGTH')) {
          $this->unit_length = SHIPPING_UNIT_LENGTH;
        } else {
          $this->unit_length = 'CM';
        }

 

Link to comment
Share on other sites

OK, well, the control for metric/imperial is in the Admin/configuration shipping module and is set to KGS/CM.

The tests I have run on the packages over 1 KG agree with the prices on the CPC Find-a Rate function perfectly when the values input are metric.

With that one particular package that was rated at 0.150 KGS, when I upped it to 1.15 KG, gave the right prices, but not if it was at less than 1 KG.

It seems that the minimum it will accept as a weight is 1 (in the case of metric. I haven't tried it in imperial.

I did notice, at line 185 in canadapost.php, that the code is trying to do some rounding function on the dimensions and weight, but I couldn't figure out how to change it with regards to the weight.

Thanks for helping get the stuff above 1 KG working right. It was so obvious, once it was pointed out :-)

 

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

@Druid6900 ok.... this is the last an only line that rounds the weight. First, in your admin make sure there is nothing in the "tare" config.... re-test if there was a "tare" weight... And then try to remove all rounding like....

 

        $this->item_weight[$index] = $weight;
Edited by greasemonkey
Link to comment
Share on other sites

@greasemonkey No, there was no tare in the shipping config.

I made the change and there was no difference and the xml request still shows the weight as 1, I'm afraid.

The only other example of rounding the weight is on line 420 when it changes lbs to kgs, but since my stuff is already in kgs, I don't see that affecting it.

When you posted the XML request to the CPC Dev site, all your parameters were correct. What difference is there in the file between yours and mine?

Edited by Druid6900

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

@Druid6900

The difference is I don't use dimensional support - therefore there is no length, width & height (in the test request I posted on the CP  developers forum I manual added dimensions to the file) ...  I would presume the weight is the same however.

Removing this set of rounding has worked for me....

        if ((float)$weight < 1.0) {
            $weight = 1;
        } else {
            $weight = round($weight, 3);

That said, I would definately test it by removing

	 if($this->unit_weight == 'LBS') {
	 	//change to kilograms
	 	$weight = round($weight/2.2,3);
     }
    if($this->unit_length == 'IN') {
		//change to centimeters 	  
		$width = round($width * 2.54,1);
		$height = round($height * 2.54,1);
		$length = round($length * 2.54,1);
	}

 

Link to comment
Share on other sites

@greasemonkeyI missed one of your questions; I'm using Gold BS.

OK, putting I in by hand explains a lot. LOL.

I don't have that first set of code in my canadapost.php file, so, I can't remove it and commenting out the second set of code had no affect.

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

I was looking at the first bit of code 2 messages up, and maybe we are going about this the wrong way....

What if we changed it like this

if ((float)$weight < 0.0001) {
            $weight = 1;
        } else {
            $weight = round($weight, 3);

And inserted it into the code?

Would that work to pick up items less than 1 KG (seeing as dimensional likes to pad things out to 3 decimal places)?

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

  • 3 weeks later...

OK, I have been trying to work out some code in an effort to pass on to this module the fact that weights less than 1 KG are valid and pass that to the CPC servers.

No matter what I try, $weight will not accept a value less than 1

The piece of code above, obviously, doesn't do it. I'm not a coder, so, it's probably a really simple task that eludes me completely.

Can anyone here help me work this out?

Thanks

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

21 hours ago, Druid6900 said:

OK, I have been trying to work out some code in an effort to pass on to this module the fact that weights less than 1 KG are valid and pass that to the CPC servers.

No matter what I try, $weight will not accept a value less than 1

The piece of code above, obviously, doesn't do it. I'm not a coder, so, it's probably a really simple task that eludes me completely.

Can anyone here help me work this out?

Thanks

HI Druid, I'm really not sure.... What I can tell you is this piece of code (if you still have it) will do what you are saying for weights less than 0.0001 kg

if ((float)$weight < 0.0001) {
            $weight = 1;
        } else {
            $weight = round($weight, 3);

To translate (to the best of my ability... I'm not a coder either) what this code is doing in words: "if the $weight is less than 0.0001 kg then make the $weight equal 1 kg" else (otherwise) "round the $weight to the 3rd decimal".

Again, my current version was doing the same thing removing the above code fixed it. I have removed this code (as well as the other fixes we spoke about in this tread) from the next version (which I have not yet released) - it is not needed or required and should not be included.

 

Link to comment
Share on other sites

@greasemonkey The code above, which was not previously in your V1.2 rendition, was something that I slightly modified from your post showing that you took it out.

I know enough about PHP to have figured out that this should do what I want it to do and allow sub-1KG values to exist, and be passed to CPC but, the problem I am having is that I don't know where about to insert it into the existing code in canadapost.php for it to work and not give me errors in the code.

BTW, if you are going to put out another version, there is some SEO code in the admin/categories.php file that should be taken out and the packaging code comes out a mess for box creation/editing.

There must be someone in Canada that is using this package that IS a coder that could clean up this code so that it could be used however a store owner needs to implement it. How about it, guys?

Even when we were all using CrashnBurn's pre-sellonline package, I figured out and shared how to have a selected handling percentage added to the information returned and displayed from the CPC server. Someone with talent could put this package together right in now time.

This package looks a lot better, but, in places, it is seriously broken and, as you know from all the great changes you've made to it, it always has been.

Maybe someone will step up to the plate since the original author seems to have abandoned it.

I mean, there is no law that says he has to, but, I've always been taught that, if you are going to do something, you do it right.

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

@Druid6900 sorry yes that exact code was not included in the current version... the exact original code was/is:

        if ((float)$weight < 1.0) {
            $weight = 1;
        } else {
            $weight = round($weight, 3);
        }

Which says: "if the $weight is less than 1 kg then make the $weight equal 1 kg" else (otherwise) "round the $weight to the 3rd decimal".

Which you are trying to replace with:

if ((float)$weight < 0.0001) {
            $weight = 1;
        } else {
            $weight = round($weight, 3);

Which says: "if the $weight is less than 0.0001 kg then make the $weight equal 1 kg" else (otherwise) "round the $weight to the 3rd decimal".

Which doesn't make a whole lot of sense (neither do)... which is why I'm saying remove it (either/both) as this has fixed the issued (remember I had the exact same issue despite me not using dimensional support).

Quote

This package looks a lot better, but, in places, it is seriously broken and, as you know from all the great changes you've made to it, it always has been.

Now - please keep in mind... most of us are not coders (those who are - are mostly likely more than happy to help you... for fee). I'm trying to support it the best I can... and i would not call it broken at all... It works perfectly for me and the issues that you have brought to my attention have been fixed (see function below).

Again replacing the above code with your code will fix your issue until you get to 0.0001 kg when it will change the weight back to 1kg (as I said... doesn't make sense to do that)

Removing it and leaving the following (i've included the entire function) should:

    function _addItem($length, $width, $height, $weight, $price = 0 ) {

        $index = $this->items_qty;
        $this->item_length[$index] = ($length ? (string)round((float)$length,1) : '0' );
        $this->item_width[$index] = ($width ? (string)round((float)$width,1) : '0' );
        $this->item_height[$index] = ($height ? (string)round((float)$height,1) : '0' );
        $this->item_weight[$index] = ($weight ? (string)round((float)$weight,1) : '0' );
        $this->item_price[$index] = $price;
        $this->items_qty++;
    }

 

Link to comment
Share on other sites

@greasemonkey I agree that both sets of code SHOULD not be necessary and that the $weight should be whatever is in the table for that item.

However, the comment for this function states "// Add box or item to shipment list. Round weights to 1 decimal places."

So, what would happen if you have a weight of 0.150? It would be rounded to 1.0 or, possibly 1.1 (I don't know the structure of the rounding operation). Both useful values, but, hardly interchangeable with .150

I have done as you suggested and removed that code and it still does exactly the same thing.

I understand that not everyone is a coder, but, I also understand that, if you are going to offer a package with multiple options, it would be nice if one checked that they all work, not just the one the author uses. Would you like me to repair your computer just to the point that it does the stuff that I use but not the stuff you need to work because I don't use it?

As for not being broken, do you recall that the above code had the width statement equaling the weight statement, so the width was always 1 (which you found). I'd call that broken. How about all the things that you've found and repaired? They must have been broken when the package was released.

I'm not saying that the author OWED us the package or that someone, even you, are required to spend your time making it work, the best you can, but, if you're going to write a contribution, why not get it right and/or give it a little support. "See what I wrote? Pretty cool, eh? It works 66% too. You're on your own." Why offer a package with dimensional support if it's not going to work right?

Yes, I'm sure that I can find someone to fix it so that it actually does dimensional support correctly, and I may just have to do that and, if I figure it out or pay someone to fix it, should I share it with the rest of the community or just say "Screw you"? No, I would share the fix so that everyone that downloaded it and expected it to do what it says it's supposed to do actually was pleasantly surprised that it did.

I was just saying that it would be nice if someone with the right skill set took a bit of time and fixed it and , like me, was able to take something broken and know the satisfaction that it is now repaired and working right and people who don't have skill set can install it and use it and not find out that, after all the work THEY put into getting it installed, that they are screwed because they put in all those dimensions for all those items (maybe during the previous versions of a Canada Post shipping module that DID work correctly) but they sure as hell aren't going to selling anything under a kilo or a pound because of faulty coding.

I repair and rebuild a lot of more current computers and donate them to places to get them to kids whose parent(s) can't afford to buy their kid(s) computers because they are poor. It usually costs me a fair amount in time and parts but it helps people. It also makes me feel good to have the skill set to be ABLE to help people. I guess I'm just strange.

GM, don't get me wrong. I appreciate all the work you've done fixing this package and all the time that it's taken you more than I could tell you, even to get to this point. If there is ever anything on the hardware side of this that I can do for you, just let me know.

I guess our definition of "community" differs from that of other people.

Edited by Druid6900

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

@Druid6900

Quote

So, what would happen if you have a weight of 0.150? It would be rounded to 1.0 or, possibly 1.1 (I don't know the structure of the rounding operation). Both useful values, but, hardly interchangeable with .150

With the original code (which will be removing from the next version)

        if ((float)$weight < 1.0) {
            $weight = 1;

0.150 kg would be 1 kg

With your versions OR if removed

if ((float)$weight < 0.0001) {
            $weight = 1;

it would stay as 0.150 kg

The rounding by the way is done (hence why I suggest this is not required) just a few lines down to 1 decimal here

        $this->item_weight[$index] = ($weight ? (string)round((float)$weight,1) : '0' );

So I guess technically 0.150 would probably show up as 0.2 kg (0.15 would round up).

I guess the point I was trying to make earlier (and now) is - if removing the code (to show as below) does not help - then something else causing your issue...

    function _addItem($length, $width, $height, $weight, $price = 0 ) {

        $index = $this->items_qty;
        $this->item_length[$index] = ($length ? (string)round((float)$length,1) : '0' );
        $this->item_width[$index] = ($width ? (string)round((float)$width,1) : '0' );
        $this->item_height[$index] = ($height ? (string)round((float)$height,1) : '0' );
        $this->item_weight[$index] = ($weight ? (string)round((float)$weight,1) : '0' );
        $this->item_price[$index] = $price;
        $this->items_qty++;
    }

 

Link to comment
Share on other sites

@greasemonkey Well, I guess it must be some else because my code looks identical to yours.

//********************************************
    function _addItem($length, $width, $height, $weight, $price = 0 ) {

        $index = $this->items_qty;
        $this->item_length[$index] = ($length ? (string)round((float)$length,1) : '0' );
        $this->item_width[$index] = ($width ? (string)round((float)$width,1) : '0' );
        $this->item_height[$index] = ($height ? (string)round((float)$height,1) : '0' );
        $this->item_weight[$index] = ($weight ? (string)round((float)$weight,1) : '0' );
        $this->item_price[$index] = $price;
        $this->items_qty++;
    }

//*********************************************************************************************

I have no idea what could be causing it unless there is some statement in there that prohibits the use of anything less that 1 on the left of the decimal place and I haven't seen it. I have noticed, though, that, if you put in a weight of .15 and save it, when you look again, it's been padded with a 0 to the left of the decimal place when you look again.

The weight and dimensions all seem to be handled in that file, so, it has to be somewhere in that canadapost.php file.

I have a LOT of items that are sub-kilo in weight, so, this is affecting a lot of my inventory.

Edited by Druid6900

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

OK, here's a good one for you.

If I select No to the question "Do you use the additional dimensions support?" in the admin configuration setup for this module, I get the right weight (.2 KG) and the right shipping price, but all my greater than 1 KG prices are wrong.

So, something in the module is forcing a minimum weight of 1 KG.....

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

1 hour ago, Druid6900 said:

OK, here's a good one for you.

If I select No to the question "Do you use the additional dimensions support?" in the admin configuration setup for this module, I get the right weight (.2 KG) and the right shipping price, but all my greater than 1 KG prices are wrong.

So, something in the module is forcing a minimum weight of 1 KG.....

lol... a good one indeed. The good news is you now know it is not the module - but associated with dimensional support files.

So, quickly looking at the addon there are 2 additional files used in dimensional support: admin/packaging.php (probably not the problem... it would not be loaded during checkout) and includes/classes/packing.php... this DEFINITELY would be loaded during checkout with dimensional support turned on....

This is where you need to start your search... looking for something similar to what we had found in the module file.

Let me know what you find.

Link to comment
Share on other sites

@greasemonkey I found this in includes/classes/packing;

if ((float)$weight < 1.0) {
            $weight = 1;
        } else {
            $weight = round($weight, 3);
        }

I removed it and the module, in ready to ship mode, works right, regardless of the weight..

I guess you can remove that for the next version of the package and now it's just a matter of fixing setting up the admin tools box sizes part of it and it will finally ALL work right.

Thanks for all the help, Scott, and, as I said, I owe you one.....

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

Too bad we didn't think of it a month ago, eh?

I removed all that packaging stuff a while bad, but, tomorrow, I'll put it back in and show you what it does.

We can go from there....

No Good Deed EVER Goes Unpunished

Link to comment
Share on other sites

  • 6 months later...

I am having issues with the Small Packet Air showing up in the shipping quotes when someone goes to checkout.  I do have insurance turned off and CP tech support is useless, so here I am.  I saw that there were the same issues, but I tried the suggested and still didn't work.  Any other suggestions? 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...