2

I am using Drupal 7 with Drupal Commerce (not Kickstart). I am having difficulties editing the order confirmation email. I am hoping to basically "duplicate" the Order review page from the Checkout process to be included in the email (order items, prices, total and billing info).

The module I installed is Commerce message and I just had no luck trying to edit the order confirmation email. I do have the Tokens module installed and enabled.

I tried to edit the email under Structure -> Message Types, however, the replacement tokens available (for example: [message:message-commerce-line-item]), don't seem to output anything in the email. Actually, the token itself is included in the email, like so:

<p>[message:message-commerce-line-item]</p>

I have tried several other tokens with the same result. I tried to select Filtered HTML and Full HTML.

Reading through the Drupal Answers I also tried to use !order-summary token, which seems to work, however the email is "unstyled" and includes HTML tags, like so:

<tr class="odd views-row-first views-row-last">
  <td class="views-field views-field-line-item-title" >
     testing credit card payment
  </td>
  <td class="views-field views-field-commerce-unit-price price" >
     $0.25
  </td>
  <td class="views-field views-field-quantity" >
     1
  </td>
  <td class="views-field views-field-commerce-total views-align-right price" >
     $0.25          
  </td>
</tr>

What puzzles me the most is seeing answers like this or this, stating that

You want the Commerce Message module and it's dependencies. It includes customer emails with a full order details, including customer profiles and all the products purchased

Any ideas on the issue? I failed to find any Commerce message tutorial or the way tokens should be used with it in Drupal Commerce. I'd be happy to go through one if it exists, I would be willing to even write one for future users who might have the same problems once I figure this out.

Thanks

2 Answers 2

1

I the end, I had to install the Mime Mail module. My site uses gmail for the site's email, so I had to use Mime Mail together with SMTP module.

The emails render html tags and tokens as needed.

For someone who might experience the similar issue, here is how I configured the Mime Mail witih SMTP:

In admin/config/system/mailsystem scroll down to the "New Class" fieldset. Create a new class using MimeMailSystem for format() and SmtpMailSystem for mail(). Use that newly created class for the "Site-wide default MailSystemInterface class.

I'm still not completely satisfied with this solution as I was hoping to make Commerce Message to work. If someone ever gets to respond to this I would be thankful for the answer.

1

I though I'd put this out there as what worked for me.

I've had a storefront running on Commerce 7.x-1.x for four years. The order confirmation emails have always been lame, but now with purchasing shifted to web, that lameness was becoming too obvious.

I didn't want to install Commerce Message (for whatever reason), so I started with and edited the standard order confirmation email rule at /admin/commerce/config/checkout/rules.

I added a blend of PHP evalution and replacement patterns from the table beneath the Message text area. Here is the result. I'll comment it a little (a lot).

blah blah blah greetings

Here is a listing of your order:
<?php // start of PHP code insert
    // get the order; it is an entity I think vs. an array (?)
    // that distinction is common throughout this code segment and I'm too php-ignorant to understand it yet
    $order_wrapper = entity_metadata_wrapper('commerce_order', $commerce_order);  
    // get an array (?) of line items on the order
    $line_items =  $order_wrapper->commerce_line_items->value();
    //loop through each line item
    foreach($line_items as $line_item){ 
        // I want to know if it's 'product' type cuz I treat them differently than 'shipping'.
        // you might see code examples which have this as 
        // $line_item->type->value(), but that just gave me errors.
        $line_item_type = $line_item->type;  
        // again here an ...->amount->value() construction gave me errors
        $unit_price = $line_item->commerce_unit_price['und'][0]['amount']; 
        // here also
        $line_item_total = $line_item->commerce_total['und'][0]['amount']; 
        // if it's product ... 
        if ($line_item_type == 'product') { 
            // casting to (int) gets rid of .00 in quantity.
            // you can't do above if you've got fractional quantities anywhere
            $quantity = (int) $line_item->quantity; 
            // get the product from the line item
            $product = commerce_product_load($line_item->commerce_product['und'][0]['product_id']); 
            // print out qty and product name separated by a few spaces, "x" and tab
            echo $quantity . "  x\t" . $product->title . "\n";  
            // on next line start with tab and spaces, then @, then formatted unit price then line total amount
            echo "\t   @  \$" . number_format($unit_price/100, 2) . " ea ...\t\$" . number_format($line_item_total/100, 2) . "\n";
        } 
        // if it's not 'product' it's 'shipping' and it's always the last one.
        else { 
            // print tab, then "Shipping:  ", then the chosen shipping option, then that unit cost
            echo ucwords($line_item_type) . ":  " . $line_item->data['shipping_service']['display_title'] . " ... \$" . number_format($unit_price/100, 2) . "\n";
        }
    } // end foreach loop
?> // end of PHP code insert

Total incl. tax:  [commerce-order:commerce_order_total] // tax is not available as a distinct element as far as I could tell
Payment:  [commerce-order:payment-method-display-title] // this one is not very descriptive in practice

Your comments:  [commerce-order:field_order_comments]

Shipping address (if applicable):
[commerce-order:commerce_customer_shipping] // this one thankfully spits out all 4-6 lines

blah blah blah nice signoff

The end result is an email like so:

blah blah blah greeting

Here is a listing of your order: 
1  x    Vivamus at laoreet orci
           @  $25.00 ea ... $25.00 
2  x    Donec eleifend rutrum consequat
           @  $25.00 ea ... $50.00 
2  x    Felis commodo tristique efficitur
           @  $25.00 ea ... $50.00 
Shipping:  Fedex/UPS/Whatever ... $1.23

Total incl. tax:  $132.50 
Payment:  Credit card

Your comments:

Shipping address (if applicable): 
Alfred E Neuman 
123 Elm St 
Anytown, KS  12345 
987-654-3210

blah blah blah nice signoff

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.