Xử lý bán hàng với Organic Groups cho Drupal Commerce

Xử lý bán hàng với Organic Groups cho Drupal Commerce

There are several ways to sell access to content on your Drupal site. One of the ways that hasn't been discussed much in Drupal tutorials is selling access to private Organic Groups with Drupal Commerce. 

As I needed this for my own project I hired Hibersh to create the Rule configurations for me. It worked perfectly ever since. As I saw other people struggling with achieving the same thing I decided to spend half a day writing this tutorial for you. I hope it helps you doing Drupal :)  

What you get

First let me discuss what you will get at the end of this tutorial:

Drupal users can purchase access to an Organic Group by purchasing a certain Drupal Commerce product.

You are going to make it so that you won't have to create a custom Rule for every Organic Group. You will have a 'universal' Rule configuration. Your site administrators or content admins can manage products and Organic Groups and the product -> Organic Group relationship and add and delete them as they see fit - if you decide to allow them to do that if course :)

Neat fact: buying 1 product can give access to 1 or several Organic Groups if you like.

To Make it Work

I've actually made 2 tutorials for you:

the Quick version: enable the example Feature and add a few nodes and you're done

the Drupalist version: learn how the structure works - knowing the right Fields and Rules configuration enables you to make it work for your own usecase. You will feel you've mastered a cool Drupal skill once you completely understand how this works!

the Quick version

Enable these modules: Organic Groups, Organic Groups access control (and Organic Groups UI). They are all part of the og project on drupal.org. Other dependencies Strongarm and Inline Entity Form. That last one is because I've built the Feature in Commerce Kickstart 2.x. Don't forget to enable Features module.

Download the selling_content feature as a zip file or through Git.

Enable the selling_content Feature on your site.  

Create 1 'Content Group' node,

Create 1 'Group Content' node and make it reference your 'Content Group' node.

Create 1 'Product for Organic Group' and make it reference your 'Content Group' node.

Done.

the 'Drupalist version'

Now let's have a look what we've actually built by enabling that selling_content Feature.

The Feature consists of a structure and a Rules configuration.

The structure

structure for selling access to Organic Groups

The Product Display -> Product reference

This is how most Drupal Commerce stores are configured. If you are not familiar with them, learn about them in this tutorial about Product Displays.

The Product -> Organic Group reference

This allows you to create a Drupal Commerce product and reference the Organic Groups it should give access to. Our Rules configuration below allows us to reference multiple Organic Groups from one product - or just one if your usecase needs to give people access to one Organic Group per product purchase. The Organic Groups need to be private and the content copies this behavior.

The Content -> Organic Group relationship

This is how most Organic Groups are structured: A content node with an Organic Groups field that makes it behave as 'Group content' and a group node with an Organic Groups field that makes it behave as 'Group'. The 'Group Audience' on the content node references the Group node.

the Rules Configuration

To make this work we'll have 2 Rules and 2 Rules components.

Rule 'OG subscribe after Product purchased'

Rule to subscibe a user to an Organic Group

This Rule in the selling_content Feature gives people access to the Organic Group if they completed the checkout AND made the payment for the order. In this example our 'Organic Group Rules' will act on the Rule event 'Completing the checkout process'. To make absolutely sure we only give paid users access to our group we've added a condition that checks of the order is paid. (Order balance comparison <= 0)

It's action loops over the line items of the order and executes the Rule Component 'OG subscribe line item' for each of them.

Rule Component 'OG subscribe line item'

Rule Component that subscribes line items to the OG

This Rule Component checks a couple of things in its condition:

the line item is of type 'product'

the product is of type 'Product for Organic Group'

The Organic Group Entity reference field is not empty

As action it loops over all the references field - that way we can reference multiple Organic Group nodes from one product node.

In that loop it adds the customer to the referenced Organic Group

That completed the Checkout part. You're done.

OG unsubscribe after Order Canceled

You probably want to remove users from the Organic Group when their order is cancelled for some reason - for example when they 'return' the product and want their money back.

That's exactly what the Rule 'OG unsubscribe after Order Canceled' is for, have a look:

unsubscribe user form OG when cancelling the order

When the order is changed (action) and its 'state' is set to 'Canceled' (condition) it loops over the line items of that order. For every line item a Rule Component is executed.

Rule Component 'OG unsubscribe line item'

This Rule component works almost the same as the other Rule Component. The only difference is that it UNsubscribes the user from the Organic Group instead of subscribing the user to it.

Test test test

Keep in mind that this is only an example Feature and you may need to tweak it to make it work for your specific usecase. If you have suggestions about making it better suited for certain usecases, please share below so others can benefit from your knowledge. Cheers!

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Tận dụng mạng xã hội để làm SEO

Tận dụng mạng xã hội để làm SEO

Để làm seo có hiệu quả ngoài việc tạo nội dung và backlink thông thường như vậy thôi không đủ, vì hiện nay các công cụ tìm kiếm rất quan tâm đến các mạng xã hội như facebook hoặc Twitter

Mật khẩu

Mật khẩu dễ đoán nhất trên thế giới - Tiếng Việt

Mật khẩu tiếng Việt là 1 trong 3 loại mật khẩu dễ đoán nhất, với hơn 14% tài khoản bị lộ mật khẩu sau 1000 lần phân tích từ điển tiếng Việt và 7,8% số tài khoản bị lộ mật khẩu sau khi phân tích bằng từ điển chung toàn cầu.

Tích hợp Facebook vào website

Tích hợp Facebook vào website

Tích hợp website của bạn với Facebook là một cách hay để xây dựng những con đường rộng mở dẫn vào "brand" của mình và làm cho website có vẻ sống động hơn.

Công ty diệt chuột T&C

 

Diet con trung