4

I've been working with Drupal Commerce for a few months now. As a non-profit, our organization hosts an e-commerce/e-learning site. We're a smaller organization with approx 20 staff users and <20,000 regular customers.

How do others handle creating audit trails/order revisions within Drupal Commerce? There are quite a few modules out there, but I have yet to find the right combination. Currently, we've added Line Item Revisions module and use the Order revisioning built into Drupal Commerce.

Here are some concerns I'm attempting to address:

  1. How did the order end up in the current state (who and why)?
  2. What was recently changed (line items, status, owner, coupons, etc. who and why also)
  3. How do you identify who deleted records, specifically financial records? Secondly, how to you log what the deleted records originally entailed?

As a non-profit, we're audited annually and when staff can accidentally delete payments/orders/etc for money already collected or products already delivered, we lose any history of how it all happened. I'm hoping I'm not the only one who has this question and some of the more tenured users here can point me in a direction.

3

IMO the Message module would be a perfect fit to answer this question. Using this module, you can create your own custom "Events logging" (to register things that happened in a site).

Specific to this question here, I'd create an appropriate set of so called "Message types" that fit your needs (the "concerns you're attempting to address", as in your question, seem to require multiple Message types). Some of the actual data you probably want to be included in one or more of them:

  • username ("who" did something).
  • event date ("when" did something happen).
  • any data about the actual orders you want to track, such as the order id (of course), etc.

You could even track how those data looked like before and after they got updated, a kind of "light" revisioning (only for those attributes you want to know about).

About Message types: think of them as equivalent to Content types, whereas you create messages (instead of nodes) of a specific Message type (instead of Content type).

Rules integration

A really interesting facility of the Message module is its perfect integration with the Rules module. Have a look at the answer to "How to implement a follow author (or user) function?" for way more details on that.

In your case, you'd simply create a (rather basic) custom rule which uses:

  • a Rules Event like "Before saving a new order", of "After updating an existing order" (or variations of these events).
  • a Rules Action to "Create a message" (of a selected Message type).

That's really it ...

Example included in Commerce Kickstart

A great sample of this can be found in Commerce Kickstart, which uses the Commerce Message module, to create such "Events logging". In that case in the format of an Order History, as shown in this screenprint (from this module's project page).

More info about the Message module

The Message module is an amazing module, it is fully entity based, which implies that it perfectly (out of the box) integrates with modules such as Views and Rules.

For more details about the Message module, refer to some interesting Use Cases detailed within its Community Documentation. And/or checkout the video introduction "Your Drupal site can talk" (if you want you can fast forward to about 03:30 where it really starts).

Learn from examples

There is not a lot of documentation about the Message module (which is what makes it a hidden Drupal gem). A possible way to get started with it, and to get an idea of the kind of things it can be used for, is to have a look at the answers to:

Replacement tokens

Because of the nature of your question, it seems you'll have quite a few of custom data to be included in your custom messages (= log records to be created). Most of them will NOT be supported out of the (message) box.

However, there is a pretty amazing technique you can take advantage of, i.e. the "replacement tokens" used by the Message module. For an in depth tutorial about how to use this technique, refer to "What's the purpose of "Replacement tokens" of a Message type?". Here are some examples where this technique is used:

  • 2
    This is a very helpful response. I'll have to play around with the module a bit to see if it'll fit our use case, but it sounds promising. Thank you @Pierre.Vriens . – Shaun O Jul 12 '17 at 12:30
  • 1
    It's unfortunate that your post (after so much work) was downvoted. I'm relatively new to the community, so I'm sure there will be many more questions to come. Thanks to all the support from devs like you! – Shaun O Jul 17 '17 at 21:19
3

I'm assuming you're using Drupal 7 here but one of the most effective ways to do is to handle it the same way that Commerce Kickstart does: with the Message stack.

There is a Commerce Message module exposes some of the common events, you'll just need to create a view and tie it into your order page or figure out some other way of handling things.

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.