2

I am using Drupal Commerce 7x-1.10 and PayPal WPS 7.x-2.3 module. How can I send an email to customer (both anonymous and authenticate), if they cancel the order or cancel the payment method or cancel anytime within the checkout process?

I am using rules, also I have use "cancelled" in the Condition section. But for some reason it is not working. Please see below for the rules code -

{ "rules_completing_the_checkout" : {
    "LABEL" : "Completing the checkout",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "mimemail", "commerce_checkout" ],
    "ON" : { "commerce_checkout_complete" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "commerce-order:status" ], "value" : "canceled" } }
    ],
    "DO" : [
      { "mimemail" : {
          "key" : [ "commerce-order:mail" ],
          "to" : [ "commerce-order:mail" ],
          "cc" : [ "" ],
          "subject" : "Cancel Order? Why",
          "body" : "Cancel Order? Why",
          "plaintext" : "Cancel Order? Why",
          "language" : [ "commerce-order:state" ]
        }
      }
    ]
  }
}
2

I think you can implement it via the module Rules

Just add the action "Send email" for a custom rule that has the "order state changes" event conditionally on order state "cancelled."

| improve this answer | |
  • Yes, I am using rules. I have edited my question and given the rules code, please check it. – Sandip Choudhury Jan 16 '16 at 5:00
1

Did you found any solution to this? If not, here's what you can do....

  1. Create a module with custom event hook_rules_event_info
  2. Implement hook_redirect_form_back and hook_process_callback in your payment gateway
  3. Use rules_invoke_event in your above method to execute the rule.
  4. Use Rules UI to create new rule with the above event and send mail as action.

Example:

/**
 * Implementation of hook_rules_event_info()
 */
function YOURMODULE_rules_event_info() {
    return array(
        'commerce_payment_canceled_event' => array(
            'label' => t('Commerce payment canceled'),
            'module' => 'YOURMODULE',
            'group' => 'Any group' ,
            'variables' => array(
                'commerce_order' => array(
                    'type' => 'commerce_order',
                    'label' => t('Completed order', array(), array('context' => 'a drupal commerce order')),
                ),
            ),
        ),
    );
}

    /**
     * + * Payment method callback: redirect form back callback.
     * + */
    function PAYMENTGATEWAY_redirect_form_back($order, $payment_method)
    {
        // Display a message indicating the customer canceled payment.
        //Can also be done in rule via set system message and level set to error    
        drupal_set_message(t('You have canceled payment but may resume the checkout process here when you are ready.'), 'error');

        // If you wish to reset selected payment while redirecting
        unset($order->data['payment_method']);

        // Process callback information from gateway.
        return PAYMENTGATEWAY_process_callback($order, $payment_method);
    }

    function PAYMENTGATEWAY_process_callback($order, $payment_method)
    {
        rules_invoke_event('commerce_payment_canceled_event', $order);

    }

Found this base idea from someone using Ogone payment gateway.

| improve this answer | |

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.