Outcome required was: Once checkout process gets completed User should get the access of perticular book for which he/she has ordered.

Best help I got is from the which sells the Node and I had to sell the whole Book(bunch of nodes).
Initially I went with the flow of the above link of commerceguys and I could achieve exactly what they have mentioned in their tutorial.

This was the positive sign for me that I am going on the right path through which I will be able to get the exact result what I want.But what happens in the above tutorial is they only sell a node and not the whole book.You can say a bunch of nodes together.

And for Selling all nodes together issue I got help from the module resolved my issue completely and helped me to get the behavior what I wanted.

Step By Step process how I got this working.

You can watch the tutorial( which will give you 60% of the things working.

==>Before Starting go to /admin/people/permissions/roles and Create a new role called "Subscribed".

1) We have Content Access and its submodule Content Access Rules enabled.
Also download and enable node_access_book module.

We need 3 things:
a) Product Display
b) Products
c) Book Page

2) Enable book module.
3) Create a content type called Product display.
4) Go to store->products->Product types and go to manage fields of "products".

** Do not forget to do this ** :
go to content type-> Book Page-> Access Control.
Remove all the access from every user except for the admin and select the checkbox for "Enable per content node access control settings".

Basically we need a page which refers to the Store Product & Store Product should refer to a book's Parent Node.
For this,

5) Go to Content type->Product display & create a field "Product reference"(You can use any name), Field type "Product reference" and widget "Select List".(Keep Number of Values 1 only).

6) Go to store->products->Product types->Products->Manage Fields & create a field "Premium Node"(You can use any name), Field type "Node reference" and widget "Checkbox/Radio".
--> Select "Book Page" for Content types that can be referenced & Keep Number of Values 1 only.

Now, We need to set the Rules.(We will Create Two Rules)


7) Go to Config->Rules and Add new Rule.
Name : Change the Order Status on Order Completion (You can use any name).
Tags : Not Required.
React on Event : Completing the checkout process
Click on "Save".

8) No need of giving any conditions.
In the Actions,click on "+ Add Loop" and you should be getting "commerce-order:commerce-line-items",just after that in "Variable label *" type "Line Item" & in "Variable name *" type "line_item".
Click on "Save".

Loop will check all the line Items available in the perticular order but what should be done in the action when it enters into the loop will be done in the Components.

9) Go to Config->Rules->components and Add new Component.
Select "Rule" and Click on "Continue".
Name: Component to Change Order Status (You can use any name).

Below you can see the table.
--Data Type : Commerce Line Item
--Label : Line Item
--Machine Name : line_item

Click on "Save Changes".

10) Conditions(2 conditions needs to be added):
--1) Click on "+ Add Condition" and select "Entity has Field", Data Selector: line-item , Field Value: commerce_product and click on "Save".
--2) Click on "+ Add Condition" and select "Entity has Field", Data Selector: line-item:commerce_product , Field Value: field_premium_node and click on "Save".
NOTE: field_premium_node is the field which is in Store->product types->products and which refers to the book's parent node.So select the field which is showing in your Products Manage fields and saved as Node Reference.

11) Actions:
--1) Click on "+ Add Action" and select "Add user role", Data Selector: site:current-user , Roles Value: Subscribed and click on "Save".
--2) Click on "+ Add Action" and select "Update the order status", Data Selector: line-item:order , Order Status Value: Completed and click on "Save".

Now the order Status will be updated to "Completed" state and we can now set the permission to the node referenced by the Product Node.

13) Go to rule you just created now.where the Loop was added in action.Click on "add action" which is next to Loop and select "The_component_you_just_created" in Select the action to add and click on "Save".

Fig: Rule1.

Fig: Component For Rule1.


14) Go to Config->Rules and Add new Rule.
Name : Grant Access to Book on Order Completion (You can use any name).
Tags : Not Required.
React on Event : Completing the After updating an existing commerce order
Click on "Save".

15) Click on "+ Add Condition" and select "Data comparison", Data to compare: commerce-order:state , Data value: Completed and click on "Save".

In the Actions,click on "+ Add Loop" and you should be getting "commerce-order:commerce-line-items",just after that in "Variable label *" type "Line Item" & in "Variable name *" type "line_item".
Click on "Save".

16) Repeat Steps 9 and 10 here.
but change the Name of component when you create.

17) Actions:
Click on "+ Add Action" and select "Grant access by user", Content: line-item:commerce-product:field-premium-node:book , GRANT VIEW ACCESS : line-item:order:owner, and remove everything from GRANT UPDATE ACCESS & GRANT DELETE ACCESS
and click on "Save".

18) Perform the Step 13 again for this rule.

Fig: Rule2.

Fig: Component For Rule2.

Done with the configuration of everything.

Create a book, Product Display content and a product content.
--Product display will refer to the Product(Store Product)
--Product(Store Product) will refer to the book.

Hope this will be helpful.

December 13, 2013

Follow the steps:

  1. Go to your /admin/config/workflow/rules/components and click on "Add new Component"
  2. Select "Action set" under Component plugin & Press Continue.
  3. Give appropriate Name.E.g: Flag Node.

    Data type : Content, Label: Node, Machine name:node & Press Continue.

  4. Click on "Add action" & select "Flag a node" ,once it returns the result data,Select which flag should be clicked.

    For => node :Data selector use node &

    For =>User on whose behalf to flag : Data selector use node:author

    & Press Save.

    Done with the component.

    Now Add a New Rule

  5. Go to your /admin/config/workflow/rules and click on "Add new Rule"

  6. Give appropriate Name.E.g: Flag Node Rule.

    React on event : After updating existing content. (as you need)

    & Press Save

  7. You can add conditions if you want whether it should be published or should belong to any content type or what so ever you need. I have used Content is of type.

  8. This is the thing which works like a magic to schedule your event(Here Flag). Click on "Add action" & Select "Schedule component evaluation" under Rule Scheduler

    & Select the Component Value ** as (**Flag Node) which we created just before configuring this rule & Press Continue.

  9. Enter Scheduled evaluation date which will schedule your event when to get triggered.

    Data selector :(Enter Your values as +2 minutes, +2days, +2 weeks etc as your need)

  10. Identifier => Value : [node:title] has been Flagged.(You can use any message you want to see on /admin/config/workflow/rules/schedule along with list of scheduled events.)

  11. Node => Data selector : node

    & Press Save.

    Done with the Rule.

Configuration is done. You can test it now.

But please have a look into this. I was not checking such thing so was not able to see the result. Your event will respond you only after the cron run because it is executed by the cron. The cron triggers a query to check whether something should be published or flagged.If your cron runs every hour and you want something published on 22:35 and it is past that time it will be actually published the next time your cron runs. So if your cron runs at 22:30 and 23:30 the publish will be at 23:30.

Hope this will be helpful for someone.