Recently we needed PO functionality for a customer site running D7, and after looking @ the module it looked like it was more or less abandoned. I decided to start with 6.x-1.0 since this was my first attempt at a D6 -> D7 port and I didn't know the working state of the 2.x branch. After doing this port I noticed that there was some other work being done by others on a port to D7 of the 2.x branch (http://drupal.org/node/1280502) but I'm not sure what the current status of that is.
I posted a reply there as well, but since my port relates to the 6.x-1.0 branch I thought a separate topic might be in order.
Attached is a port of the 6.x-1.0 uc_po module to D7. I've tested it and it appears to be working from what I can tell; if anyone else finds this useful and would like to test it that would be great.
-kevin hanser
Energy Web Design
http://energywebdevelopment.com
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | uc_po-7.x-1.x-dev-20121119-2128.tar_.gz | 15.82 KB | kmhanser |
| #20 | 1526056-D7-Port-ucpo1-20.patch | 1.74 KB | demma10 |
| #18 | 1526056-D7-Port-ucpo1-18.patch | 1.56 KB | demma10 |
| #17 | 1526056-D7-Port-ucpo1-17.patch | 466 bytes | demma10 |
| #15 | uc_po-7.x-1.x-dev-20120420-1450.tar_.gz | 15.89 KB | kmhanser |
Comments
Comment #1
kmhanser commentedI messed up when I tar'd that up and forgot the directory (d'oh). This one should work better and create a uc_po sub dir instead of just plopping everything in the current dir...
Comment #2
demma10 commentedThanks kmhanser
Great work on the port. I'm also using version 6.x-1.0 and need this functionality for my site.
I've tested your code and have so far only found two issues, neither of them major. The first is every time I visit the po_number search page or try to edit it I receive this error:
Missing join: uc_orders uc_payment_poThe error doesn't interfere with the display and search functionality. I don't know enough about how views works to be able to offer a solution.
The second issue is that the token module hooks have changed in Drupal 7. This issue is easily fixed.
I've created a patch incorporating all of your changes plus the fix for the token hooks. This patch was created against the master branch of the git repository, which appears to be the 6.x-1.x version of the module.
Comment #3
kmhanser commentedAwesome, Demma10, thanks for checking out my code and thanks for the fixes!
I updated my code w/the fixes to the two token functions that you added (I think there were just the two functions uc_po_tokens and uc_po_token_info, correct?)
I will have a look @ the code and see if I can figure out that views error... this was my first attempt at using the hook_views_data hook so I probably have something wrong in there.
thx!
-kevin hanser
Energy Web Design
http://energywebdevelopment.com
Comment #4
kmhanser commentedDemma10,
I wasn't able to duplicate the join error that you are seeing on the "Search by PO" view. I thought at first it was because I had warnings turned off so I wasn't seeing it, but after confirming that all errors are being shown, I can't seem to get that error.
I did change a few things in how I named the relationship in hook_views_data so maybe that will help. (not sure that was the issue though since I wasn't able to make it happen for me...)
I've attached a new snapshot of my code which has been updated with your token hook changes and the updated view in it if you want to download it and give it a try. Be sure to disable and then enable the module after putting the new one in place to make sure the view is re-created with the new info.
thx!
-kevin
Energy Web Design
http://energywebdevelopment.com
Comment #5
demma10 commentedI think I know why I've received the errors but you haven't. I have the Devel module installed and I've turned Views debugging on. The messages appear to be coming from the Devel module.
The messages don't appear to affect the functionality of the module. The purchase order search page displays properly and the search filters all work.
I think I've tracked down what's caused them. In your hook_views_default_views the relationship option to the order_total and order_status fields is missing. Once I added this field to the view the Missing Join messages disappeared. I'll post a patch shortly.
Comment #6
demma10 commentedI've attached a zipped copy of uc_po.views_default.inc with the missing relationship lines included. I've also attached a patch which includes all the changes up until now. Like the patch in comment #2 this patch is against the master branch of the project's git repository.
kmhanser, would it be possible for you to put your code in a sandbox project? This will make patching much easier.
Comment #7
kmhanser commentedWow, that's really weird! Thanks for tracking that down for me; I'm not sure how those relationships got removed, but sure enough they weren't there. The strange thing is that if I edit the field thru the view gui, it then has the correct relationship listed and all I needed to do was save. I don't know when/why those two relationships disappeared... probably somewhere along the way when I renamed the relationship(s) and re-exported/imported the view. Thanks for tracking that down for me!
Yeah I totally forgot about the Devel and Coder modules; I should try to make sure to install those on whatever site I'm doing my devel on from now on.
As for the sandbox project; sure, I will go and get one set up. I didn't do this initially since this was an existing project and I wasn't sure what the procedure was for adding in a port to an existing project. From the project page on this it looks like the project is somewhat abandoned... it says the status is "seeking new maintainer" so I wasn't sure how I would go about getting this port added into the official project.
Once I get it set up in the sandbox I'll post here w/more details! Thanks for your help Demma10
Comment #8
kmhanser commentedOk I have set up a sandbox project here: http://drupal.org/sandbox/bradjmsu/1539674
I added my latest snapshot into the git sandbox repository; this includes the fixes to the relationships on the views.
Also attached a snapshot .tar.gz.
Let me know how this one works for you,
thx!
-k
Comment #9
demma10 commentedThanks kmhanser
Just checked out the code in the sandbox and so far I haven't found any errors or unexpected behaviour.
The next question is, what will be the future of this module? That's a question for another thread.
Comment #10
demma10 commentedLooks like I spoke too soon.
I've found another potential error with this module. Once an order has been created I then cannot go in as an administrator and change the purchase order number. I'm not sure whether this is an errror with this module, with Ubercart or with UC Webform Checkout Panes (I've had problems with this module in the past). I'll need to do further testing to narrow down which module is causing this.
kmhanser, can you reproduce this error?
Comment #11
kmhanser commentedHmm, that's something I never tried to do :) Let me look into it and see what I can find out.
-k
Comment #12
kmhanser commentedHmm, interesting. Yeah I get an error from uc_order.module when I try to edet an order (with or w/out a purchase order):
Fatal error: Nesting level too deep - recursive dependency? in /home/roco/dev/sites/all/modules/ubercart/uc_order/uc_order.admin.inc on line 1065It appears to be something I've introduced w/my module, since a version of the same site w/out the uc_po module does not have this problem.
Looking into it now...
Comment #13
kmhanser commentedOk now I'm more confused; maybe this isn't something I caused? I disabled the uc_po module on my dev site, and tried to edit a credit card order (actually no edit was performed, I just loaded it in the edit screen and pressed the save changes button).
And I'm getting the same error.. I added some degugging output into the uc_order.admin.inc file and it seems like it's bombing out when it tried to process the 'products' portion of the order.
This is the code that's bombing, on the "if" statement line... (I added in the echoes for debugging):
And this is what my debugging echoes produce:
It's crapping out when it gets to the 'products' section of the order. Which appears to have some recursion in there... but I'm not sure that's a bad thing. I've seem arrays w/recursion in them all over in Drupal so I'm not sure if this is out of the ordinary or not.
I'm really still not sure at this point, I need to do some more investigation on this and other sites I have running ubercart.
Is this the same error you're seeing, Demma10?
thx
-k
Comment #14
kmhanser commentedUpdated: I updated my ubercart to the latest dev version (7.x-3.x-dev 2012-Apr-20) and now I'm not getting that error anymore. (it was still present when I tried version 7.x-3.0)
So that error doesn't appear to be something that uc_po caused; however, when I try to edit a PO number now it saves w/out error, but it doesn't actually update the PO number either... so I'll work on seeing how I can fix that.
-k
Comment #15
kmhanser commentedI have made some changes to the uc_po.module code; Looks like I didn't have code in there for the op 'order-save' that occurs when you edit an order. Possibly this is some hook that changed or didn't exist in D6/UC2 since there wasn't anything there to do this previously... not sure if there was code written in for editing PO numbers or not, since I didn't see any existing code to update the uc_payment_po table which is where the PO's are actually stored.
I also am not sure if the token hooks are actually necessary for this module or not... there was an error being caused by one of them, and the po number still seemed to show up fine despite the error. I added some code into the hook to avoid the error, but I'm not really sure if these are necessary or not. I've left them in since I don't want to break anything right now...
I updated the sandbox project / git repository w/my latest changes, and I've also attached the latest SVN snapshot .tar.gz
I did some testing on my site, and I was able to place a PO order as a user and it was recorded ok.
I also tested editing the PO number as an admin and that appears to be working now. When you edit / add a po number it records the change in the admin comments section now too for historical purposes.
Give it a go and see what else you can find! Thanx again for your testing assistance, I seem to miss some of the bugs sometimes when I'm doing my own testing, so w/out your help I may not have found these errors until the customer found it on their site :)
-k
Energy Web Design
http://energywebdevelopment.com
Comment #16
demma10 commentedGlad to help :-). As I've said in another thread I need this module for my main site so I'll help where I can.
In my testing I never received any errors about recursions, however I didn't test very thoroughly. In fact I didn't receive any error messages, only that the PO number was not updating. I'll test the new code and report back once I've gone back to work as that's where my test site is located.
With regards to the token functions. This is the first time I've used the token hooks, so they're probably not the correct way to write them. They were in the original module so I ported them across. I think we should keep the token hooks because the uc_order module makes all the order data available through tokens, and as the PO number is part of the order data it should be included for completeness. If you think they're unecessary then we can remove them.
Comment #17
demma10 commentedI've tested the latest code in the sandbox and can report that when an administrator edits and saves the order the purchase order information is also saved (ie the order-save code is working as expected).
Now I've found another error. When deleting an order (with or without a PO number) I receive the following two messages:
Both errors are caused by a typo on line 178. The attached patch fixes both error. This patch is rolled against the code in the sandbox (see comment #8).
kmhanser, do you think that the code for the delete block in uc_po_uc_order should be placed inside an if ($order->payment_method == 'po') { } block? Then the delete database call will only run if there is a PO number to delete. Does this question make sense?
Comment #18
demma10 commented@kmhanser. With regards to the hook_tokens error I've done more testing and it turns out I was getting the same error you received. This one is actually my fault as I didn't update the token hooks correctly. Between D6 and D7 the $order->payment_details array changed to $order->payment_method['data'] and I forgot to update this when updating hook_tokens.
I've attached a patch with the error corrected plus a small sanity check to ensure that $order->payment_method['data']['po_number'] exists before referencing it. I've tested this and have not had any errors. Please test this as I'm not 100% sure I've formed the if statement correctly.
I suspect Ubercart calls hook_tokens when generating invoices, which is why we're receiving error messages upon order completion. In which case the token hooks may need to stay so that the PO number can be shown on the order invoice.
Comment #19
kmhanser commentedI applied your patches, but the 2nd one (for the token hook) was causing an error; something about "cannot use string offset as array" on line 80 which would be the line that was changed to:
The first one seems to work well, I put that in the sandbox. I also added the sanity check on delete that you suggested. I have some other projects I need to focus on today unfortunately or I'd try to figure out what that error is in the 2nd patch.
Thanx!
-k
Comment #20
demma10 commentedNo worries. I was in a rush when I created the second patch so it's not surprising that there was a major error.
I had a lot more time today compared to yesterday so I did a much better job of testing. The error reported in comment #19 was caused by referencing the wrong order property. The reference:
$order->payment_method['data']['po_number']should've been:
$order->data['po_number']as $order->payment_method is simply a string with the machine-readable name of the payment method used.
I've re-rolled the patch from comment #18 with the correct order property referenced. When you've got time give this a test.
Comment #21
demma10 commentedI've started an issue to discuss what to do with this module for Drupal 7. The issue is here: http://drupal.org/node/1564986
Comment #22
jennypanighetti commentedDoes anybody have a *complete* 7.0 alpha or beta module? There are some zip files and some patches... can someone please create a latest complete zip?
Comment #23
kmhanser commented@jenstechs:
Hmm I guess I didn't realize there wasn't a "latest version" snapshot .tar.gz in the thread. Been a little while since I worked on this project, and I just reviewed the thread now after seeing your comment.
I believe the code that's in the git sandbox repository is a working copy. I will try to get a snapshot .tar.gz rolled up in the next couple days and post it to this thread. If you don't want to wait, you can grab a copy from the git sandbox yourself from here: http://drupal.org/sandbox/bradjmsu/1539674
I'll have to check and make sure the latest patches have been applied to the sandbox code, but I'm pretty sure that the code in the git sandbox is working/functional (I was and still am using this code on a customer site so as far as I know it's still working). I probably won't have a chance to look it over and get a new .tar.gz out until this weekend though, so if you need it really quick the git sandbox repo may be your best bet.
Let me know if you encounter any issues!
thx
-k
Comment #24
kmhanser commentedI have attached a SVN snapshot of the code that I was last using on the site that I created this for. I compared it to the code that the site is still running and it seems to match.
I haven't had a chance yet to see if the git repo contains the same code, my git client was acting up on me and I don't feel like messing with it tonite :) I also need to verify if my code contains all of Demma10's patches. I think it does, but there may be one at the end that didn't get implemented(?).
As far as I know, this is a working version of the module. please let me know if you encounter any issues.
thx
-k
Comment #25
demma10 commentedThanks kmhanser
The code in the previous comment is missing the patch from comment 20. All this patch does is fix some of the token handling code, it doesn't affect the purchase order number handling. The code should function without the patch but it may produce some errors about invalid tokens.
I have an archive of the git sandbox code with the patch applied. If you'd like I can upload it to this thread.
Comment #27
vinoth m commented