Forums / Addon Shipping Modules / USPS Shipping 15 (No Lower than Fixed Rate)

USPS Shipping 15 (No Lower than Fixed Rate)

Views: 1,307

Results 1 to 7 of 7
12 Mar 2012, 3:29 AM
#1
ezorb avatar

ezorb

Zen Follower

Join Date:
Apr 2006
Location:
Midland TX
Posts:
426
Plugin Contributions:
0

USPS Shipping 15 (No Lower than Fixed Rate)

I need help with USPS Shipping 15 installing/fixing the below modification.
This code goes in includes/module/shipping/usps.php about line 268. The purpose is to not allow the USPS Quoted cost be below our Fixed Rate cost.

// ************* START MODIFICATION *****************
// if quoted cost is lower than flat rate module cost, mark up the cost to equal flat rate
$quoted_cost = ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes;
$adjusted_cost = ($quoted_cost < MODULE_SHIPPING_FLAT_COST ? MODULE_SHIPPING_FLAT_COST : $quoted_cost);
$methods[] = array('id' => $type,
'title' => $title,
'cost' => $adjusted_cost);
// ************* END MODIFICATION *****************

This is about all I lack to get 1.5.0 up.
Thanks

12 Mar 2012, 12:11 PM
#2
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: USPS Shipping 15 (No Lower than Fixed Rate)

EZorb:

I need help with USPS Shipping 15 installing/fixing the below modification.
This code goes in includes/module/shipping/usps.php about line 268. The purpose is to not allow the USPS Quoted cost be below our Fixed Rate cost. about all I lack to get 1.5.0 up.
Thanks

Forgive me for asking, but exactly what help is it that you need?

It seems to me that the code you supplied should do the job OK, so would I be wrong in assuming that you just need to know exactly where to place the code?

If so, I'd assume that if the usps code has been changed between versions it is probable that it'll still need to be inserted somewhere around the line# specified, and the best way to determine exactly where to place it would be to look at the original modified code at the lines immediately before and after this inserted code, then find the identical code in the updated file.

Please advice if I'm on the wrong track.

Cheers
Rod

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

13 Mar 2012, 12:04 AM
#3
ezorb avatar

ezorb

Zen Follower

Join Date:
Apr 2006
Location:
Midland TX
Posts:
426
Plugin Contributions:
0

Re: USPS Shipping 15 (No Lower than Fixed Rate)

RodG:

Forgive me for asking, but exactly what help is it that you need?

It seems to me that the code you supplied should do the job OK, so would I be wrong in assuming that you just need to know exactly where to place the code?

If so, I'd assume that if the usps code has been changed between versions it is probable that it'll still need to be inserted somewhere around the line# specified, and the best way to determine exactly where to place it would be to look at the original modified code at the lines immediately before and after this inserted code, then find the identical code in the updated file.

Please advice if I'm on the wrong track.

Cheers
Rod

I am using Beyond Compare and it appears that it wants to insert it in about same spot as 1.3.9h. I have tried changing this line ('title' => $title,) to what is used in 1.5.0 and also leaving it as is and does not work. It Kills the whole shipping mod. I don't know php so was asking for help.

13 Mar 2012, 12:44 AM
#4
ezorb avatar

ezorb

Zen Follower

Join Date:
Apr 2006
Location:
Midland TX
Posts:
426
Plugin Contributions:
0

Re: USPS Shipping 15 (No Lower than Fixed Rate)

RodG:

Forgive me for asking, but exactly what help is it that you need?

It seems to me that the code you supplied should do the job OK, so would I be wrong in assuming that you just need to know exactly where to place the code?

If so, I'd assume that if the usps code has been changed between versions it is probable that it'll still need to be inserted somewhere around the line# specified, and the best way to determine exactly where to place it would be to look at the original modified code at the lines immediately before and after this inserted code, then find the identical code in the updated file.

Please advice if I'm on the wrong track.

