Jump to content
blucollarguy

Multi_Vendor_Shipping new thread

Recommended Posts

I have no idea. Obviously not the module, since mine doesn't work either. Something in your setup perhaps. I don't even know where to start looking for the problem. Sorry.

 

Regards

Jim

 

 

Well, now I'm really baffled.

I figured I'd disable UPSXML and just use the ups.php module instead as I really do need to use the ship estimator.

 

 

I don't get quotes with ups.php either!

the estimator will only return quotes for usps.php and freeamount.php (I use that one for gift certificates)

For the life of me I can't figure out why it is not getting any type of UPS quote regardless of which module I use.

 

any ideas at all where I should look?

aside from MVS, I have the following contribs on my site at www.cigarsforless.com that "might" affect this in some way but I can not see how.

Country State Selector

address enhancer v1.1

CCGV trad


Jim Bullen - President

The Cigar Hut Group of Companies

 

 

Installed add-ons: (that now need to be upgraded to OSC CE Phoenix)

PWA, MVS, Easy Populate, Dynamic Sitemap, Featured Products, MVS Order Editor, MVS Shipping Estimator, Google XML Sitemap, About Us, Ad Tracker, Address Enhancer, Also Purchased, Backorders, Category Descriptions, Dynamic Meta Tags, Contact Us Email Subjects, Country state Selector, Extra Address Line, Order Number in Email Subject, OSC Affiliate, Product Extra Fields, Review Approval System, Reviews in Product Display, Sold Out, Sold Out (but Displayed), Ultimate SEO URL's, Updated Spiders, Welcome Email Password, Pending Order Email, Who's Online Enhancement, CCGV, Easy Discounts, Customer Comments, Request a Review, Sales Report, plus many many more!

Share this post


Link to post
Share on other sites

Does anyone actually have a live site that uses mvs. I have tried implementing it numerous times. I have followed the directions with painstakingly accuracy. I am beginng to wonder if it actually workds.

 

I know a lot of people have spent a great deal of time on it, and that is to be commended.

 

Please let me know what the latest version is, where I can get it and how to implement it. I love the software, mvs would make life so easy.

 

Thank you for putting up with a novice like me.

Share this post


Link to post
Share on other sites

Jim: Did you try the version I posted above? What were the results?

 

Danny: Yes, it works. I have it running on two live stores and am about to add it to a third. Craig has it running on several more. Other people are also running it. If you are having problems installing it, post your specific errors here and we'll help.

 

The latest version is 1.1. There are three bugfixes posted after that that also need to be added. There are also a number of shipping modules posted that you can add if you need them.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites
Does anyone actually have a live site that uses mvs. I have tried implementing it numerous times. I have followed the directions with painstakingly accuracy. I am beginng to wonder if it actually workds.

 

I know a lot of people have spent a great deal of time on it, and that is to be commended.

 

Please let me know what the latest version is, where I can get it and how to implement it. I love the software, mvs would make life so easy.

 

Thank you for putting up with a novice like me.

 

 

Oh yes it does work! I have three very busy live stores using it for years now. Very good code.

 

You'll get it worked out!


Kendall

Brooklyn, New York USA

Share this post


Link to post
Share on other sites
Well, now I'm really baffled.

I figured I'd disable UPSXML and just use the ups.php module instead as I really do need to use the ship estimator.

I don't get quotes with ups.php either!

the estimator will only return quotes for usps.php and freeamount.php (I use that one for gift certificates)

For the life of me I can't figure out why it is not getting any type of UPS quote regardless of which module I use.

 

any ideas at all where I should look?

aside from MVS, I have the following contribs on my site at www.cigarsforless.com that "might" affect this in some way but I can not see how.

Country State Selector

address enhancer v1.1

CCGV trad

 

 

