Documentation

Checkout Completion Rules

Drupal Commerce defines several default checkout completion rules that perform the following operations when an order in checkout first reaches the checkout completion page:

  • Updates the order status to the default status of the Pending state (typically the matching Pending status).
  • Assigns an anonymous order with a known e-mail address to the appropriate user account -or-
  • Creates a new user and sends the new account e-mail notification to the customer.
  • Send an order notification e-mail to the customer.

You are free to customize these defaults rules, disable them entirely, and add your own rules to address your business logic pertaining to what must happen on checkout completion. Note that payment may not have been completed at this time; it may still be pending or it may have been submitted as an authorization awaiting a later capture.

If you have business logic that depends on payment being completed, you should add rules to the When an order is first paid in full event instead.

Excercise: Fulfillment Email

To demonstrate the Checkout Rules, we've created an exercise that will send an email to our fulfillment shop once the payment is complete. This is a particularly interesting case because we will not use the event that Commerce picks for us by default. All is explained in the captions.

Add Checkout Rule

By click on "Add Checkout Rule" you have taken the first step. Though, technically this rule is not a checkout rule because of the event we will be using, it's not a bad place to start.

  • Administration
  • Store
  • Store Configuraiton
  • Checkout
  • Checkout Rules: Add Rule

Replace Event

First, go ahead and delete the event that is at the top. Next, you will want to click "Add Event." This is because we don't want to send our fulfillment email until we've received payment.

  • Administration
  • Workflow
  • Rules
  • Edit Rule
  • Rule Overview

Choose this event.

This event will only fire after payment is paid in full. "Completing the Checkout" is not "Paid in Full" and this distinction can be a common mistake. That might allow your customer to fraudulently use a payment that doesn't complete and you find out after you have given them access or sent them the physical product.

  • Administration
  • Workflow
  • Rules
  • Edit Rule
  • Add Event

Add Action

Up until now, this rule could be used for anything. Perhaps you want to assign "Valued Customer" role and send them a 50% coupon code? Anything is possible with Rules. Here, we just want to add an action that will send an email. Can be found under "System > Send Mail"

  • Administration
  • Workflow
  • Rules
  • Edit Rule
  • Add Action

Configure Action

This is the straightforward email action page. This replaces the .tpl for ubercart, which means only plain text emails are possible. If you want HTML emails, we recommend Mime Mail for Drupal (it's designed to work within Rules very well).

  • Administration
  • Workflow
  • Rules
  • Edit Rule
  • Configure Action

Final Rule

This is what our Fulfillment Email Rule looks like when we're done. It reads, "When an order is paid in full, Send Mail." You can't have gone through this and not absolutely fallen in love with Actions.

  • Administration
  • Workflow
  • Rules
  • Edit Rule
  • Rule Overview

Testing the Rule

We added a product to our cart, checked out, and nothing seemed to happen. Notice that even after checkout, the status on the order is "Pending." This is what happens with the default testing payment method. But the event does happen, it just won't show a "display message" action.

  • Administration
  • Store
  • Store Configuraiton
  • Orders
  • Edit Order

To get the event to fire in a way you can see, simply create an order and apply a payment manually.