Cheers
Rod

EZorb:

I am using Beyond Compare and it appears that it wants to insert it in about same spot as 1.3.9h. I have tried changing this line ('title' => $title,) to what is used in 1.5.0 and also leaving it as is and does not work. It Kills the whole shipping mod. I don't know php so was asking for help.

I compared 1.3.9h usps.php to 1.5.0 usps.php and found a few lines above and below that were remark-out in 1.3.9h version. Also had to change in 1.5.0 version "$title = str_replace('**', '', $title);" back to 1.3.9h version "'title' => $title,"
Now it works.
If anyone sees anything wrong with this please give input.

13 Mar 2012, 1:30 AM
#5
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: USPS Shipping 15 (No Lower than Fixed Rate)

EZorb:

I compared 1.3.9h usps.php to 1.5.0 usps.php and found a few lines above and below that were remark-out in 1.3.9h version. Also had to change in 1.5.0 version "$title = str_replace('**', '', $title);" back to 1.3.9h version "'title' => $title,"
Now it works.
If anyone sees anything wrong with this please give input.

The code
$title = str_replace('', '', $title);
is there to remove "
" (if it exists) from the title string. If there isn't a '' in the string it has no effect... In other words, it will be the same as the old code that reads 'title' => $title," so as long as you don't have '' in the $title variable then all will be OK.

Now having said that, assuming what you posted here was a copy/paste I can now see the problem.
"$title = str_replace('', '', $title);" should actually be
"$title = str_replace('
', '', $title),"

Note the difference between the semi-colon and the comma at the end of the code snippets. The comma is correct, the semi-colon is going to cause an error.

Cheers
Rod

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

13 Mar 2012, 4:53 AM
#6
ezorb avatar

ezorb

Zen Follower

Join Date:
Apr 2006
Location:
Midland TX
Posts:
426
Plugin Contributions:
0

Re: USPS Shipping 15 (No Lower than Fixed Rate)

RodG:

The code
$title = str_replace('', '', $title);
is there to remove "
" (if it exists) from the title string. If there isn't a '' in the string it has no effect... In other words, it will be the same as the old code that reads 'title' => $title," so as long as you don't have '' in the $title variable then all will be OK.

Now having said that, assuming what you posted here was a copy/paste I can now see the problem.
"$title = str_replace('', '', $title);" should actually be
"$title = str_replace('
', '', $title),"

Note the difference between the semi-colon and the comma at the end of the code snippets. The comma is correct, the semi-colon is going to cause an error.

Cheers
Rod

Rod I thank you a bunch. I wonder why this has not caused an error before. I did copy/paste now I got to open the download and see if the ";" is in the original. The other thing I found was just a line below there is a "/" and a couple lines down should be the "/" which was missing, comparing to the 1.3.9h version of usps.php

For anyone that need this feature. If you use Flat Rate shipping this prevents USPS from being less than what you have Flat Rate set for. I also have simlar code for FedEx.

13 Mar 2012, 7:12 AM
#7
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: USPS Shipping 15 (No Lower than Fixed Rate)

EZorb:

The other thing I found was just a line below there is a "/" and a couple lines down should be the "/" which was missing, comparing to the 1.3.9h version of usps.php

The "/" signifies the start of a comment block (code that is never executed). The "/" signifies the end of the comment block.

For each "/" there should be a corresponding "/" otherwise it will be the same as saying 'don't run any code past this point', which is sure to cause major problems.

Now, having said that it is quite possible, even likely, that someone has inserted a "/*" within the comment block itself, in which case this second occurrence is ignored.

Example:

/* Start of comment block
any text can go here

  • any text can go here too
    /* here too (duplicate start comment is ignored)
  • this is yet another comment
    */ This one ends the comment block.
    functional code will start here

If you view the code with something that does Syntax highlighting it will become very clear where these comment blocks start and finish.

Cheers
Rod

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.