0

I'm trying to allow people to subscribe to an organic group when buying a specific product. The thing is that I need to set the OG context in the order, not the product or anywhere else.

Use case: The anonymous user completes an order. The site admin reviews it and then he may or may not grant the anon user the access to a specific role from a list.

How I´m trying to accomplish that:

  • I've installed Drupal Commerce, Rules and Organic Groups.
  • I create an OG audience field inside commerce orders (*og_group_ref_commerce*).
  • I set a rule with some conditions (if the order is set to "completed", and if the user is an anon...) and some actions (a loop to create the new user and assign him a role).

And I'm adding a special action (which doesn´t work):

Subscribe user to group

User Data selector: account-fetched:0 Group Data Selector:
commerce-order:og-group-ref-commerce:0

I´ve tried another way, without any success:

User Data selector: account-created (in and outside the loop that created the user) Group Data Selector: site:og-context--node

Note: As the order doesn´t initially have the group audience context, I have to edit it in order to assign it a group. After saving it (it is still in "pending" status), I edit it again to change it to "completed".

Any ideas?

  • u should use rules – monymirza Mar 22 '13 at 5:56
1

Try out following these steps

1) Using the Entity Reference module, I've created an entity reference on my product type. It's target type is "Node", and the Target Bundle is the content type of my Organic Group. In my case, that's called "Classroom".

2) I create a piece of content of type "Classroom".

3) I create a new product and a drop-down will show a list of all my Classrooms. I select one of them.

4) Now comes the time to make the rule to automatically add the user to the correct group.

Conditions
Event: Completing the checkout process

Conditions
Entity has field: commerce-order:commerce-line-items:0 .. Name of the field to check for: commerce_product

Entity has field: commerce-order:commerce-line-items:0:commerce-product .. Name of the field to check for: field_og_reference (this is the name of my entity reference that I put on the product in Step #1).

Actions
Fetch entity by property. .. Value: User
.. Property: Email
.. Value: commerce-order:mail
.. Limit result count: 1
.. Variable Label: Fetched Account
.. Variable Name: account_fetched

Subscribe User to Group
.. User: account-fetched:0
.. Group: commerce-order:commerce-line-items:0:commerce-product:field-og-reference:group

Solution 2 See tutorial about this, have a look:

  • Thanks for your clear explanation! I´ve followed each step carefully, but I get this error: Notice: Undefined offset: 1 in og_membership_from_group_and_user_context() (line 28 of /public_html/sites/all/modules/og/plugins/relationships/og_membership_from_group_and_user.inc). I rather use your explanation (Solution 1) because it is easier (and module-less :). – Anita G. Mar 23 '13 at 5:25
  • After reviewing what I could have done wrong (for the third time), I realize that the last part was wrong, BUT, because I can´t get the same output as you. In fact I just get: commerce-order:commerce-line-items:0:commerce-product:field-myfield. If I try to go further I get author, translation source node and the main body text as selectors. There´s no way I can set "group". And if I try to do it forcing it by hand, I get this error "Data selector commerce-order:commerce-line-items:0:commerce-product:field-myfield:group for parameter group is invalid." – Anita G. Mar 23 '13 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.