Page 1 of 1

Manually entering order - do not want email sent

Posted: Mon Jun 28, 2010 2:39 pm
by Thistle3408
The Order Placed email is set up and when a customer places their order, it is triggered...that's fine for orders entered by customers directly.

However, we get a lot of purchase orders, some of which require some editing (some for special one-off pricing, some for other reasons) after being entered.

When we receive and process one of these, we enter the order manually through the admin side. We find the user, go to create their order, enter items, etc. In other words all the normal steps for entering an order, except when it gets to the payment screen "Create Order for customerxxx (Step 4 of 4)" we want to put in "Defer Payment" so that we can make some adjustments, whatever they might be.

At this point, however, the Order Placed trigger causes the Order Placed email to be sent and we're not really done entering/adjusting the order details yet. In effect I want that Order Placed email to go our AFTER we have adjusted the order, even if we have to do it manually or semi-manually.

Here's the logic I want, while retaining the automatic sending of that email when a customer completes their order on the customer side.

1. FInd User
2. Enter Order (items, addresses, etc.)
3. Set Shipping method
4. If everything is okay (no adjustments to the order needed) the select the payment method (e.g., PayPal, Credit Card via ath.net, Purchase Order....any method other than "defer", then it's okay to send the Order Placed email
5. If something needs to be changed in the order (let's say it's a one-off price deal) then click on "Defer Payment" and DO NOT trigger the sending of the Order Placed email at that time.

Maybe there is a better trigger for the customer side and this situation could be avoided.

I'd appreciate your experiences on how to address this...the way it works now, either we have to go "untrigger" the email, finish the order, then reset the trigger....and, manually cause the Order Placed email to the customer.

Re: Manually entering order - do not want email sent

Posted: Mon Jun 28, 2010 2:55 pm
by Shopping Cart Admin
Hello,

Changing the trigger to order paid, should work unless you have non-real time payment methods on the website, which allow orders to be placed without payment.

Re: Manually entering order - do not want email sent

Posted: Mon Jun 28, 2010 3:05 pm
by Thistle3408
I thought of that, but we do have non-real time payments available.

Does the "paid" trigger get set when someone enters that they will pay via Check, for example?

If it does (and also for the others below) then that would solve it, wouldn't it?

Credit/Debit Card
PayPal
Check or Wire Transfer
Purchase Order

(also have a "Gratis" and "Defer" which can be used on the admin side only).

Is the Paid Trigger set when the customer says, "Yes, pay using that method"?

I've always been a tad confused by the triggers (and others must be too, as the head of one of the AC partners told me some stuff that was proven wrong empirically.

Re: Manually entering order - do not want email sent

Posted: Mon Jun 28, 2010 3:16 pm
by Shopping Cart Admin
Hello,

Check or Wire Transfer
Purchase Order
"Gratis" and "Defer"

These would not kick off the paid order trigger, so I'd guess this would need to be customized situation. Basically to automate what you're doing manually right now as a work around.

Re: Manually entering order - do not want email sent

Posted: Mon Jun 28, 2010 4:25 pm
by Thistle3408
Not sure about that.

As a customer (not the admin side), when I placed an order and tried to "pay" via Check or Wire Transfer no email was sent due to the "Order Paid" trigger. (I still have the Order Placed template in place sent when triggered by the "Order Placed" and I received that.)
If I went into the admin side and changed the Check to "complete" it DID then send the Order Paid email. But I want the customer to get an Order Acknowledgement anytime an order is entered...or should I say, completely entered (to take into account the manually entered orders that need some adjustment.)

On the admin side when I put in an order using the "defer payment" I get the Order Confirmation (based on Order Placed Trigger) and only when I "complete" a payment (of any kind...as long as it is completed) the email is sent based on the Order Paid trigger.


Is that clear?

Seems to me that the way around this is to leave everything EXCEPT the manually clicked "Defer Payment" use the "Order Placed" trigger. That would mean I need to find where the "defer payment" is detected, prior to the "order placed" trigger being triggered and then have the order administrator send the email as part of their process to complete a manual order that needed to be "deferred".

Can you point me to where that might be customized?

Re: Manually entering order - do not want email sent

Posted: Tue Jun 29, 2010 5:39 am
by mazhar
One workaround could be to control Email send functionality through code. Simply remove order placed trigger from confirmation Email. Then put some code on both retail and admin order pages to trigger alerts depending upon your custom logic. See following thread about how to put code to send Emails manually
viewtopic.php?f=42&t=8571

Re: Manually entering order - do not want email sent

Posted: Wed Jul 07, 2010 9:27 am
by Thistle3408
Okay, I tired to do some of this but I guess I am not smart enough )yet).