It is looking like the address enhancer v1.1 (http://addons.oscommerce.com/info/1868) contrib is the culprit

I have modified the ship estimator a bit to get it to work with ups.php when logged in but it still does not work when not logged in.

(still does not work at all with upsxml.php)


Jim Bullen - President

The Cigar Hut Group of Companies

 

 

Installed add-ons: (that now need to be upgraded to OSC CE Phoenix)

PWA, MVS, Easy Populate, Dynamic Sitemap, Featured Products, MVS Order Editor, MVS Shipping Estimator, Google XML Sitemap, About Us, Ad Tracker, Address Enhancer, Also Purchased, Backorders, Category Descriptions, Dynamic Meta Tags, Contact Us Email Subjects, Country state Selector, Extra Address Line, Order Number in Email Subject, OSC Affiliate, Product Extra Fields, Review Approval System, Reviews in Product Display, Sold Out, Sold Out (but Displayed), Ultimate SEO URL's, Updated Spiders, Welcome Email Password, Pending Order Email, Who's Online Enhancement, CCGV, Easy Discounts, Customer Comments, Request a Review, Sales Report, plus many many more!

Share this post


Link to post
Share on other sites
Jim: Did you try the version I posted above? What were the results?

 

Regards

Jim

 

 

Tried it and had no difference.

Still no UPS quotes.

Am working on figuring out the issues as posted above.

Will let you know if I get it to work...


Jim Bullen - President

The Cigar Hut Group of Companies

 

 

Installed add-ons: (that now need to be upgraded to OSC CE Phoenix)

PWA, MVS, Easy Populate, Dynamic Sitemap, Featured Products, MVS Order Editor, MVS Shipping Estimator, Google XML Sitemap, About Us, Ad Tracker, Address Enhancer, Also Purchased, Backorders, Category Descriptions, Dynamic Meta Tags, Contact Us Email Subjects, Country state Selector, Extra Address Line, Order Number in Email Subject, OSC Affiliate, Product Extra Fields, Review Approval System, Reviews in Product Display, Sold Out, Sold Out (but Displayed), Ultimate SEO URL's, Updated Spiders, Welcome Email Password, Pending Order Email, Who's Online Enhancement, CCGV, Easy Discounts, Customer Comments, Request a Review, Sales Report, plus many many more!

Share this post


Link to post
Share on other sites
Tried it and had no difference.

Still no UPS quotes.

Am working on figuring out the issues as posted above.

Will let you know if I get it to work...

 

 

OK, making some progress here...

 

If I do NOT select a shipping zone in the UPS modules I get quotes

This works for both ups.php and upsxml.php

 

BUT, I have a shipping zone set up for UPS that only includes the 51 states

APO PR etc are removed from the US state selection

 

if I select any of the shipping zones I have set up, I get no UPS quotes from the shipping estimator.

as soon as I set a module to use only a selected shipping zone, no ups quotes are returned

 

so..

 

now we know exactly what is causing the problem

how do I fix it?


Jim Bullen - President

The Cigar Hut Group of Companies

 

 

Installed add-ons: (that now need to be upgraded to OSC CE Phoenix)

PWA, MVS, Easy Populate, Dynamic Sitemap, Featured Products, MVS Order Editor, MVS Shipping Estimator, Google XML Sitemap, About Us, Ad Tracker, Address Enhancer, Also Purchased, Backorders, Category Descriptions, Dynamic Meta Tags, Contact Us Email Subjects, Country state Selector, Extra Address Line, Order Number in Email Subject, OSC Affiliate, Product Extra Fields, Review Approval System, Reviews in Product Display, Sold Out, Sold Out (but Displayed), Ultimate SEO URL's, Updated Spiders, Welcome Email Password, Pending Order Email, Who's Online Enhancement, CCGV, Easy Discounts, Customer Comments, Request a Review, Sales Report, plus many many more!

Share this post


Link to post
Share on other sites

Jim,

 

Thanks for the excellent job on re-working the MVS Shipping Estimator. The new buttons are a much better match to OSC's standard buttons and integration on the Product Info page is great.

 

Thanks,

Rick

Share this post


Link to post
Share on other sites
OK, making some progress here...

 

If I do NOT select a shipping zone in the UPS modules I get quotes

This works for both ups.php and upsxml.php

 

BUT, I have a shipping zone set up for UPS that only includes the 51 states

APO PR etc are removed from the US state selection

 

if I select any of the shipping zones I have set up, I get no UPS quotes from the shipping estimator.

as soon as I set a module to use only a selected shipping zone, no ups quotes are returned

 

so..

 

now we know exactly what is causing the problem

how do I fix it?

 

 

it seems that this zones issue affects all shipping modules.

As soon as I set a MVS shipping module Shipping Zone for a vendor

 

Shipping Zone

If a zone is selected, only enable this shipping method for that zone.

 

the shipping estimator returns no quotes regardless of the shipping module used

 

if no shipping zone is set, then the shipping estimator works like a charm!

 

on a side note, it would be real nice if we could get the shipping estimator to display an error message if no quote was returned.

Something like:

"Sorry, we are unable to obtain an estimate at this time. Please proceed to checkout to see your shipping options and rates"


Jim Bullen - President

The Cigar Hut Group of Companies

 

 

Installed add-ons: (that now need to be upgraded to OSC CE Phoenix)

PWA, MVS, Easy Populate, Dynamic Sitemap, Featured Products, MVS Order Editor, MVS Shipping Estimator, Google XML Sitemap, About Us, Ad Tracker, Address Enhancer, Also Purchased, Backorders, Category Descriptions, Dynamic Meta Tags, Contact Us Email Subjects, Country state Selector, Extra Address Line, Order Number in Email Subject, OSC Affiliate, Product Extra Fields, Review Approval System, Reviews in Product Display, Sold Out, Sold Out (but Displayed), Ultimate SEO URL's, Updated Spiders, Welcome Email Password, Pending Order Email, Who's Online Enhancement, CCGV, Easy Discounts, Customer Comments, Request a Review, Sales Report, plus many many more!

Share this post


Link to post
Share on other sites

I just installed this on my site and I was testing before I added it to my live store with the test.php file.

 

Here is what I get when I try to request a quote.

 

It does the first shipping method fine (USPS)

 

Then it says,

 

Federal Express (Total items: 0 pcs. Total weight: 0 lbs)

 

Warning: Invalid argument supplied for foreach() in /home/ganodco/public_html/ship_estimator.php on line 717

Share this post


Link to post
Share on other sites

Here's where we are on the Shipping Estimator bugs/issues:

 

The Zones bug is confirmed. I have tested this and confirmed that it always happens. I don't know why yet; that will take further investigation. I probably won't be able to work on this for a day or two. Anybody who wants to poke at the code is more than welcome.

 

The conflict with the Address Book Enhancer contribution is unconfirmed but entirely possible. Address Book Enhancer changes the way osCommerce deals with addresses. The Shipping Estimator will probably need to be modified to deal with those changes.

 

The "hang" problem is unconfirmed. I can't get the Shipping Estimator to hang under any circumstances. My experimental code to deal with a possible runaway redirect apparently had no effect. I don't have any more ideas to test out here, so any more data would be welcome.

 

The conflict with the Royal Mail module is unconfirmed. It may be one of the above bugs. More testing is needed after we've solved at least one of the above.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites
I just installed this on my site and I was testing before I added it to my live store with the test.php file.

 

Here is what I get when I try to request a quote.

 

It does the first shipping method fine (USPS)

 

Then it says,

 

Federal Express (Total items: 0 pcs. Total weight: 0 lbs)

 

Warning: Invalid argument supplied for foreach() in /home/ganodco/public_html/ship_estimator.php on line 717

From the error message, FedEx is seeing zero products with zero weight, which should cause FedEx to return an error message. The foreach() error is probably caused by FedEx returning nothing at all, or timing out. That shouldn't happen, but then, neither should asking for a quote on zero products. I don't know what is going on there. I can fix the error in the Shipping Estimator, but that won't stop the invalid Fedex quote. Is FedEx enabled on a different vendor than UPS? Are there products from the FedEx vendor in the cart?

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites
(snip)

The conflict with the Address Book Enhancer contribution is unconfirmed but entirely possible. Address Book Enhancer changes the way osCommerce deals with addresses. The Shipping Estimator will probably need to be modified to deal with those changes.

 

 

I have figured out that the Address Book Enhancer contribution does not in fact affect the Shipping Estimator at all.

(If I disable shipping zones, the estimator returns proper quotes and addresses when the shipping address book entry is changed)

This can be considered closed as it is not an issue


Jim Bullen - President

The Cigar Hut Group of Companies

 

 

Installed add-ons: (that now need to be upgraded to OSC CE Phoenix)

PWA, MVS, Easy Populate, Dynamic Sitemap, Featured Products, MVS Order Editor, MVS Shipping Estimator, Google XML Sitemap, About Us, Ad Tracker, Address Enhancer, Also Purchased, Backorders, Category Descriptions, Dynamic Meta Tags, Contact Us Email Subjects, Country state Selector, Extra Address Line, Order Number in Email Subject, OSC Affiliate, Product Extra Fields, Review Approval System, Reviews in Product Display, Sold Out, Sold Out (but Displayed), Ultimate SEO URL's, Updated Spiders, Welcome Email Password, Pending Order Email, Who's Online Enhancement, CCGV, Easy Discounts, Customer Comments, Request a Review, Sales Report, plus many many more!

Share this post


Link to post
Share on other sites
Here's where we are on the Shipping Estimator bugs/issues:

(snip)

The Zones bug is confirmed. I have tested this and confirmed that it always happens. I don't know why yet; that will take further investigation. I probably won't be able to work on this for a day or two. Anybody who wants to poke at the code is more than welcome.

 

Regards

Jim

 

 

From what I can tell, we need to collect the State info to set the Zone id

If a shipping zone is selected in the shipping module, it looks to see if the delivery address zone id is within the selected shipping zone restrictions

no zone id, no quote

 

will play with the code to see if I can patch something together


Jim Bullen - President

The Cigar Hut Group of Companies

 

 

Installed add-ons: (that now need to be upgraded to OSC CE Phoenix)

PWA, MVS, Easy Populate, Dynamic Sitemap, Featured Products, MVS Order Editor, MVS Shipping Estimator, Google XML Sitemap, About Us, Ad Tracker, Address Enhancer, Also Purchased, Backorders, Category Descriptions, Dynamic Meta Tags, Contact Us Email Subjects, Country state Selector, Extra Address Line, Order Number in Email Subject, OSC Affiliate, Product Extra Fields, Review Approval System, Reviews in Product Display, Sold Out, Sold Out (but Displayed), Ultimate SEO URL's, Updated Spiders, Welcome Email Password, Pending Order Email, Who's Online Enhancement, CCGV, Easy Discounts, Customer Comments, Request a Review, Sales Report, plus many many more!

Share this post


Link to post
Share on other sites
I have figured out that the Address Book Enhancer contribution does not in fact affect the Shipping Estimator at all.

(If I disable shipping zones, the estimator returns proper quotes and addresses when the shipping address book entry is changed)

This can be considered closed as it is not an issue

Thanks for that. One potential bug off the list, three to go. I have some unexpected time this evening, so I'll take a look at the Zones issue. Perhaps I can get a handle on what's going wrong there.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

My goodness things have been busy here. For some reason I haven't been getting my emails. The Estimator looks pretty good Jim, I like the version from the product_info page, very cool

 

I am guessing from just a quick look through the code here, but the issue with the "Zones" not allowing quotes could be caused from not setting "zone_id" as part of the "order" class.

The "zone_id" is in the $order-> array from the "cart" function in the order class. One would need to populate that value in order for the shipping modules to function correctly. If you can't find it I will try to make some time over the weekend to look more deeply into the code and work out how to populate that value.

 

Very nice work though. The original version that was uploaded looks like some code I rushed through a long time ago, but I can't remember who I did it for and can't find it in my notes or archives. I had done a quick version of a popup estimator and had intended to go back and re-write it later, but never did. It seems you have beaten me to it one way or the other.

 

Craig :)


