Needs work
Project:
Ubercart Donation Products
Version:
6.x-2.0-beta3
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
22 Sep 2009 at 17:18 UTC
Updated:
23 Nov 2011 at 06:01 UTC
Jump to comment: Most recent file
Comments
Comment #1
anonThe problem is that the serialized data string in the uc_cart_products table thinks that the "donate_amount" is a string.
But in "uc_donation_update_cart_item" its a float. why? I dont know, ask the maintainer.
I have created a patch that works.
Comment #2
bibeksahu commentedAnon: thank you for the patch. It allowed me to figure out what was going on. That being said, I think I may have some better (or at least simpler) solutions.
But in "uc_donation_update_cart_item" its a float. why? I dont know, ask the maintainer.
After a few hours of analyzing the code, I think I can answer that: in "uc_donation_add_to_cart_form_validate()", the donate_amount gets converted to a float. If you properly use the existing forms, the validate function will automatically get called. If you create your own form and manually call "uc_cart_add_item()", it doesn't get called.
Solution #1: in your code, when you're creating the form_state[] (assuming you do it manually), change $form_state['donate_amount'] to be a float. This fixes the problem for me; and I believe addresses the underlying issue.
(I swiped that "... floatval()" line from "uc_donation.module", line 199.)
Solution #2: find a way to call "uc_donation_add_to_cart_form_validate()" properly from your code, just before the "uc_cart_add_item()" call. This looked like more trouble than it was worth, considering I'd have to build a form to go along with the form_state[].
Solution #3: when creating your form, use the standard product $form_state[] keys, perhaps by calling uc_product_form(), and make sure all the proper handlers/callbacks are set. This will automatically call "uc_donation_add_to_cart_form_validate()", which will take care of the floatval() problem. This is my preferred solution, but it's not one I can use in all cases, especially when I don't know at form-build-time what the node will be.
Comment #3
jasonawantDo either of these patches work when page caching is enabled?
Thanks,
jwant
Comment #4
deggertsen commentedThanks for providing a patch anon. Whether there is a better solution or not I needed an immediate solution and that worked!
Comment #5
torgospizzaI'm using the default Add to Cart form - no form generated manually - and I, too, cannot remove a Donation product from the cart. The patch didn't work for me.
I'll be digging into this a bit more as I have a non-profit client who could use this working correctly.
EDIT: Interestingly enough, I can't delete it if there's only one product in the cart. But if I add another one, I can delete one after the other (from the top to bottom). Attempting to delete the bottom one also doesn't work. Really weird behavior.
Comment #6
korzh-nick commentedAre there some news? Still not working.