I went to the two off-line payment methods and found
Purchase Orders
Check or Wire Transfer

The purchase orders are processed through
PurchaseOrderPaymentForm.ascx

But I find two of them...one under Admin and one under Checkout directories.
Looks like the code is very close (one must be for manually entered POs and the other for customer entered POs).

The Check or WT is processed through
CheckPaymentForm.ascx

Same situation (two of them).

But the two versions aren't my real question; however if you have any insight that might cause me difficulties let me know.

So I used the link to the other post (viewtopic.php?f=42&t=8571) and it helps but just not quite enough.

If I want to mimic the normal "Customer Order Notification" email what parameters do I need to pass and how do I do that.

In all the code for the above ascx forms, there is code that looks like this:

Code: Select all

                //PROCESS THE CHECKOUT
                CheckoutRequest checkoutRequest = new CheckoutRequest(payment);
                CheckoutResponse checkoutResponse = Token.Instance.User.Basket.Checkout(checkoutRequest);
                if (checkoutResponse.Success)
                {
                    if (CheckedOut != null) CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                    Response.Redirect(NavigationHelper.GetReceiptUrl(checkoutResponse.OrderId));
                }
                else
                {
                    List<string> warningMessages = checkoutResponse.WarningMessages;
                    if (warningMessages.Count == 0)
                        warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                    if (CheckedOut != null) CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                }
It seems to me that I could add some code between these instructions and accomplish the goal.

if (CheckedOut != null) CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
// add email code here
Response.Redirect(NavigationHelper.GetReceiptUrl(checkoutResponse.OrderId));

But what code?

You suggested (for the vendor notification):

Code: Select all

                    EmailTemplateCollection emailTemplates = EmailTemplateDataSource.LoadForCriteria(" Name = 'VendorNotificationEx' ");
                    if (emailTemplates.Count > 0)
                    {
                        emailTemplates[0].Parameters.Add("store", Token.Instance.Store);
                        emailTemplates[0].Parameters.Add("order", _Order);
                        emailTemplates[0].Parameters.Add("vendorname", orderItem.Product.Vendor.Name);
                        emailTemplates[0].ToAddress = orderItem.Product.Vendor.Email;
                        emailTemplates[0].Send();
                    }
I can easily change the email template name from 'Vendor....' to my template.
I don't care about the vendor, so those two lines can go away.
If I put this code into the modules I mentioned, I get an error on the _Order (not valid in context)...do I really need to set up those parameters. If so how? If not, does that mean the email templates always get the key things (order, customer) ?

So, what do I need to put into the(se) module to make this work?

Re: Manually entering order - do not want email sent

Posted: Wed Jul 07, 2010 9:55 am
by mazhar
You need to update following part of the payment forms

Code: Select all

if (checkoutResponse.Success)
                {
........................
........................
}
You need to handle this here because order it will be available here. For example following code could be used to send confirmation Email with required parameters.

Code: Select all