Happy Coding!

Craig Garrison Sr

Anything worth having, is worth working for.

Multi Vendor Shipping V1.1 Demo Catalog

3 Vendors, each category, "buy" a product from each category to see how MVS works during checkout.

Multi Vendor Shipping V1.1 Demo Admin

login: webmaster@blucollarsales.com

pass: mvs_demo

MVS Thread:

Multi-Vendor Shipping

My contribs:

Download Multi Vendor Shipping V1.1

Vendor Email

Vendor Info in easypopulate

EZ Price Updater

And more to come!

Share this post


Link to post
Share on other sites
My goodness things have been busy here. For some reason I haven't been getting my emails. The Estimator looks pretty good Jim, I like the version from the product_info page, very cool

<snip>

Craig :)

Thanks Craig. Version 1.0 of this thing has my initials on it, but I don't remember doing it. I certainly didn't mean to steal your code. You're perfectly welcome to it.

 

I was aware of the zone not being set for customers that are not logged in. We could either ask the customer for that information or calculate it from the Postcode. The last would require an enormous database table -- the US table alone is over 43,000 rows. I would be very pleased if you could come up with a better way to do this.

 

The problem here is that the zone still doesn't work if the customer is logged in and that value is populated. I'm still trying to track that down. Not much time to look at it, so I haven't gotten very far.

 

The forum periodically deletes my notifications, and sometimes fails to email me even when the notification is still set. Go figure. I'm keeping some of the more important ones (like MVS) open in browser tabs so that I can go check them every day or two. I still miss things, so feel free to PM or email me a reminder if you need me.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites
Thanks Craig. Version 1.0 of this thing has my initials on it, but I don't remember doing it. I certainly didn't mean to steal your code. You're perfectly welcome to it.

 

I was aware of the zone not being set for customers that are not logged in. We could either ask the customer for that information or calculate it from the Postcode. The last would require an enormous database table -- the US table alone is over 43,000 rows. I would be very pleased if you could come up with a better way to do this.

 

The problem here is that the zone still doesn't work if the customer is logged in and that value is populated. I'm still trying to track that down. Not much time to look at it, so I haven't gotten very far.

 

The forum periodically deletes my notifications, and sometimes fails to email me even when the notification is still set. Go figure. I'm keeping some of the more important ones (like MVS) open in browser tabs so that I can go check them every day or two. I still miss things, so feel free to PM or email me a reminder if you need me.

 

Regards

Jim

You didn't steal anything, if it is something I did, I probably didn't intend it to be released in that condition.

 

I had to do something of this sort(finding a zone_id) with some other project I was working on some time back, I will see if I can remember what I did. The fact that the zones still don't work when the zone_id is populated certainly complicates the bug hunt. I may have some time later tonight(if I don't simply pass out at my laptop again) and I may play with it a bit.

 

Maybe simply request the state form a dropdown perhaps. But I guess one of the points is to ask as little of the customer as possible.

 

Hmmmmm.....


Happy Coding!

Craig Garrison Sr

Anything worth having, is worth working for.

Multi Vendor Shipping V1.1 Demo Catalog

3 Vendors, each category, "buy" a product from each category to see how MVS works during checkout.

Multi Vendor Shipping V1.1 Demo Admin

login: webmaster@blucollarsales.com

pass: mvs_demo

MVS Thread:

Multi-Vendor Shipping

My contribs:

Download Multi Vendor Shipping V1.1

Vendor Email

Vendor Info in easypopulate

EZ Price Updater

And more to come!

Share this post


Link to post
Share on other sites

I found the problem with logged-in customers. If you want to have the module use the zone ID from the order, you have to instantiate the order class before the modules. D'oh!

 

The best way to handle customers that are not logged in still seems to be asking them for the delivery state/province. I can add a config selection to turn this off if you don't need to use zones. Unless somebody can come up with a better way to do this....

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

This has turned out to be a massive pain. I hope that nobody else is working on this. I wouldn't wish this mess on anybody. Well, maybe ... better not go there. Anyway, part of the problem was in getting everything done in just the right order. There are so many dependencies in the modules system that it's a bit of a miracle that it ever worked.

 

The really nasty part is apparently a bug in PHP. Well, it's in version 5.2.5 for certain, and probably the rest. In order to get a quote when the customer is not signed in, we've been faking the variables that the modules need to get from the order class. It turns out that this works just fine except in a class constructor. And of course the zone ID is set in the class constructor of the shipping modules. I had a lot of fun tracking that one down. This really shouldn't be considered a bug, since you shouldn't expect to pass variables in a class that doesn't exist. So we've been using the bug all along in the Shipping Estimator. I just found a case where the bug isn't. Anyway, I managed to fix it by creating the class, which then allows the variables to be faked. Works fine. Wish I could say the same for my head. I'm still trying to wrap my brain around this one.

 

Oh, and there are problems with a couple of the modules. The Table and First item Plus modules don't handle zones correctly. If you think it's fun finding bugs in the language, try debugging with modules that don't work right in the first place.

 

I need to clean up my code a bit, and port the changes over into the products estimator file, then I'll post the whole mess. Maybe tomorrow.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

I've uploaded V2.1 of the Shipping Estimator. This should fix issues with the use of Zones, plus some other odd bugs. As I noted (OK, ranted) above, bugs in this thing were nasty. If you were having problems with this module before, please upgrade to 2.1 and let us know if it fixed the problem. It works fine on my machine, but I have no way of knowing if it will work under different conditions.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

after installed mvs shipping estimator(I only used product shipping estimator), package tare weight doesn't add to USPS shipping, FedEx works tho. Do you have usps.php for vendor shipping? Can you send me the code?

 

Thanks.

 

If I disable vendor shipping, both working.

Edited by blafrog

Share this post


Link to post
Share on other sites
after installed mvs shipping estimator(I only used product shipping estimator), package tare weight doesn't add to USPS shipping, FedEx works tho. Do you have usps.php for vendor shipping? Can you send me the code?

 

Thanks.

 

If I disable vendor shipping, both working.

Sounds like a bug in the USPS module. I'll take a look at that as soon as I can. I don't have a USPS account to test with, so any changes will be untested.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites
Sounds like a bug in the USPS module. I'll take a look at that as soon as I can. I don't have a USPS account to test with, so any changes will be untested.

 

Regards

Jim

 

 

Tare weight gets added on my site for USPS.php but zones don't work

This is not an issue for me though as I do not use any zone restrictions for USPS

 

Below is a copy of my USPS.php for MVS that works for me

 

<?php

