How to grant a user role when a specific product has been ordered?

Created on 27 September 2024, about 2 months ago

I need to create a model that will add the user role "member" to a user's account when that user orders product variation with ID "2". The user will likely be anonymous when they check out, but I have the checkout flow setting "Create a new account for an anonymous order" enabled.

Can anyone please provide guidance on how I can set this up? Is there an existing recipe I can use?

πŸ’¬ Support request
Status

Active

Version

2.0

Component

Miscellaneous

Created by

πŸ‡ΊπŸ‡ΈUnited States hockey2112

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @hockey2112
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    I don't know Commerce well enough, especially the anonymous checkout which creates a user account automatically. But I would assume that the user needed to be created before the order can be completed, because that user needs to be attached to that order, and for that to be possible, the user needs to be present by then.

    If that assumption is correct, you could create a model that starts with the order being created or completed. Then the model can load the referenced user and assign a role to that user.

    Samples on how to assign roles to users can be found in the ECA Guide Library. Hope that helps?

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    @jurgenhaas is correct, the best way would be on the order status change (not creation cause it's created as a cart)

    Then you can get the user and add the role once payment is complete.

  • πŸ‡ΊπŸ‡ΈUnited States hockey2112

    The problem is that these users are purchasing memberships. We don't want to have any users registered who are not members, and they must purchase that membership fee in order to become a member.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    Yes, that should not be a problem, once they have finished the purchase they will have an account created by commerce.
    Then you can track that order in ECA and set the role.

  • πŸ‡ΊπŸ‡ΈUnited States goose2000

    Hi, following this, I would like to do this. Although, in my case, my users are all authenticated and exist before shopping.

    Is that doable? More doable? The video in the library, 3 conditions met and add new role was helpful, thank you.

Production build 0.71.5 2024