if (checkoutResponse.Success)
                {
                    Order order = OrderDataSource.Load(checkoutResponse.OrderId);

                    EmailTemplateCollection emailTemplates = EmailTemplateDataSource.LoadForCriteria(" Name = 'OrderCofirmation' ");
                    if (emailTemplates.Count > 0)
                    {
                        emailTemplates[0].Parameters.Add("store", Token.Instance.Store);
                        emailTemplates[0].Parameters.Add("order", order);
                        emailTemplates[0].Parameters.Add("customer", order.User);
                        emailTemplates[0].Parameters.Add("payments", order.Payments);
                        emailTemplates[0].Send();
                    }
....................................................................
....................................................................
}

Re: Manually entering order - do not want email sent

Posted: Thu Jul 08, 2010 10:03 am
by Thistle3408
In general that worked.

I have a related problem, however.

First, what worked.
I fixed the code in the Mail (it's used for the Check/Money order payments) and Purchase Order payment forms to include the code above.
On the "customer" side, all is working well. On the admin order creation, the PO form is also working well.

So, 3 out of 4 worked fine. I also changed the standard Order Notification Message to be triggered when Order is Paid. So, I think we almost have accomplished the objective.

What's not working is the MailPaymentForm.ascx.cs in the admin-orders-create folder.

First thing that occurred was an error. When clicking to go from "CreateOrder3" to "CreateOrder4" I get an error.
======================error shown is======================
Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'EmailTemplateCollection' could not be found (are you missing a using directive or an assembly reference?)

Source Error:


Line 131: Order order = OrderDataSource.Load(checkoutResponse.OrderId);
Line 132:
Line 133: EmailTemplateCollection emailTemplates = EmailTemplateDataSource.LoadForCriteria(" Name = 'Customer Order Notification' ");
Line 134: if (emailTemplates.Count > 0)
Line 135: {

Source File: c:\inetpub\wwwroot\netgate\Admin\Orders\Create\PurchaseOrderPaymentForm.ascx.cs Line: 133
=============================================================

Well, that threw me for a loop, but I said, fine, let's just restore the backed up version of that module...which I did (delete new one, rename "copy" to original) The code in that module no longer has the EmailTemplateCollection....code in it.

How come the compiler is not using the most recent version?

Re: Manually entering order - do not want email sent

Posted: Thu Jul 08, 2010 10:18 am
by mazhar
Its because its unable to find the class definition because of missing namespace. If you are doing this in separate *.cs file then simply add following in above using statements

Code: Select all

using CommerceBuilder.Messaging;
If this script is in *.ascx file then try simply prefixing EmailTemplateCollectoin and EmailTemplate names as

Code: Select all

CommerceBuilder.Messaging.EmailTemplateCollection
and

Code: Select all

CommerceBuilder.Messaging.EmailTemplate

Re: Manually entering order - do not want email sent

Posted: Thu Jul 08, 2010 11:46 am
by Thistle3408
Got her done.
Thanks

Re: Manually entering order - do not want email sent

Posted: Fri Jul 16, 2010 4:52 pm
by Thistle3408
Ah, well, I thought I had it done.

Clearly I have the 'manual' sending of emails working (for the non-realtime payment methods such as check, purchase orders).

Now on the emails for customers using the normal payment methods (PayPal, Credit Card, Google Checkout) I wasn't sure which way to set this up.

The "Order Confirmation" email template is there and exists (in fact it is the template sent by the code xxxpaymentforms.ascx.cs as discussed above.)

On the Administration > Configure > Email > Templates screen I did NOT set up an Event Trigger (mainly because I wasn't sure which one(s) to use. So I went to the Administration > Configure > Order Statuses screen and set up the "Ready for Fulfillment" status, which has "Order Paid" as a trigger, and under Select Emails:, checked the email template "Customer Order Notification".

I assumed that when an order is paid, the status would get set to the "ready..." status and that the selected email would be sent. The "help" bubble tells me that what I am doing is the intended purpose for the "select emails".

It does not appear to be getting sent. I manually tried to set an order to the "ready..." status and nothing happened, if that's helpful.

What am I doing wrong?