/*

$Id: usps.php,v 1.47 2003/04/08 23:23:42 dgw_ Exp $

++++ modified as USPS Methods 2.5 08/02/03 by Brad Waite and Fritz Clapp ++++

 

Modified for MVS by Rick Knight

 

Modified for May 14, 2007 Service update by Jared De Blander of www.iofast.com

and www.bmotorsports.com. Based on USPSMethods_2.8d Updates for May 14 Rates &

Service Changes (minor correction) found at:

http://www.oscommerce.com/community/contri...ons,487/page,12

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

class usps {

var $code, $title, $description, $icon, $enabled, $countries;

 

// class constructor

function usps() {

global $order;

// Added MVS

// $this->vendors_id = ($products['vendors_id'] <= 0) ? 1 : $products['vendors_id'];

// End ADD

 

$this->code = 'usps';

$this->title = MODULE_SHIPPING_USPS_TEXT_TITLE;

$this->description = MODULE_SHIPPING_USPS_TEXT_DESCRIPTION;

$this->icon = DIR_WS_ICONS . 'shipping_usps.gif';

$this->delivery_country_id = $order->delivery['country']['id'];

$this->delivery_zone_id = $order->delivery['zone_id'];

// Removed MVS

/*

$this->sort_order = MODULE_SHIPPING_USPS_SORT_ORDER;

$this->tax_class = MODULE_SHIPPING_USPS_TAX_CLASS;

$this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false);

 

if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_ZONE > 0) ) {

$check_flag = false;

$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_USPS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");

while ($check = tep_db_fetch_array($check_query)) {

if ($check['zone_id'] < 1) {

$check_flag = true;

break;

} elseif ($check['zone_id'] == $order->delivery['zone_id']) {

$check_flag = true;

break;

}

}

 

if ($check_flag == false) {

$this->enabled = false;

}

}

End of Remove

*/

$this->types = array('EXPRESS' => 'USPS Express Mail',

'FIRST CLASS' => 'USPS First-Class Mail',

'PRIORITY' => 'USPS Priority Mail',

'PARCEL' => 'USPS Parcel Post');

/*

$this->intl_types = array('GXG Document' => 'Global Express Guaranteed Document Service',

'GXG Non-Document' => 'Global Express Guaranteed Non-Document Service',

'Express' => 'Global Express Mail (EMS)',

// 'Priority Lg' => 'Global Priority Mail - Flat-rate Envelope (large)',

'Priority Lg' => 'Global Priority Mail - Flat-rate Envelope (Large)',

// 'Priority Sm' => 'Global Priority Mail - Flat-rate Envelope (small)',

'Priority Sm' => 'Global Priority Mail - Flat-rate Envelope (Small)',

// 'Priority Var' => 'Global Priority Mail - Variable Weight Envelope (single)',

'Priority Var' => 'Global Priority Mail - Variable Weight Envelope (Single)',

// 'Airmail Letter' => 'Airmail Letter Post',

'Airmail Letter' => 'Airmail Letter-post',

'Airmail Parcel' => 'Airmail Parcel Post',

// 'Surface Letter' => 'Economy (Surface) Letter Post',

'Surface Letter' => 'Economy (Surface) Letter-post',

'Surface Post' => 'Economy (Surface) Parcel Post');

*/

 

$this->intl_types = array(

'Global Express' => 'Global Express Guaranteed',

'Global Express Non-Doc Rect' => 'Global Express Guaranteed Non-Document Rectangular',

'Global Express Non-Doc Non-Rect' => 'Global Express Guaranteed Non-Document Non-Rectangular',

'Express Mail Int' => 'Express Mail International (EMS)',

'Express Mail Int Flat Rate Env' => 'Express Mail International (EMS) Flat Rate Envelope',

'Priority Mail Int' => 'Priority Mail International',

'Priority Mail Int Flat Rate Env' => 'Priority Mail International Flat Rate Envelope',

'Priority Mail Int Flat Rate Box' => 'Priority Mail International Flat Rate Box',

'First-Class Mail Int' => 'First-Class Mail International'

);

 

$this->countries = $this->country_list();

}

 

// MVS ADD

function sort_order($vendors_id='1') {

$sort_order = @constant ('MODULE_SHIPPING_USPS_SORT_ORDER_' . $vendors_id);

if (isset ($sort_order)) {

$this->sort_order = $sort_order;

} else {

$this->sort_order = '-';

}

return $this->sort_order;

}

 

function tax_class($vendors_id='1') {

$this->tax_class = constant('MODULE_SHIPPING_USPS_TAX_CLASS_' . $vendors_id);

return $this->tax_class;

}

/*

function enabled($vendors_id='1') {

$this->enabled = false;

$status = @constant('MODULE_SHIPPING_USPS_STATUS_' . $vendors_id);

if (isset ($status) && $status != '') {

$this->enabled = (($status == 'True') ? true : false);

}*/

function enabled($vendors_id='1') {

 

$this->enabled = false;

 

$status = @constant('MODULE_SHIPPING_USPS_STATUS_' . $vendors_id);

 

if (isset ($status) && $status != '') {

 

$this->enabled = (($status == 'True') ? true : false);

 

}

if ( ($this->enabled == true) && ((int)constant('MODULE_SHIPPING_USPS_ZONE_' . $vendors_id) > 0) ) {

$check_flag = false;

$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . (int)constant('MODULE_SHIPPING_USPS_ZONE_' . $vendors_id) . "' and zone_country_id = '" . $this->delivery_country_id . "' order by zone_id");

while ($check = tep_db_fetch_array($check_query)) {

if ($check['zone_id'] < 1) {

$check_flag = true;

break;

}

elseif ($check['zone_id'] == $this->delivery_zone_id) {

$check_flag = true;

break;

}

}

 

if ($check_flag == false) {

$this->enabled = false;

}//if

}//if

return $this->enabled;

}

 

function zones($vendors_id='1') {

/*

if ( ($this->enabled == true) && ((int)constant('MODULE_SHIPPING_USPS_ZONE_' . $vendors_id) > 0) ) {

$check_flag = false;

$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . (int)constant('MODULE_SHIPPING_USPS_ZONE_' . $vendors_id) . "' and zone_country_id = '" . $this->delivery_zone_id . "' order by zone_id");

*/

if ( ($this->enabled == true) && ((int)constant('MODULE_SHIPPING_USPS_ZONE_' . $vendors_id) > 0) ) {

 

$check_flag = false;

 

$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . (int)constant('MODULE_SHIPPING_USPS_ZONE_' . $vendors_id) . "' and zone_country_id = '" . $this->delivery_country_id . "' order by zone_id");

while ($check = tep_db_fetch_array($check_query)) {

if ($check['zone_id'] < 1) {

$check_flag = true;

break;

} elseif ($check['zone_id'] == $this->delivery_zone_id) {

$check_flag = true;

break;

} //if

}//while

 

if ($check_flag == false) {

$this->enabled = false;

}//if

}//if

return $this->enabled;

}//function

// EOADD MVS

 

// class methods

// Changed MVS

// function quote($method = '') {

function quote($method = '', $module = '', $vendors_id = '1') {

// EOCHANGE

 

// BOF: UPS USPS

global $HTTP_POST_VARS, $shipping_weight, $order, $cart, $shipping_num_boxes, $transittime;

 

if ( tep_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types)) ) {

$this->_setService($method);

}

 

$this->_setMachinable('False');

$this->_setContainer('None');

$this->_setSize('REGULAR');

 

// usps doesnt accept zero weight

$shipping_weight = ($shipping_weight < 0.1 ? 0.1 : $shipping_weight);

$shipping_pounds = floor ($shipping_weight);

$shipping_ounces = round(16 * ($shipping_weight - floor($shipping_weight)));

$this->_setWeight($shipping_pounds, $shipping_ounces);

// BOF: UPS USPS

 

if (in_array('Display weight', explode(', ', constant('MODULE_SHIPPING_USPS_OPTIONS_' . $vendors_id)))) {

$shiptitle = ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'lbs)';

} else {

$shiptitle = '';

}

// EOF: UPS USPS

 

$uspsQuote = $this->_getQuote($vendors_id);

 

