Topic-icon Custom Profile Plugin

Active Subscriptions:

None
13 years 4 months ago #29915 by learnthrusong
Hi @alzander,

Scenario
I'm almost finished writing a custom shopping cart component for J2.5 and as part of the package I need to create my own profile plugin to automatically bind some component specific user details to the session when the user logs in/registers etc. Also, to leverage the awesome power of facebook as far as social-marketing is concerned, I need to create a profile plugin for JFBC too... OK, so thanks to J2.5, creating a 'standard' profile plugin is pretty straight-forward - no problems there. To clarify, the specific data I need to store for users are;
  • Payment Address - street, town...country etc
  • Delivery Address - street, town...country etc
  • Customer type - whether the customer is a 'regular' (member of the public) customer OR a 'trade' customer (shop or business)
So, I'm almost done with my component's profile plugin but am a little unsure how this should be integrated with/called from the custom JFBCProfile Plugin.

I'm following along with the docs on creating a JFBC Profile plugin however, I'm a little bit lost as to how this 'connects' to my existing profile plugin.

Questions
Do I even need to create 2 plugins - I mean, a component profile plugin & a JFBC plugin - or can I combine them in 1 and just check for the existence of JFBC to deal with the FB-related stuff?
  • If it is best to have 2 independent plugins, how does JFBCProfile plugin handle calling my component's user-profile plugin? Which lines in the Kunena plugin do this for Kunena?
  • If combining them is best, please could you give me a couple of hints as to what/where I must make changes?
On a slightly different note, do you have any developer docs on creating an OG Actions Plugin for components?

Thanks in advance!!!

Gez
The topic has been locked.
Support Specialist
13 years 4 months ago #29947 by alzander
Replied by alzander on topic Custom Profile Plugin
Gez,
First off, you can't retrieve the user's street address from Facebook. That information isn't even info that Facebook asks on their profiles. You can get their city and state, but not zip code. That's just how their profiles work.

You also won't be able to get whether the user is a "profile" or a "Page/Business". The reason for that is that the only users that can use the Login with Facebook button are real profile users. You can't log in to an Application/Website using a Facebook Page.

So, with that said, let me ask you a few questions:
* Do you already have a Joomla - Login plugin for your app? If so, I'd probably recommend just adding a few lines to that to import the user's profile information into your component when logging in.. it'd be easier than a full-blown JFBCProfile plugin
* The profile plugin system built-in to Joomla is somewhat limited. I'd test and make sure that works for you from a user registering normally and make sure you get the info you need and can use it in the database how you'd expect. Additionally, if you're using the "Normal Registration Flow" of JFBConnect, the fields you setup in the Profile plugin *should* show up as extra fields on the registration, which may be nice.

Finally, for the upcoming v5.0 release of JFBConnect, we're in the process of completely over-hauling the profile plugin system. It's really way too confusing and complex right now. The plan is to make things a ton simpler and easier to understand with the next release.

Hope that helps answer your questions or give you some ideas, but let us know your thoughts and we'll help you get what you need.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 4 months ago #29957 by learnthrusong
Replied by learnthrusong on topic Custom Profile Plugin
Hi alex,

Thanks for your reply!

I'm sorry, I think I may have mislead you a bit... Yes, I am creating a profile plugin with all of the fields I described (and more).

RE: The address & user type:
I understand that facebook doesn't provide that however, I need to get what I can from facebook then, have the user provide the additional information. To clarify, the reason that I require the address is, the products for the shop I'm building are split into 2: those that can be shipped abroad and those that can't. Therefore, to prevent users from getting annoyed by purchasing an item that they can't have delivered to their country, I need their country. This way, at the point where a customer adds a product to their cart, I can warn them that the item can not be sent to their territory. They can then override this and place in their cart if it was for example, a gift that needed to be sent to a country where it can be delivered.

AIM
So, at registration;
*1 - I want the user to select whether they are wishing to signup as a Customer or a Business
*2 - If the user is a customer, I want them to register through facebook to get all of the main info such as username, city, state (and country - if I can get that) and the usual stuff. This user is to be be auto confirmed in the registration flow and get immediate access.
*3 - If the user is a Business (trade customer), as above, I want them to be able to access the same registration flow except that, when they select Business I will also want to collect some additional profile info - business name etc, website, company number etc. Obviously, I will need the user to enter this manually. Also, I will be setting a custom boolean field (trade_enabled) = false. This means that the user will not gain the right to see trade prices until the site admin has 'approved' them as a trade customer. They will however be able to login and view the site in the meantime.

