Great job; awesome module!
May I suggest some options on allowing the form to be displayed and not displayed in specific cases. For example, I think an option to display for specific role types would be helpful - i.e. for new users (anonymous role) but not returning customers (authenticated or other roles). I suppose the ideal way would use something like checkboxes in a form in the settings page, etc.. A "probably less ideal way" would be through permissions which can be done with the following:
Adding:
/**
* Implementation of hook_perm().
*/
function uc_profile_perm() {
return array('show profile field in checkout');
}
and then adding this to the array in hook_checkout_pane:
'#access' => user_access('show profile field in checkout'),
In my case, I just wanted this for anonymous users checking out to set the profile fields initially. I have Jquery that places profile field vales into the corresponding billing address fields (as the default) as they are filled out.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | uc_profile_anon.patch | 1.74 KB | EvanDonovan |
| #5 | uc_profile anon.txt | 9.27 KB | MBroberg |
Comments
Comment #1
pcorbett commentedThis actually follows a similar need that I have, which I will be writing in shortly. I think I would opt for the settings route versus permissions. What is the specific need you have? In what context is it needed?
Comment #2
WebNewCastle commentedSorry I missed replying to this.
Mainly, I just needed to have the profile fields displayed to be filled out for anonymous users rather than logged in users.
Comment #3
WebNewCastle commentedOh, and yes, I think you're right that it would be better done via settings. I played around with a simple version of that tonight and like it much better.
Comment #4
MBroberg commentedI would like logged in users to see their existing profile fields in checkout, update them if necessary, and then choose whether or not to update their profile upon submit.
For anonymous users they will not be creating a profile (unless they choose to do so) but I need the same data from them, only they will have to fill it all out in checkout. They could choose to create a user account at that point or not. If not, I would like that data to be stored with the order, but technically there is no user profile. Is there a "temp" profile or something associated with just the order?
Comment #5
MBroberg commentedWe worked on some modifications of the uc_profile.module file so that an anonymous user can also see and use the fields. This is a total hack and probably very rough, since we are not Drupal programmers, but it is working for our site.
The trick was to create a new user with the username "Anon." This is referenced as the user name in the code so it must be Anon, although you could change to a user ID. We tried it both ways and prefer this for consistency.
Only the username and email are set. All of the extra profile fields in that user account should be blank.
When a logged in user checks out everything works as usual.
When an anonymous user tries to check out they are exposed to the values (empty) in the Anon user account. Then they can fill them out and the values are saved with the order.
Edits include:
-Got rid of permissions requirement for profile access so that anonymous users are not restricted
-Commented out the "auto-update your profile" feature so that anonymous users are not putting permanent information into the Anon account. This is critical so that you do not have the previous anonymous user 's info stored and thus exposed to the next user!
The new file is attached. Just save the original file somewhere, then copy and paste this code instead. Use at your own risk of course!
Comment #6
pcorbett commentedThanks, I'll take a look at this. Just finished a big move across country, so bear with me as we get settled.
Comment #7
EvanDonovan commented@MBroberg: I may need this functionality as well, but I'm not sure if this is the best way to go about implementing it. Could you post your code as a patch for easier review?
Comment #8
EvanDonovan commented@MBroberg: What version of the module is your code based off of? It looks like you made a lot of changes vs. the stable release that I have, most of which seem unrelated to this patch.
Also, what is the $tu variable? Why is it called that?
Comment #9
EvanDonovan commentedI determined that MBroberg's code was based off #606366: Make it possible for uc_profile to include fields from different profile categories, comment #3. I re-rolled this as a patch based off my patch in that issue, comment #14.
The result is uploaded here. You will have to apply the patch from comment #14 of #606366: Make it possible for uc_profile to include fields from different profile categories to test this.
However, I am almost certain that this is not the best way to do this, since it requires the creation of a "dummy" user, and there are security risks with that data getting overwritten later.
I personally am able to use the original version of uc_profile.module to add profile data for an anonymous user - possibly it depends on the access settings for a profile field.
I think that the correct method for profile form access control would be to add a dropdown to the settings form for the checkout pane, which is populated based on the user roles existing on the site. The user roles for which the checkout pane should show up could then be saved as a variable in the database.
Then, in the 'view' $op of uc_checkout_pane_profile, the entire logic would be wrapped in a function that checked the role of the current user, so it would only execute if the current user had a role in the array of allowed roles.
I don't think I actually need this functionality, but at least I have described now the proper way to do it.
Comment #10
EvanDonovan commentedComment #11
EvanDonovan commented@MBroberg: As far as I know, Ubercart always creates a user account when an anonymous purchase is made (unless you have modified Ubercart's code somehow). The option is just whether or not to log in to the account immediately upon creation.
That said, I see the need for something like your patch now, only if #606366: Make it possible for uc_profile to include fields from different profile categories has been committed, since the profile fields will not show up for anonymous users when you are running a version of uc_profile.module patched with that.
I am going to look into a better way to do this.
Comment #12
EvanDonovan commented@MBroberg: To fix the issue with anonymous users not being able to see the profile fields, your "dummy" user account code was not necessary. All that was necessary was to remove profile_category_access() from the if.
This is because, as per the API docs, profile_category_access calls user_edit_access, which checks
$account->uid > 0(i.e., not anonymous).Comment #13
WebNewCastle commentedSide note on a comment I noticed circling back to this thread: In case it helps someone, I have a module out that allows the option to not have Ubercart create a Drupal account on anonymous checkout (in the UC_ECO module).
Comment #14
herveh commented#12 is the way to go, working fine for me.
I'm not very familiar into creating new modules, but id like to know if there is a safer way to do #12 without hacking uc_profile
In this case I'm not the only person working on the site and would like to be sure that everything will run smootly even if someone update uc_profile
Comment #15
pcorbett commented#606366: Make it possible for uc_profile to include fields from different profile categories is now part of 6.x-2.x-dev, so we can now start considering this for inclusion.
Comment #16
manuelgc commentedHi, I installed the development version and I realize that's not what I expected.
Today I created two user roles, customers and partners (besides the default one), I want to show the profile form only to users with anonymous role has no customers or affiliates (because it assumes that already have an account in the website)
I think the initial solution (uc_profile_perm) would work. I wish someone would give me some idea of what solution to implement
Comment #17
spazfoxIn case you haven't figured this out yet, I was able to implement this using a slightly modified version of the initial solution. As suggested, I added this to the top of uc_profile.module:
This part did NOT work for me, however:
'#access' => user_access('show profile field in checkout'),Instead, to get it to work I added this conditional statement to uc_profile_checkout_pane:
Works perfectly for me now!
Comment #18
chinita7 commented@spazfox Thanks your code works for me. By the way, The preview page has only Account information but not "Profile details" for the role which doesn't have the access to profile field in checkout . It would be great if the "Profile details" can be displayed for all roles on preview page.
Comment #19
AllyMediaGroup commentedThis is so close to what I need, I am fine with the profile permissions being on the user permissions page. But what I need is to be able to separate out the profiles per role. I have the User information, Company information, and Player information. I need to separate out each on onto it individual form in the checkout pane so I can specify player info only shows for high school roles, and User and Company info only shows for the Corporate roles.
Any help would be much appreciated.
Comment #20
AllyMediaGroup commentedI am looking at the settings of content profile, and the area roles in the settings of content profile, you can set what roles use what categories, if we could somehow use the built in roles part of content profile, there would not be a need to create other permissions as the roles would be set when you create the categories.
Comment #21
pcorbett commented@AllyMediaGroup I will take a look at your request in about two weeks. Sorry for the delay.