if (is_array($uspsQuote)) {

if (isset($uspsQuote['error'])) {

$this->quotes = array('module' => $this->title,

'error' => $uspsQuote['error']);

} else {

 

// Added MVS

$vendors_data_query = tep_db_query("select handling_charge,

handling_per_box,

vendor_country,

vendors_zipcode

from " . TABLE_VENDORS . "

where vendors_id = '" . (int)$vendors_id . "'"

);

$vendors_data = tep_db_fetch_array($vendors_data_query);

$country_name = tep_get_countries($vendors_data['vendor_country'], true);

 

$handling_charge = $vendors_data['handling_charge'];

$handling_per_box = $vendors_data['handling_per_box'];

if ($handling_charge > $handling_per_box*$shipping_num_boxes) {

$handling = $handling_charge;

} else {

$handling = $handling_per_box*$shipping_num_boxes;

}

// EOADD MVS

 

/* Original

$this->quotes = array('id' => $this->code,

'module' => $this->title . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'lbs)');

*/

// BOF: UPS USPS

$this->quotes = array('id' => $this->code,

'module' => $this->title . $shiptitle);

// EOF: UPS USPS

 

$methods = array();

$size = sizeof($uspsQuote);

for ($i=0; $i<$size; $i++) {

list($type, $cost) = each($uspsQuote[$i]);

 

// BOF: UPS USPS

$title = ((isset($this->types[$type])) ? $this->types[$type] : $type);

if(in_array('Display transit time', explode(', ', constant('MODULE_SHIPPING_USPS_OPTIONS_' . $vendors_id)))) $title .= $transittime[$type];

 

/* ORIGINAL

$methods[] = array('id' => $type,

'title' => ((isset($this->types[$type])) ? $this->types[$type] : $type),

'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);

*/

// if(!stristr($title, 'First-Class') === false) $cost*=1.27;

// if(!stristr($title, 'Priority') === false) $cost*=1.07;

 

 

 

$methods[] = array('id' => $type,

'title' => $title,

'cost' => ($cost + $handling) * $shipping_num_boxes);

}

// EOF: UPS USPS

 

$this->quotes['methods'] = $methods;

// $this->tax_class = constant(MODULE_SHIPPING_USPS_TAX_CLASS_ . $vendors_id);

if ($this->tax_class($vendors_id) > 0) {

$this->quotes['tax'] = tep_get_tax_rate($this->tax_class($vendors_id), $order->delivery['country']['id'], $order->delivery['zone_id']);

}

}

} else {

$this->quotes = array('module' => $this->title,

'error' => MODULE_SHIPPING_USPS_TEXT_ERROR);

}

 

if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);

 

return $this->quotes;

}

 

// MVS Added/Changed

// function check() {

function check($vendors_id = '1') {

//EOMVS

 

if (!isset($this->_check)) {

// MVS Added/Changed

// $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_STATUS'");

$check_query = tep_db_query("select configuration_value from " . TABLE_VENDOR_CONFIGURATION . " where vendors_id = '". $vendors_id ."' and configuration_key = 'MODULE_SHIPPING_USPS_STATUS_" . $vendors_id . "'");

// EOMVS

 

$this->_check = tep_db_num_rows($check_query);

}

return $this->_check;

}

 

// MVS Added/Changed

/*

function install() {

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable USPS Shipping', 'MODULE_SHIPPING_USPS_STATUS', 'True', 'Do you want to offer USPS shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the USPS User ID', 'MODULE_SHIPPING_USPS_USERID', 'NONE', 'Enter the USPS USERID assigned to you.', '6', '0', now())");

// BOF: UPS USPS

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the USPS Password', 'MODULE_SHIPPING_USPS_PASSWORD', 'NONE', 'See USERID, above.', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Which server to use', 'MODULE_SHIPPING_USPS_SERVER', 'production', 'An account at USPS is needed to use the Production server', '6', '0', 'tep_cfg_select_option(array(\'test\', \'production\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_USPS_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_USPS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_USPS_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_USPS_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Domestic Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES', 'Express, Priority, First Class, Parcel', 'Select the domestic services to be offered:', '6', '14', 'tep_cfg_select_multioption(array(\'Express\', \'Priority\', \'First Class\', \'Parcel\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Int\'l Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES_INTL', 'GXG Document, GXG Non-Document, Express, Priority Lg, Priority Sm, Priority Var, Airmail Letter, Airmail Parcel, Surface Letter, Surface Post', 'Select the international services to be offered:', '6', '15', 'tep_cfg_select_multioption(array(\'GXG Document\', \'GXG Non-Document\', \'Express\', \'Priority Lg\', \'Priority Sm\', \'Priority Var\', \'Airmail Letter\', \'Airmail Parcel\', \'Surface Letter\', \'Surface Post\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('USPS Options', 'MODULE_SHIPPING_USPS_OPTIONS', 'Display weight, Display transit time', 'Select from the following the USPS options.', '6', '16', 'tep_cfg_select_multioption(array(\'Display weight\', \'Display transit time\'), ', now())");

// EOF: UPS USPS

}

*/

function install($vendors_id = '1') {

tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added, vendors_id) values ('Enable USPS Shipping', 'MODULE_SHIPPING_USPS_STATUS_" . $vendors_id . "', 'True', 'Do you want to offer USPS shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now(), '" . $vendors_id . "')");

tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, vendors_id) values ('Enter the USPS User ID', 'MODULE_SHIPPING_USPS_USERID_" . $vendors_id . "', 'NONE', 'Enter the USPS USERID assigned to you.', '6', '0', now(), '" . $vendors_id . "')");

// BOF: UPS USPS

tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, vendors_id) values ('Enter the USPS Password', 'MODULE_SHIPPING_USPS_PASSWORD_" . $vendors_id . "', 'NONE', 'See USERID, above.', '6', '0', now(), '" . $vendors_id . "')");

tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added, vendors_id) values ('Which server to use', 'MODULE_SHIPPING_USPS_SERVER_" . $vendors_id . "', 'production', 'An account at USPS is needed to use the Production server', '6', '0', 'tep_cfg_select_option(array(\'test\', \'production\'), ', now(), '" . $vendors_id . "')");

tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, vendors_id) values ('Handling Fee', 'MODULE_SHIPPING_USPS_HANDLING_" . $vendors_id . "', '0', 'Handling fee for this shipping method.', '6', '0', now(), '" . $vendors_id . "')");

tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added, vendors_id) values ('Tax Class', 'MODULE_SHIPPING_USPS_TAX_CLASS_" . $vendors_id . "', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now(), '" . $vendors_id . "')");

tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added, vendors_id) values ('Shipping Zone', 'MODULE_SHIPPING_USPS_ZONE_" . $vendors_id . "', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now(), '" . $vendors_id . "')");

tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, vendors_id) values ('Sort Order', 'MODULE_SHIPPING_USPS_SORT_ORDER_" . $vendors_id . "', '0', 'Sort order of display.', '6', '0', now(), '" . $vendors_id . "')");

tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added, vendors_id) values ('Domestic Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES_" . $vendors_id . "', 'EXPRESS, PRIORITY, FIRST CLASS, PARCEL', 'Select the domestic services to be offered:', '6', '14', 'tep_cfg_select_multioption(array(\'EXPRESS\', \'PRIORITY\', \'FIRST CLASS\', \'PARCEL\'), ', now(), '" . $vendors_id . "')");

//old

// tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added, vendors_id) values ('Int\'l Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES_INTL_" . $vendors_id . "', 'GXG Document, GXG Non-Document, Express, Priority Lg, Priority Sm, Priority Var, Airmail Letter, Airmail Parcel, Surface Letter, Surface Post', 'Select the international services to be offered:', '6', '15', 'tep_cfg_select_multioption(array(\'GXG Document\', \'GXG Non-Document\', \'Express\', \'Priority Lg\', \'Priority Sm\', \'Priority Var\', \'Airmail Letter\', \'Airmail Parcel\', \'Surface Letter\', \'Surface Post\'), ', now(), '" . $vendors_id . "')");

//new

tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added, vendors_id) values ('Int\'l Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES_INTL_" . $vendors_id . "', 'Global Express, Global Express Non-Doc Rect, Global Express Non-Doc Non-Rect, Express Mail Int, Express Mail Int Flat Rate Env, Priority Mail Int, Priority Mail Int Flat Rate Env, Priority Mail Int Flat Rate Box, First-Class Mail Int', 'Select the international services to be offered:', '6', '15', 'tep_cfg_select_multioption(array(\'Global Express\', \'Global Express Non-Doc Rect\', \'Global Express Non-Doc Non-Rect\', \'Express Mail Int\', \'Express Mail Int Flat Rate Env\', \'Priority Mail Int\', \'Priority Mail Int Flat Rate Env\', \'Priority Mail Int Flat Rate Box\', \'First-Class Mail Int\'), ', now(), '" . $vendors_id . "')");

 

 

tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added, vendors_id) values ('USPS Options', 'MODULE_SHIPPING_USPS_OPTIONS_" . $vendors_id . "', 'Display weight, Display transit time', 'Select from the following the USPS options.', '6', '16', 'tep_cfg_select_multioption(array(\'Display weight\', \'Display transit time\'), ', now(), '" . $vendors_id . "')");

// EOF: UPS USPS

}

// EOADD

 

// MVS Added/Changed

/*

function remove() {

tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");

}

*/

function remove($vendors_id) {

tep_db_query("delete from " . TABLE_VENDOR_CONFIGURATION . " where vendors_id = '". $vendors_id ."' and configuration_key in ('" . implode("', '", $this->keys($vendors_id)) . "')");

}

// EOADD

 

// MVS Added/Changed

/*

function keys() {

// BOF: UPS USPS

// ORIGINAL return array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_PASSWORD', 'MODULE_SHIPPING_USPS_SERVER', 'MODULE_SHIPPING_USPS_HANDLING', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_SORT_ORDER');

return array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_PASSWORD', 'MODULE_SHIPPING_USPS_SERVER', 'MODULE_SHIPPING_USPS_HANDLING', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_SORT_ORDER', 'MODULE_SHIPPING_USPS_OPTIONS', 'MODULE_SHIPPING_USPS_TYPES', 'MODULE_SHIPPING_USPS_TYPES_INTL');

// EOF: UPS USPS

}

*/

function keys($vendors_id) {

// BOF: UPS USPS

// ORIGINAL return array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_PASSWORD', 'MODULE_SHIPPING_USPS_SERVER', 'MODULE_SHIPPING_USPS_HANDLING', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_SORT_ORDER');

return array('MODULE_SHIPPING_USPS_STATUS_' . $vendors_id, 'MODULE_SHIPPING_USPS_USERID_' . $vendors_id, 'MODULE_SHIPPING_USPS_PASSWORD_' . $vendors_id, 'MODULE_SHIPPING_USPS_SERVER_' . $vendors_id, 'MODULE_SHIPPING_USPS_HANDLING_' . $vendors_id, 'MODULE_SHIPPING_USPS_TAX_CLASS_' . $vendors_id, 'MODULE_SHIPPING_USPS_ZONE_' . $vendors_id, 'MODULE_SHIPPING_USPS_SORT_ORDER_' . $vendors_id, 'MODULE_SHIPPING_USPS_OPTIONS_' . $vendors_id, 'MODULE_SHIPPING_USPS_TYPES_' . $vendors_id, 'MODULE_SHIPPING_USPS_TYPES_INTL_' . $vendors_id);

// EOF: UPS USPS

}

// EOADD MVS

 

function _setService($service) {

$this->service = $service;

}

 

function _setWeight($pounds, $ounces=0) {

$this->pounds = $pounds;

$this->ounces = $ounces;

}

 

function _setContainer($container) {

$this->container = $container;

}

 

function _setSize($size) {

$this->size = $size;

}

 

function _setMachinable($machinable) {

$this->machinable = $machinable;

}

 

function _getQuote($vendors_id) {

// BOF: UPS USPS

global $order, $transittime;

// MVS Added

$vendors_data_query = tep_db_query("select vendor_country,

vendors_zipcode

from " . TABLE_VENDORS . "

where vendors_id = '" . (int)$vendors_id . "'"

);

$vendors_data = tep_db_fetch_array($vendors_data_query);

// MVS End

if(in_array('Display transit time', explode(', ', constant('MODULE_SHIPPING_USPS_OPTIONS_' . $vendors_id)))) $transit = TRUE;

// EOF: UPS USPS

 

if ($order->delivery['country']['id'] == /*SHIPPING_ORIGIN_COUNTRY*/ $vendors_data['vendor_country']) {

$request = '<RateRequest USERID="' . constant('MODULE_SHIPPING_USPS_USERID_' . $vendors_id) . '" PASSWORD="' . constant('MODULE_SHIPPING_USPS_PASSWORD_' . $vendors_id) . '">';

$services_count = 0;

 

if (isset($this->service)) {

$this->types = array($this->service => $this->types[$this->service]);

}

 

$dest_zip = str_replace(' ', '', $order->delivery['postcode']);

if ($order->delivery['country']['iso_code_2'] == 'US') $dest_zip = substr($dest_zip, 0, 5);

 

reset($this->types);

// BOF: UPS USPS

$allowed_types = explode(", ", constant('MODULE_SHIPPING_USPS_TYPES_' . $vendors_id));

while (list($key, $value) = each($this->types)) {

// BOF: UPS USPS

if ( !in_array($key, $allowed_types) ) continue;

$request .= '<Package ID="' . $services_count . '">' .

'<Service>' . $key . '</Service>' .

'<ZipOrigination>' . /*SHIPPING_ORIGIN_ZIP*/ $vendors_data['vendors_zipcode'] . '</ZipOrigination>' .

'<ZipDestination>' . $dest_zip . '</ZipDestination>' .

'<Pounds>' . $this->pounds . '</Pounds>' .

'<Ounces>' . $this->ounces . '</Ounces>' .

'<Container>' . $this->container . '</Container>' .

'<Size>' . $this->size . '</Size>' .

'<Machinable>' . $this->machinable . '</Machinable>' .

'</Package>';

 

// BOF: UPS USPS

if($transit){

$transitreq = 'USERID="' . constant('MODULE_SHIPPING_USPS_USERID_' . $vendors_id) .

'" PASSWORD="' . constant('MODULE_SHIPPING_USPS_PASSWORD_' . $vendors_id) . '">' .

'<OriginZip>' . $vendors_data['vendors_zipcode'] . '</OriginZip>' .

'<DestinationZip>' . $dest_zip . '</DestinationZip>';

 

switch ($key) {

case 'EXPRESS': $transreq[$key] = 'API=ExpressMail&XML=' .

urlencode( '<ExpressMailRequest ' . $transitreq . '</ExpressMailRequest>');

break;

case 'PRIORITY': $transreq[$key] = 'API=PriorityMail&XML=' .

urlencode( '<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>');

break;

case 'PARCEL': $transreq[$key] = 'API=StandardB&XML=' .

urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>');

break;

default: $transreq[$key] = '';

break;

}

}

// EOF: UPS USPS

 

$services_count++;

}

$request .= '</RateRequest>';

 

$request = 'API=Rate&XML=' . urlencode($request);

} else {

$request = '<IntlRateRequest USERID="' . constant('MODULE_SHIPPING_USPS_USERID_' . $vendors_id) . '" PASSWORD="' . constant('MODULE_SHIPPING_USPS_PASSWORD_' . $vendors_id) . '">' .

'<Package ID="0">' .

'<Pounds>' . $this->pounds . '</Pounds>' .

'<Ounces>' . $this->ounces . '</Ounces>' .

'<MailType>Package</MailType>' .

'<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' .

'</Package>' .

'</IntlRateRequest>';

 

$request = 'API=IntlRate&XML=' . urlencode($request);

}

 

switch (constant('MODULE_SHIPPING_USPS_SERVER_' . $vendors_id)) {

case 'production': $usps_server = 'production.shippingapis.com';

$api_dll = 'shippingapi.dll';

break;

case 'test':

default: $usps_server = 'testing.shippingapis.com';

$api_dll = 'ShippingAPITest.dll';

break;

}

 

$body = '';

 

$http = new httpClient();

if ($http->Connect($usps_server, 80)) {

$http->addHeader('Host', $usps_server);

$http->addHeader('User-Agent', 'osCommerce');

$http->addHeader('Connection', 'Close');

 

if ($http->Get('/' . $api_dll . '?' . $request)) $body = $http->getBody();

// BOF: UPS USPS

// mail('you@yourdomain.com','USPS rate quote response',$body,'From: <you@yourdomain.com>');

if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY)) {

while (list($key, $value) = each($transreq)) {

if ($http->Get('/' . $api_dll . '?' . $value)) $transresp[$key] = $http->getBody();

}

}