What would be your advice with how to proceed with this?
My custom profile plugin with JFBCProfile overrides OR 2 plugins?

Many thanks,

Gez

PS what is the timeframe for V5.0?
The topic has been locked.
Support Specialist
13 years 4 months ago #30008 by alzander
Replied by alzander on topic Custom Profile Plugin
Gez,
Thanks for the clarifications. From this statement:

I want the user to select whether they are wishing to signup as a Customer or a Business

This is going to be the trickiest point. There's no way in JFBConnect's flow (or Joomla for that matter) to let a user select a profile type during registration. I'm not sure how you're planning on doing that.

Once you decide that though, getting the profile information from Facebook would be pretty easy. If you're already making a Joomla profile plugin, it may just be easier to add the code there. You'd need to simply do a call like:
$fields = array(0 => 'first_name', 1 => 'last_name', 2 => 'status', 3 => 'email', 4 => 'name', 5=>'hometown',6=>'current_location');
            $jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
            $fbUserId = $jfbcLibrary->getFbUserId();
            $profile = $jfbcLibrary->getUserProfile($fbUserId, $fields);
You can change the requested fields, as seen above, pretty easily. Then, with that $profile variable, you can pre-fill or post-fill any information in the user's profile that you want.

Using a JFBCProfile plugin has the benefits of:
* Dynamically setting the permissions required at login - If you need current_location, the login button will request permission for that information from the user. That's very easy to set in our JFBConnect configuration area as well though
* Import avatar - doesn't sound like you need that.
JFBCProfile plugins are much more complex though, so I think might be more than you're looking for.

Finally, we're shooting to get v5.0 out at the end of this month, but it may slip into the first week or so of February.

Hope that all helps,
Alex
Hope that hel
The topic has been locked.
Active Subscriptions:

None
13 years 4 months ago #30016 by learnthrusong
Replied by learnthrusong on topic Custom Profile Plugin
Hi alzander,

Thanks for your reply!

RE: How I intend to split the users into customers/trade customers, I'm going to be using jQuery to dynamically change the required field attribute and required property in the class dependent upon their selection of Trade or Customer. There are only 4 additional fields for Trade customers so it shouldn't be that difficult to deal with. Also, when a user views/edits their profile, I'm going to remove all Trade Customer fields from the array of JForm fields when the value of customer_type = Customer.

Using a JFBCProfile plugin has the benefits of:
* Dynamically setting the permissions required at login - If you need current_location, the login button will request permission for that information from the user. That's very easy to set in our JFBConnect configuration area as well though
* Import avatar - doesn't sound like you need that.
JFBCProfile plugins are much more complex though, so I think might be more than you're looking for.

Do you mean that to automatically request from facebook, I will have to create a JFBCProfile plugin or will including the calls above do this anyway?

BTW, can I just check, what is a user's FB current_location? Is it their city/state?

Looking forward to version 5!

Thanks again,

Gez
The topic has been locked.
Support Specialist
13 years 4 months ago #30054 by alzander
Replied by alzander on topic Custom Profile Plugin
Gez,
The code I mentioned above for fetching the profile fields should be all you need. I'd probably just recommend fetching all the data you need for trade users or customers and using JForm to pre-fill those values before the page loads. You can even choose to hide the fields that are pre-filled from Facebook, if you want.

Then, with that information imported before the page loads, you can use your jQuery form changing based on type without any issues. Whether the user is coming from Facebook or registering through Joomla normally, it shouldn't really change anything.

As for the current_location value, you'll get back data that's in an array like:
"current_location": {
        "city": "Austin", 
        "state": "Texas", 
        "country": "United States", 
        "zip": "", 
        "id": 106224666074625, 
        "name": "Austin, Texas"
JFBConnect will help you parse that data out already, but the above is an example. The zip field will always be blank.

Hope that helps,
Alex
The topic has been locked.