2

I have created a user role "seller"

when user enters to their account a "Add blog post"-tab is shown to user when user click on it he/she can add "Add blog posts"

"Add blog posts" is a node form which contains field "title","image upload","body"

I want to add restriction to "seller" type user Only those users can add post who paid (paid membership) for it to add "Add blog posts" (I have created a special role for paid membership).

Notes:

  • I have created a special role for paid membership.
  • When a user clicks on "Add blog post"-tab, the user must be redirected to checkout page if the user didn't paid in past. Users who already have the paid membership role should be able to create, edit and delete blog posts.
0

2 Answers 2

1

Assuming that your "Add blog post" matches with an URL like node/add/blog, you can use the Rules module to stop any user who is trying to use that URL, if that user does not have access to the role "Paid membership" that you have in place. Here is the actual rule to do so (in Rules export format, just import it in your own site and enable it there to see it at work):

{ "rules_limit_access_to_node_add_blog" : {
    "LABEL" : "Limit access to node\/add\/blog",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "NOT user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "4" : "4" } }
        }
      },
      { "text_matches" : { "text" : [ "site:current-page:url" ], "match" : "node\/add\/blog" } }
    ],
    "DO" : [
      { "drupal_message" : {
          "message" : "Adding content for selected content types (such as for \u0022\u003Cstrong\u003E[site:current-page:path]\u003C\/strong\u003E\u0022) triggers some extra (Rules) logic, as you can see here. I.e. for anyone who does not have the role to do so.",
          "type" : "error"
        }
      }
    ]
  }
}

The assumption in this rule is that your role "Paid membership" has a role-id of "4" (if not just adapt the role after you imported the rule to make it fit, or change the value of "4" before importing the rule). And if your URL is different from node/add/blog, then adapt that also to make it fit for your case. Obviously, the actual error message being shown may need tuning also. And if the machine name of your content type is not "blog", but "whatever", just change all blog occurrences to "whatever" before importing this rule.

Happy Rules-ing!

0

I think the easiest solution is to create a new role Paid membership and give this role to the seller after he has paid.

You can assign the permission Add blog content to this role and remove that permission from the seller role.

4
  • how to give new role to the seller after he has paid,by creating some rules or something else
    – user52318
    Feb 16, 2016 at 4:24
  • How does the payment work? By some module? Feb 16, 2016 at 11:08
  • drupal commerce by adding new product
    – user52318
    Feb 16, 2016 at 11:55
  • 1
    You should be able to create checkout rules (like you said), check this site for a little help on this subject: drupalcommerce.org/user-guide/checkout-completion-rules Feb 16, 2016 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.