Closed (fixed)
Project:
Ubercart
Version:
7.x-3.x-dev
Component:
Shipping
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
3 Aug 2011 at 02:01 UTC
Updated:
14 Nov 2012 at 09:01 UTC
Jump to comment: Most recent file
Comments
Comment #1
beefzilla commentedComment #2
beefzilla commentedwhy is this status ignored? This just might make it work!
Comment #3
beefzilla commentedapparently i need git, and I don't have that right now... It's just a one line addition - see my ignored .diff file, anyone who knows what s/he's doing, and post a patch please!
Comment #4
beefzilla commentedComment #5
tr commentedStarting with #1, the reason your patch was marked "Ignored" by the automated test bot is that patches are supposed to have a file extension .patch. Any other file extension, e.g. .jpg, is ignored because the test bot does not recognize it as something that can be tested. Additionally, the test bot only runs when a patch is marked "needs review". You had the issue set to "patch (to be ported)", which is absolutely the wrong status because that means there is a patch that has been applied already to one version of Ubercart and it is awaiting a port to a different version of Ubercart. That is not what you have here.
Re: #3: No, you do not need git to make a patch, but you do need to make it in unified diff format, rooted at the ubercart main directory. So you could create a proper patch by cd-ing to the ubercart directory then typing:
Finally, there is no way your patch could fix the problem you describe. Putting that line in might stop the PHP notice (which comes third in your list of errors), but the PHP notice is not the problem and is not preventing anything from working correctly. The $services array is supposed to be created by parsing the USPS response, so something is wrong with your USPS response. And it's not a simple error response from the USPS server, because Ubercart can handle error responses without generating warnings and notices. Turn on shipping quotes debug to see the request sent to USPS and the response returned to get some idea of what's going on.
I have been running USPS quotes successfully every day and have never seen this error. Hundreds of other users are also running USPS quotes. There have been no previous reports that they are broken entirely. Examining my watchdog logs for the past month I don't see any entries from the uc_usps module. All this points to a configuration problem or a server problem on your end. Please turn on the debug and post that output here (remember to remove your USPS credentials from the debug output). Also, please post a screen shot of your USPS settings.
BTW, have USPS quotes *ever* worked for you? And did you telephone USPS to activate your API credentials on the "production" server?
Comment #6
beefzilla commentedThanks for the response, TableRow. One day I'll get this open source thing down. :)
Yes, I am using the production server. Of course, now I get the same response from the USPS regardless of my patch:
However, from a computer-science perspective, please look at the code in uc_usps.module's uc_usps_quote function. All references to the $services variable are made inside for loops. It needs a scope outside those closures to have any lasting effect by the time it gets to line 408.
Here are the messages i get when refreshing the checkout page after using the shipping quote, (post-patch; without the patch, there are the problems posted in #1):
Notice: Undefined property: stdClass::$weight_units in _uc_usps_package_products() (line 744 of .../sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
Notice: Undefined property: stdClass::$pounds in uc_usps_rate_request() (line 484 of .../sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
Notice: Undefined property: stdClass::$ounces in uc_usps_rate_request() (line 485 of .../sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
And I have the weight of my product defined in its node.
Comment #7
beefzilla commentedComment #8
beefzilla commentedComment #10
beefzilla commentedDarn line endings.
Comment #12
beefzilla commentedI'll give you a tip! The tip of my boot.
Comment #14
beefzilla commentedtip of the code base? I guess that means the latest dev version - wherever I find that...
Comment #15
longwaveThe patch doesn't apply because the filename is wrong:
The second line should refer to just
ubercart/shipping/uc_usps/uc_usps.moduleHowever, I fixed and committed the patch:
http://drupalcode.org/project/ubercart.git/commitdiff/ab88fed
Setting back to active, as it seems your support request is still not solved by this.
Comment #16
beefzilla commentedThanks longwave! <3
Now I just have to figure out the problem with weights.
Comment #17
tr commentedActually, that's not true in PHP. In PHP, variables declared inside control structures retain their definition and value outside the control structure.
It's still a good idea to declare it outside the loop, and in fact that's how it's done in the D6 version of the module. It looks like I accidentally removed that line about 5 months ago in commit 78e3bd079f5b507 when I refactored that part of the code (I do love git log -S !). But as I said, I run this code almost every day and have never seen that notice, so something more fundamental is going on here.
So the obvious question at this point is, do you have a weight set for your products, and do you have any contributed modules installed that affect weights? (uc_product_power_tools, for instance.) Are you using the weight markup feature of the uc_usps module?
Even when I try to get quotes for a zero-weight product, I do not see the warnings or notice that you cite in your original post - on my server the uc_usps module just doesn't present a quote to the customer, which is as it should be. With only a zero-weight product, the packaging algorithm doesn't make any packages, and a request should never be sent to USPS. Perhaps you have several products in the order, only one of which has zero weight, and several packages are made by the packager? Please try to get quotes for a simple order of 1 product with the product weight set.
Comment #18
beefzilla commentedI get the same problem with only one item in the cart.
I'm not using funky modules. The optional ubercart modules I have enabled are: payment, reports, shipping and shipping quotes.
Under ubercart fufillment I have enabled: USPS and weight quote. I only recently enabled weight quote.
Right now I only have one product in my store, and I have filled in its weight of 3.3 ounces in the edit node dialog.
Under admin->store->config I have U.S. Postal Service (Parcel) checked. For the USPS quote settings, see attached .gif - nearly all the parcel checkboxes are checked.
I really have no idea what's going wrong if it's only configuration based. I'd have to strap on my snorkel and code dive at this point.
Comment #19
beefzilla commentedlooking in my database, both tables uc_weightquote_methods and uc_weightquote_products have zero rows.
uc_products does have my singular product in it, and its weight. uc_packaged_products and uc_packages have nothing in them.
These empty tables seem like they should have something in them for this to work. I'm feeling the urge to uninstall ubercart and reinstall.
Comment #20
tr commentedI've done some extensive testing and still can't reproduce this.
Do you have your default pickup address set at admin/store/settings/quotes/edit ?
What do you have set for the USPS markup settings?
What do you have set for packaging settings?
Those database tables have nothing to do with USPS quoting.
Comment #21
beefzilla commentedI have the default pickup address set to my home address.
For markup I have 0; tried it with 100% too, no change. Weight markup type is grayed out.
Default order fufillment type for products: small package.
Where do I find packaging settings?
In cart/checkout, when I check "My delivery information is the same as my billing information." It doesn't update the order total. When I click "Click to calculate shipping" however, it does update the order total, adding this table row: "U.S.P.S. First-Class Mail Parcel: $1.73," but also shows an error.
Here is the response from the USPS:
Comment #22
tr commentedPackaging settings are under "Quote options" on the USPS settings page.
BTW, what version of PHP are you using?
Problem still seems to be that your package weight is 0, which USPS rejects. I suggest you start putting print statements in uc_usps_package_products() (inside uc_usps.module) to discover where the weight gets set to zero. It's still possible that it's a bug, but it would have to be a bug related to a non-default setting that I haven't tried recently, which is why I'd like to know what your settings are.
Comment #23
beefzilla commentedmy server is using php 5. Thanks for your help so far.
I have "All products in one package" radio button checked. The three checkboxes below it are grayed out.
I'll do some more debugging and share my results.
Comment #24
beefzilla commentedLogging each $product in function _uc_usps_package_products with my hand-dandy beefzilla_log function:
both $product->length_units and $product->weight_units are not defined. That's a problem! I search on.
Comment #25
tr commentedPHP 5 point what? The big change that might cause a problem is between 5.2.x and 5.3.x. PHP 5.3.x still causes problems in many corners of Drupal. I would like to find out if that is a potential cause of this problem.
You should only get to line
beefzilla_log($product,0,'product at start of foreach');if there is more than one distinct product in your cart. I thought you were testing with just one product ... Length units are *not* set at this point, scroll down about 25 lines and you'll see where the length units are set along with a comment describing what's happening. However, weight units *should* be set at this point. I have tested by setting different weight units on my product, and I can't reproduce this - I always have a valid value for weight units at this point.Comment #26
beefzilla commentedI'm on a shared host with PHP Version 5.2.17.
And whoops, you're right. I copied the wrong block of logging code. But there were log statements in both sides of the if/else, so the results are still valid.
I used my trusty krumo hack to debug the $form that's passed by reference into the uc_quote_form_uc_cart_checkout_form_alter function before uc_quote.module's code alters it, and this is $form['cart_contents']['#value']:
a:1:{i:0;O:8:"stdClass":14:{s:12:"cart_item_id";s:2:"14";s:7:"cart_id";s:1:"1";s:3:"nid";s:2:"13";s:3:"qty";s:1:"1";s:7:"changed";s:10:"1312411519";s:4:"data";a:2:{s:9:"shippable";s:1:"1";s:6:"module";s:10:"uc_product";}s:5:"title";s:28:"Nifty product you must buy";s:3:"vid";s:2:"13";s:4:"cost";s:7:"2.50000";s:5:"price";s:7:"7.99000";s:6:"weight";s:3:"3.3";<strong>s:12:"weight_units";s:2:"oz";</strong>s:6:"module";s:10:"uc_product";s:5:"model";s:1:"2";}}Though serialized, you can read in there that the weight units are indeed present. A text search through the entire ubercart folder only yields one match to "uc_cart_checkout_form_alter," this one. Where else could this information be altered?
Off-topic:
I noticed that the copy address box doesn't do what the calculate shipping box does. Line 253 of uc_quote.module -
@todo: Figure out what needs to be done when the copy-address box is checked.That checkbox probably already has ajax on it, and would need another function strapped onto it. How does drupal 7 handle multiple ajax callbacks? Does it?
Comment #27
tresero commentedI can confirm that this is a real bug. I am too tired to debug tonight, but I will tomorrow.
Comment #28
tresero commentedOK, Here is some more info:
Error 1: Notice: Undefined property: stdClass::$weight_units in _uc_usps_package_products() (line 744 of /var/www/sites/asdf/shoppica/sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
Error 2: Notice: Undefined property: stdClass::$pounds in uc_usps_rate_request() (line 484 of /var/www/sites/asdf/shoppica/sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
Error 3: Notice: Undefined property: stdClass::$ounces in uc_usps_rate_request() (line 485 of /var/www/sites/asdf/shoppica/sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
Error 4: Notice: Undefined variable: services in uc_usps_quote() (line 403 of /var/www/sites/asdf/shoppica/sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
Error 5: Warning: Invalid argument supplied for foreach() in uc_usps_quote() (line 403 of /var/www/sites/asdf/shoppica/sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
Error 6: Notice: Undefined variable: services in uc_usps_quote() (line 408 of /var/www/sites/asdf/shoppica/sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
Error 7: Warning: Invalid argument supplied for foreach() in uc_usps_quote() (line 408 of /var/www/sites/asdf/shoppica/sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
That is all the errors that are showing when I click on calculate shipping.
Obviously something is not being defined correctly.
Comment #29
tresero commentedOK, more on this, if there is only one item in the cart the errors show. If there is more than one, it is also broken.
Comment #30
tresero commentedHere is what I think is happening, I am getting deeper into this.
The hook to check USPS is being called 1 time more than the actual packages being shipped. If you have one item, it is called 2x, the first time returns the correct information, the second, everything is empty.
This is difficult to debug, but the reason that the quotes work, but throw an error is the whole thing loops 1 time more than the number of items.
Comment #31
tr commentedI suggest if you're going to look into this, you should use the latest dev code. The line numbers in your PHP notices indicates you're not.
Comment #32
beefzilla commentedI made a fresh install of drupal 7.7 and all the latest ubercart dependencies on a new subdomain, and I'm still gettting this error. That tells me this is not configuration based, unless I'm totally missing something. My product does have its weight listed in the node settings.
Comment #33
beefzilla commentedDid some more testing today. Findings: in ubercart/shipping/uc_usps.module function
_uc_usps_package_productswith only one item in the cart, theforeach ($products as $product) {loop iterates twice when clicking the "Click to calculate shipping" button. The first time through$package->weight_unitsis defined, the second time, it is not. I find this a little strange because at the beginning of the function, the$productsarray only holds one item, and that item does not have a weight_units attribute...Here is the var_dump of the
$packageobject after the firstswitch($product->weight_units)in said function, on both 1st and 2nd iterations:Comment #34
beefzilla commentedAlso of note, there is a lack of defensive code up in here:
Notice the lack of a
default:. Whoever coded this didn't expect there to not be a weight_units attribute, so this fails gracelessly. So there's still room for improvement after I find this bug. The default could alert the watchdog with a notice.Comment #35
beefzilla commentedI finally found the problem. Committing patch shortly. :)
Comment #36
beefzilla commentedComment #37
beefzilla commentedComment #38
beefzilla commentedHmmm... test postponed. Should I worry about this?
BTW, this has perplexed me for a while now - citing TR:
Hundreds of other users are also running USPS quotes. There have been no previous reports that they are broken entirely.
Are all these sites using drupal 7? One of my coworkers uses drupal 6 with ubercart and it works masterfully. Ubercart 7 is still buggy. I considered porting my custom theme to drupal 6, but I figured that would be a step in the wrong direction, so here I am.
-_-
Comment #39
tr commentedAs I said in #25, $weight_units is always set for me at that point, and does not need to be pulled out of $temp on my site. That's why I feel the error is occurring somewhere else, and you're only masking the true problem by using the patch in #36. In fact, the whole block of code that's currently in there that defines $temp is a big hack and is not needed in D6 Ubercart - somewhere higher in the food chain, probably in uc_quote, there's an implicit node_load() missing. When that's found and fixed, the whole $temp block can be removed from uc_usps and uc_ups. The curious thing is that $weight_units isn't set for some people - there seems to be some unknown factor that's different on our servers.
Comment #40
beefzilla commentedIf you're interested in finding this unknown factor, I suggest a fresh install of drupal 7.7 with minimal requirements to get ubercart and usps shipping quotes working. That's what I'm testing on - a site with only one node, that's a product.
Heck, I've considered opening up a subdomain of my personal development domain to the drupal developer public just to test this issue. Does that sound like a bad idea?
And why has my patch not been tested yet?
Comment #41
gmopinillosv commentedHello guys
It is very intereting all of this but without solution yet.
I subscribe with #30 . I am using D7.7 and Ubercart 7.x and I setting all weights on my products.
To me this is happening:
1. with only a product, showed message "Please enter the package weight"
2. with two products, showed Shipping calculation from USPS and the message "Please enter the package weight"
3. with three or more products, showed the same like #2.
Also when I clicked back buton on checkout, showed the next: (with three products)
Notice: Undefined property: stdClass::$weight_units in _uc_usps_package_products() (line 699 of /home2/wholesa1/public_html/sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
Notice: Undefined property: stdClass::$weight_units in _uc_usps_package_products() (line 699 of /home2/wholesa1/public_html/sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
Notice: Undefined property: stdClass::$weight_units in _uc_usps_package_products() (line 699 of /home2/wholesa1/public_html/sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
Notice: Undefined property: stdClass::$weight in _uc_usps_package_products() (line 702 of /home2/wholesa1/public_html/sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
Notice: Undefined property: stdClass::$weight in _uc_usps_package_products() (line 703 of /home2/wholesa1/public_html/sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module).
I am not an expertice on Drupal or Ubercart, but I think that there are something not defined or there are something by default with weight "0" .
Maybe this could help to find the solution at problem.
Thanks. (sorry for my english)
Comment #42
beefzilla commentedThe ajax call hits
uc_usps_quotetwice for some reason. The first time through it does the right thing. The second time through, weight_units is not present at the product level.The backtrace for the second call runs 14 functions deep...
Comment #43
beefzilla commentedpictured is the diff between the two backtraces
Comment #44
gmopinillosv commentedHello again
To @beefzilla, If this call twice, with just only a product it must show "shipping cost from USPS" and the message too but it is not like this. Whit just only product just show the message (Please enter the package weight). So in this case, I think it is just reading a first product by default without weight in my humble opinion. It must read only the products in the cart.
On the other hand, how do you use the patch? How does it install that? I have never used a patch and I don't know how install that.
Thanks in advance
Comment #45
gmopinillosv commentedUpdate: Maybe, it is only reading the first product without weight..
Think a little bit about this.
Thanks
Comment #46
beefzilla commentedIt reads the product's
weightjust fine - that attribute never changes. However at some point before the second timeuc_usps_quoteis called, theweight_unitsattribute disappears from the product.USPS doesn't recognize a weight without accompanying weight_units, hence the problem. My task is to determine where the weight_units are lost.
Apparently it's calling twice because the form needs to be rebuilt.
Comment #47
gmopinillosv commentedThen, What do I have to do?
Do I have to wait for some batch to fix that bug?
I am in this 1 week ago and I don't get out of this issue.
Well I will keep trying. Thanks.
Comment #48
beefzilla commentedI have a patch above that worked for me - http://drupal.org/files/issues/1027554_2.patch but the purists want me to track down the source of the bug and kill it, as my patch is just a "hack."
Comment #49
gmopinillosv commentedHow can I implement your batch?
Where I have to put that?
So i can see whether it work or not. I am sorry for my ignorance.
I am not using Ubercart dev.
Are there some problem with that?
Thanks in advance
Comment #50
beefzilla commentedBackup the file /sites/all/modules/ubercart/shipping/uc_usps/uc_usps.module
...and replace it with the contents of this zip file. Try it out. Worked for me. Good luck! :)
Comment #51
beefzilla commentedthinking out loud, as usual. There's a problem with
uc_order_load($order->order_id, TRUE), as that does not add the weight_units attribute along with everything else. Essentially it callsentity_load($entity_type = 'uc_order', $ids = array($order_id), $conditions = array(), $reset = TRUE)This happens in uc_cart_pages.inc, at the bottom of function uc_cart_checkout_form_validate.
Comment #52
beefzilla commentedFound the problem. The solution is not a one-liner. -_-
See line 1303 of uc_order.module:
$result = db_query("SELECT * FROM {uc_order_products} WHERE order_id = :id ORDER BY order_product_id", array(':id' => $order->order_id));That query should also fetch the weight_units for that product, because without units, a number is meaningless!
I recommend an INNER JOIN to get the product's weight and weight units. Heck the uc_order_products table shouldn't even hold fields such as weight and weight_units, as those should be held solely by the uc_products table. We're just duplicating data here. To fix this, change the query above to:
Ideally, it should instead read:
If the uc_order_products table had the redundant weight field removed from it.
More testing and patch to follow (hopefully). It's nearly midnight over here.
Comment #53
gmopinillosv commented@fillezilla
Your file .zip
Just to work for the first product but it with 2 or more products then appears the message "Please enter the package weight" in the end.
Also when I put Puerto Rico (international country) it gives me the next message (see attach file)
I keep looking for a solution.
Comment #54
beefzilla commented@gmopinillosv
Ok, good to know. Thanks for giving that a try. That's why I asked you to backup the original file! :P
Hopefully i will have a better fix soon. My website needs this to work too.
Comment #55
gmopinillosv commented@beezilla
I am going to prove your second option and I will see what happen.
Comment #56
gmopinillosv commentedUpdate: Before to do the test, I note it work in "shopping cart" page but not in "Checkout" page. You can see my pictures attaching.
Comment #57
beefzilla commentedOK, I uploaded another patch,
For you, @gmopinillosv, try the contents of that zip file in ubercart/uc_order/uc_order.module - please backup first! :) It works on my site, but I only do domestic shipping.
@TR and @longwave, the uc_orders table should drop the
weightcolumn.Comment #58
beefzilla commentedwhoops - now with unix line endings!
Comment #59
beefzilla commentedComment #60
beefzilla commentedComment #61
gmopinillosv commented@beefzilla
I used only your last uc_order.zip and it is the results:
With just only product is OK in shopping cart and checkout pages
With 2 or more products always appears that message on the end only in checkout page
It is better but not how expected. I will use this .zip meanwhile.
Thanks.
Comment #62
beefzilla commented@gmopinillosv
I did some more testing and got the same error you did. I will continue debugging this week and keep you informed.
Comment #63
beefzilla commentedTesting with 3 items in the cart. 2 are the same product, 1 is a different product. Request/response to/from USPS:
Notice that the first package has nothing in it; the second package has all three items in it. That tells me there is something wrong with the packaging logic.
Comment #64
beefzilla commentedI think I discovered why this happens around line 673 of uc_usps.module:
The two objects are not equal because one doesn't have an email address and the other does. When testing address equality that shouldn't matter. Therefore the UcAddress class should have a "equalPhysicalLocation($obj)" method that would return TRUE in this case.
Comment #65
beefzilla commentedalso
uc_quote_get_default_shipping_address($nid)spits out stdClass objects instead of UcAddress objects.Comment #66
beefzilla commented@gmopinillosv I have a fix. See the attached .zip file to backup and replace the 3 files listed in updated.txt:
shipping/uc_usps/uc_usps.module
shipping/uc_quote/uc_quote.module
uc_store/classes/address.inc
Comment #67
tr commentedPlease DO NOT attach zip files or entire copies of modules to an issue. In Drupal, we create patch files instead. Complete copies of modules actually make things harder for the maintainers, so if you can't post a patch I'd rather you don't post anything at all.
Also, please don't turn this into a catch-all issue for any problems you find. Issues should deal with one and only one problem. Open a new issue if you find a different problem. For instance, the address comparison issue has been a documented feature for a long time. There is an entirely separate thread discussing what should be done about that - please participate in that thread if you want to help.
Comment #68
beefzilla commentedI just now posted a patch to http://drupal.org/node/405678 for the issue gmopinillosv discovered. The .zip files are only for his benefit, as he is not as tech savvy.
TR, please check my attempt at a multi-file patch there; is that the proper format?
Comment #69
kc8phj commentedIs there any status on this?
I am using ubercart-7.x-3.0-beta4 and I still get a message from usps that asks for package weight when there is only item in the cart and it displays prices as expected when there are more than one items in the cart.
This is on the checkout page.
The ups module works fine with either one or multiple items in the cart.
.
Comment #70
kc8phj commentedComment #71
kc8phj commentedIs there any update on this issue?
I still have the problem of the usps module asking for the package weight when there is only one item in the cart.
If there is more than one item the quotes show for the usps options though I am not entirely sure they are accurate but will do more research on that.
The UPS option works as expected.
I am using ubercart-7.x-3.0-beta4.
Comment #72
tr commentedComment #73
beefzilla commentedAll I can recommend is that you use my latest patches, in this bug and the referenced one, as those make it work on my site... Unless there's a new version out.
Comment #74
beefzilla commentedComment #75
beefzilla commentedthe patch above works - do I just set this issue to fixed?
Comment #77
longwaveHopefully, this should be fixed by #1118036: add weight_unit to {uc_order_products} table and http://drupalcode.org/project/ubercart.git/commitdiff/1645d08
Comment #78
tr commentedTestbot is finally working! Patch doesn't apply. "Needs work" is correct status here.
Comment #79
longwaveCan anyone confirm whether this is still a issue or if it is already fixed in latest 7.x-3.x-dev?
Comment #80
longwaveA year on and this thread has gone quiet; presuming this was fixed as noted in #77.