// EOF: UPS USPS

 

$http->Disconnect();

} else {

return false;

}

 

$response = array();

while (true) {

if ($start = strpos($body, '<Package ID=')) {

$body = substr($body, $start);

$end = strpos($body, '</Package>');

$response[] = substr($body, 0, $end+10);

$body = substr($body, $end+9);

} else {

break;

}

}

 

$rates = array();

if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {

if (sizeof($response) == '1') {

if (ereg('<Error>', $response[0])) {

$number = ereg('<Number>(.*)</Number>', $response[0], $regs);

$number = $regs[1];

$description = ereg('<Description>(.*)</Description>', $response[0], $regs);

$description = $regs[1];

 

return array('error' => $number . ' - ' . $description);

}

}

 

$n = sizeof($response);

for ($i=0; $i<$n; $i++) {

if (strpos($response[$i], '<Postage>')) {

$service = ereg('<Service>(.*)</Service>', $response[$i], $regs);

$service = $regs[1];

$postage = ereg('<Postage>(.*)</Postage>', $response[$i], $regs);

$postage = $regs[1];

 

$rates[] = array($service => $postage);

 

// BOF: UPS USPS

if ($transit) {

switch ($service) {

case 'EXPRESS': $time = ereg('<MonFriCommitment>(.*)</MonFriCommitment>', $transresp[$service], $tregs);

$time = $tregs[1];

if ($time == '' || $time == 'No Data') {

$time = '1 - 2 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;

} else {

$time = 'Tomorrow by ' . $time;

}

break;

case 'PRIORITY': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);

$time = $tregs[1];

if ($time == '' || $time == 'No Data') {

$time = '2 - 3 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;

} elseif ($time == '1') {

$time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY;

} else {

$time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;

}

break;

case 'PARCEL': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);

$time = $tregs[1];

if ($time == '' || $time == 'No Data') {

$time = '4 - 15 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;

} elseif ($time == '1') {

$time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY;

} else {

$time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;

}

break;

case 'FIRST CLASS': $time = '2 - 15 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;

break;

default: $time = '3 - 9' . MODULE_SHIPPING_USPS_TEXT_DAYS;

break;

}

if ($time != '') $transittime[$service] = ' (' . $time . ')';

}

// EOF: UPS USPS

}

}

} else {

if (ereg('<Error>', $response[0])) {

$number = ereg('<Number>(.*)</Number>', $response[0], $regs);

$number = $regs[1];

$description = ereg('<Description>(.*)</Description>', $response[0], $regs);

$description = $regs[1];

 

return array('error' => $number . ' - ' . $description);

} else {

$body = $response[0];

$services = array();

while (true) {

if ($start = strpos($body, '<Service ID=')) {

$body = substr($body, $start);

$end = strpos($body, '</Service>');

$services[] = substr($body, 0, $end+10);

$body = substr($body, $end+9);

} else {

break;

}

}

 

// BOF: UPS USPS

$allowed_types = array();

foreach( explode(", ", constant('MODULE_SHIPPING_USPS_TYPES_INTL_' . $vendors_id)) as $value ) $allowed_types[$value] = $this->intl_types[$value];

// EOF: UPS USPS

 

$size = sizeof($services);

for ($i=0, $n=$size; $i<$n; $i++) {

if (strpos($services[$i], '<Postage>')) {

$service = ereg('<SvcDescription>(.*)</SvcDescription>', $services[$i], $regs);

$service = $regs[1];

$postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs);

$postage = $regs[1];

// BOF: UPS USPS

$time = ereg('<SvcCommitments>(.*)</SvcCommitments>', $services[$i], $tregs);

$time = $tregs[1];

$time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time);

$time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time);

$time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time);

 

if( !in_array($service, $allowed_types) ) continue;

// EOF: UPS USPS

if (isset($this->service) && ($service != $this->service) ) {

continue;

}

 

$rates[] = array($service => $postage);

// BOF: UPS USPS

if ($time != '') $transittime[$service] = ' (' . $time . ')';

// EOF: UPS USPS

}

}

}

}

 

return ((sizeof($rates) > 0) ? $rates : false);

}

 

function country_list() {

$list = array('AF' => 'Afghanistan',

'AL' => 'Albania',

'DZ' => 'Algeria',

'AD' => 'Andorra',

'AO' => 'Angola',

'AI' => 'Anguilla',

'AG' => 'Antigua and Barbuda',

'AR' => 'Argentina',

'AM' => 'Armenia',

'AW' => 'Aruba',

'AU' => 'Australia',

'AT' => 'Austria',

'AZ' => 'Azerbaijan',

'BS' => 'Bahamas',

'BH' => 'Bahrain',

'BD' => 'Bangladesh',

'BB' => 'Barbados',

'BY' => 'Belarus',

'BE' => 'Belgium',

'BZ' => 'Belize',

'BJ' => 'Benin',

'BM' => 'Bermuda',

'BT' => 'Bhutan',

'BO' => 'Bolivia',

'BA' => 'Bosnia-Herzegovina',

'BW' => 'Botswana',

'BR' => 'Brazil',

'VG' => 'British Virgin Islands',

'BN' => 'Brunei Darussalam',

'BG' => 'Bulgaria',

'BF' => 'Burkina Faso',

'MM' => 'Burma',

'BI' => 'Burundi',

'KH' => 'Cambodia',

'CM' => 'Cameroon',

'CA' => 'Canada',

'CV' => 'Cape Verde',

'KY' => 'Cayman Islands',

'CF' => 'Central African Republic',

'TD' => 'Chad',

'CL' => 'Chile',

'CN' => 'China',

'CX' => 'Christmas Island (Australia)',

'CC' => 'Cocos Island (Australia)',

'CO' => 'Colombia',

'KM' => 'Comoros',

'CG' => 'Congo (Brazzaville),Republic of the',

'ZR' => 'Congo, Democratic Republic of the',

'CK' => 'Cook Islands (New Zealand)',

'CR' => 'Costa Rica',

'CI' => 'Cote d\'Ivoire (Ivory Coast)',

'HR' => 'Croatia',

'CU' => 'Cuba',

'CY' => 'Cyprus',

'CZ' => 'Czech Republic',

'DK' => 'Denmark',

'DJ' => 'Djibouti',

'DM' => 'Dominica',

'DO' => 'Dominican Republic',

'TP' => 'East Timor (Indonesia)',

'EC' => 'Ecuador',

'EG' => 'Egypt',

'SV' => 'El Salvador',

'GQ' => 'Equatorial Guinea',

'ER' => 'Eritrea',

'EE' => 'Estonia',

'ET' => 'Ethiopia',

'FK' => 'Falkland Islands',

'FO' => 'Faroe Islands',

'FJ' => 'Fiji',

'FI' => 'Finland',

'FR' => 'France',

'GF' => 'French Guiana',

'PF' => 'French Polynesia',

'GA' => 'Gabon',

'GM' => 'Gambia',

'GE' => 'Georgia, Republic of',

'DE' => 'Germany',

'GH' => 'Ghana',

'GI' => 'Gibraltar',

'GB' => 'Great Britain and Northern Ireland',

'GR' => 'Greece',

'GL' => 'Greenland',

'GD' => 'Grenada',

'GP' => 'Guadeloupe',

'GT' => 'Guatemala',

'GN' => 'Guinea',

'GW' => 'Guinea-Bissau',

'GY' => 'Guyana',

'HT' => 'Haiti',

'HN' => 'Honduras',

'HK' => 'Hong Kong',

'HU' => 'Hungary',

'IS' => 'Iceland',

'IN' => 'India',

'ID' => 'Indonesia',

'IR' => 'Iran',

'IQ' => 'Iraq',

'IE' => 'Ireland',

'IL' => 'Israel',

'IT' => 'Italy',

'JM' => 'Jamaica',

'JP' => 'Japan',

'JO' => 'Jordan',

'KZ' => 'Kazakhstan',

'KE' => 'Kenya',

'KI' => 'Kiribati',

'KW' => 'Kuwait',

'KG' => 'Kyrgyzstan',

'LA' => 'Laos',

'LV' => 'Latvia',

'LB' => 'Lebanon',

'LS' => 'Lesotho',

'LR' => 'Liberia',

'LY' => 'Libya',

'LI' => 'Liechtenstein',

'LT' => 'Lithuania',

'LU' => 'Luxembourg',

'MO' => 'Macao',

'MK' => 'Macedonia, Republic of',

'MG' => 'Madagascar',

'MW' => 'Malawi',

'MY' => 'Malaysia',

'MV' => 'Maldives',

'ML' => 'Mali',

'MT' => 'Malta',

'MQ' => 'Martinique',

'MR' => 'Mauritania',

'MU' => 'Mauritius',

'YT' => 'Mayotte (France)',

'MX' => 'Mexico',

'MD' => 'Moldova',

'MC' => 'Monaco (France)',

'MN' => 'Mongolia',

'MS' => 'Montserrat',

'MA' => 'Morocco',

'MZ' => 'Mozambique',

'NA' => 'Namibia',

'NR' => 'Nauru',

'NP' => 'Nepal',

'NL' => 'Netherlands',

'AN' => 'Netherlands Antilles',

'NC' => 'New Caledonia',

'NZ' => 'New Zealand',

'NI' => 'Nicaragua',

'NE' => 'Niger',

'NG' => 'Nigeria',

'KP' => 'North Korea (Korea, Democratic People\'s Republic of)',

'NO' => 'Norway',

'OM' => 'Oman',

'PK' => 'Pakistan',

'PA' => 'Panama',

'PG' => 'Papua New Guinea',

'PY' => 'Paraguay',

'PE' => 'Peru',

'PH' => 'Philippines',

'PN' => 'Pitcairn Island',

'PL' => 'Poland',

'PT' => 'Portugal',

'QA' => 'Qatar',

'RE' => 'Reunion',

'RO' => 'Romania',

'RU' => 'Russia',

'RW' => 'Rwanda',

'SH' => 'Saint Helena',

'KN' => 'Saint Kitts (St. Christopher and Nevis)',

'LC' => 'Saint Lucia',

'PM' => 'Saint Pierre and Miquelon',

'VC' => 'Saint Vincent and the Grenadines',

'SM' => 'San Marino',

'ST' => 'Sao Tome and Principe',

'SA' => 'Saudi Arabia',

'SN' => 'Senegal',

'YU' => 'Serbia-Montenegro',

'SC' => 'Seychelles',

'SL' => 'Sierra Leone',

'SG' => 'Singapore',

'SK' => 'Slovak Republic',

'SI' => 'Slovenia',

'SB' => 'Solomon Islands',

'SO' => 'Somalia',

'ZA' => 'South Africa',

'GS' => 'South Georgia (Falkland Islands)',

'KR' => 'South Korea (Korea, Republic of)',

'ES' => 'Spain',

'LK' => 'Sri Lanka',

'SD' => 'Sudan',

'SR' => 'Suriname',

'SZ' => 'Swaziland',

'SE' => 'Sweden',

'CH' => 'Switzerland',

'SY' => 'Syrian Arab Republic',

'TW' => 'Taiwan',

'TJ' => 'Tajikistan',

'TZ' => 'Tanzania',

'TH' => 'Thailand',

'TG' => 'Togo',

'TK' => 'Tokelau (Union) Group (Western Samoa)',

'TO' => 'Tonga',

'TT' => 'Trinidad and Tobago',

'TN' => 'Tunisia',

'TR' => 'Turkey',

'TM' => 'Turkmenistan',

'TC' => 'Turks and Caicos Islands',

'TV' => 'Tuvalu',

'UG' => 'Uganda',

'UA' => 'Ukraine',

'AE' => 'United Arab Emirates',

'UY' => 'Uruguay',

'UZ' => 'Uzbekistan',

'VU' => 'Vanuatu',

'VA' => 'Vatican City',

'VE' => 'Venezuela',

'VN' => 'Vietnam',

'WF' => 'Wallis and Futuna Islands',

'WS' => 'Western Samoa',

'YE' => 'Yemen',

'ZM' => 'Zambia',

'ZW' => 'Zimbabwe');

 

return $list;

}

}

?>


Jim Bullen - President

The Cigar Hut Group of Companies

 

 

Installed add-ons: (that now need to be upgraded to OSC CE Phoenix)

PWA, MVS, Easy Populate, Dynamic Sitemap, Featured Products, MVS Order Editor, MVS Shipping Estimator, Google XML Sitemap, About Us, Ad Tracker, Address Enhancer, Also Purchased, Backorders, Category Descriptions, Dynamic Meta Tags, Contact Us Email Subjects, Country state Selector, Extra Address Line, Order Number in Email Subject, OSC Affiliate, Product Extra Fields, Review Approval System, Reviews in Product Display, Sold Out, Sold Out (but Displayed), Ultimate SEO URL's, Updated Spiders, Welcome Email Password, Pending Order Email, Who's Online Enhancement, CCGV, Easy Discounts, Customer Comments, Request a Review, Sales Report, plus many many more!

Share this post


Link to post
Share on other sites
I've uploaded V2.1 of the Shipping Estimator. This should fix issues with the use of Zones, plus some other odd bugs. As I noted (OK, ranted) above, bugs in this thing were nasty. If you were having problems with this module before, please upgrade to 2.1 and let us know if it fixed the problem. It works fine on my machine, but I have no way of knowing if it will work under different conditions.

 

Regards

Jim

 

 

Jim, you are my hero!

 

You have no idea how badly I have been wanting a working shipping estimator for MVS!

 

Thanks for busting your brains and getting this contrib to work with MVS

 

I had tried and tried to get it to work myself, but gave up after realizing it was beyond my abilities.

You really saved the day, thanks again!


Jim Bullen - President

The Cigar Hut Group of Companies

 

 

Installed add-ons: (that now need to be upgraded to OSC CE Phoenix)

PWA, MVS, Easy Populate, Dynamic Sitemap, Featured Products, MVS Order Editor, MVS Shipping Estimator, Google XML Sitemap, About Us, Ad Tracker, Address Enhancer, Also Purchased, Backorders, Category Descriptions, Dynamic Meta Tags, Contact Us Email Subjects, Country state Selector, Extra Address Line, Order Number in Email Subject, OSC Affiliate, Product Extra Fields, Review Approval System, Reviews in Product Display, Sold Out, Sold Out (but Displayed), Ultimate SEO URL's, Updated Spiders, Welcome Email Password, Pending Order Email, Who's Online Enhancement, CCGV, Easy Discounts, Customer Comments, Request a Review, Sales Report, plus many many more!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×