Developer forum

Forum » Development » email notification

email notification


Reply
I’m developing a payment Gatway that is singular in step 5 the user is redirected to a site where you enter the credit card information. This gateway receives as parameter a notificationURL, which will be used to notify the dynamicweb that the order has been paid (this is necessary if the customer closes the window without going back to the buyer’s site without going through step 6). I'm trying to send an email to de buyer when I receive that notification but I am not able to.



Dynamicweb.eCommerce.Orders.

Dynamicweb.eCommerce.Orders.Gateways.

Order o = new Order(Request.QueryString["_OID_"]);Redunicre_3 r = getGatewayTemplate(new Dynamicweb.eCommerce.Orders.Payment(o.PaymentMethodID));

 

{

if (!o.Complete)

o.Complete =

true;

o.ConnectToUsersEmail(o.CustomerEmail);

Dynamicweb.Frontend.

PageView pv = new Dynamicweb.Frontend.PageView(101);

Dynamicweb.Templatev2.

Template template = new Dynamicweb.Templatev2.Template("eCom/Cart/OrderShopEmail_FH.html");

o.SendTo(ref pv, o.CustomerEmail, "no-reply@host.com", ref template);

}

 

o.StateID = r.PayedStatusID;

o.Save();


Replies

 
Reply
Hi Humberto 

Have you tried debugging through your code?
Is it the call to Order.SendTo that fails to send the email or is the error that the call to Order.SendTo is never made?

 - Lasse
 
Reply

Thanks in advance for your reply,
I think I found the exception problem but don’t know how to solve  this one ,

If I indicate the complete path to the template file like this:

 

Dynamicweb.Templatev2.Template template = new Dynamicweb.Templatev2.Template("./"+Request.ServerVariables["server_name"]+"/Files/Templates/eCom/Cart/OrderShopEmail_FH.html");

 

It don’t throw any exception and the email is sent but is empty.

What do I need to do to order details appear in the email content?

Thanks!

 
Reply
Hi Humberto 

Actually you need to call the Template constructor with the path relative from /Files/Templates.

So your call should be

Dynamicweb.Templatev2.Template template = new Dynamicweb.Templatev2.Template("eCom/Cart/OrderShopEmail_FH.html");

 - Lasse

 
Reply

I can see that the template object is correct.(writing it to a log file)

And looking at the exception I can see that it occurs when is rendering the template.

I think that once the notification is made after the browser is closed and skip step 6 (that’s way I need to send a email to the client), the frontend isn’t instantiated.

This is only a guess, I’m a beginner in DW modules development.

If that is true what can I do to resolve it??

 

 

templateHTML  :

<table width="600" cellspacing="0" cellpadding="0">

  <tr>

    <td style="padding-bottom: 25px;"><a href="http://www.falesiahotel.com" target="_blank" title="Falésia Hotel"><img src="http://falesiahotel.dev.dynamicweb.pt/Files/System/FalesiaHotel/BarraNewsletter.jpg" alt="Falésia Hotel" width="600" height="100" border="0" /></a>

  </tr>

  <tr>

    <td style="border:1px solid #cccccc;padding:35px;">

      <table border="0" cellspacing="0" cellpadding="2" width="100%">

        <tr>

          <td style="font-size:10px; padding-bottom:15px; font-family:Verdana, Helvetica, Arial;">Nova reserva</td>

        </tr>

      </table>

      <table border="0" cellspacing="0" cellpadding="2" width="100%">

        <tr>

          <td width="80" style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><b>Reserva:</b></td>

          <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><!--@Ecom:Order.ID--></td>

        </tr>

        <tr>

          <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><b>Data:</b></td>

          <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><!--@Ecom:Order.Date--></td>

        </tr>

        <tr>

          <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><b>Nome:</b></td>

          <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><!--@Ecom:Order.Customer.Name--></td>

        </tr>

        <tr>

          <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><b>E-mail:</b></td>

          <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><!--@Ecom:Order.Customer.Email--></td>

        </tr>

        <!--@If Defined(Ecom:Order.Customer.Phone)-->

          <tr>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><b>Telefone:</b></td>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><!--@Ecom:Order.Customer.Phone--></td>

          </tr>

        <!--@EndIf(Ecom:Order.Customer.Phone)-->

        <!--@If Defined(Ecom:Order.Customer.Cell)-->

          <tr>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><b>Telemóvel:</b></td>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><!--@Ecom:Order.Customer.Cell--></td>

          </tr>

        <!--@EndIf(Ecom:Order.Customer.Cell)-->

        <!--@If Defined(Ecom:Order.Customer.Address)-->

          <tr>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><b>Morada:</b></td>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><!--@Ecom:Order.Customer.Address--></td>

          </tr>

        <!--@EndIf(Ecom:Order.Customer.Address)-->

        <!--@If Defined(Ecom:Order.Customer.Address2)-->

          <tr>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"></td>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><!--@Ecom:Order.Customer.Address2--></td>

          </tr>

        <!--@EndIf(Ecom:Order.Customer.Address2)-->

        <!--@If Defined(Ecom:Order.Customer.City)-->

          <tr>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><b>Localidade:</b></td>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><!--@Ecom:Order.Customer.City--></td>

          </tr>

        <!--@EndIf(Ecom:Order.Customer.City)-->

        <!--@If Defined(Ecom:Order.Customer.Country)-->

          <tr>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><b>País:</b></td>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><!--@Ecom:Order.Customer.Country--></td>

          </tr>

        <!--@EndIf(Ecom:Order.Customer.Country)-->

        <!--@If Defined(Ecom:Order.Customer.Comment)-->

          <tr>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;" valign="top"><b>Comentários:</b></td>

            <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;" valign="top"><!--@Ecom:Order.Customer.Country--></td>

          </tr>

        <!--@EndIf(Ecom:Order.Customer.Comment)-->

      </table>

      <table border="0" cellspacing="0" cellpadding="2" width="100%">

        <tr>

          <td style="padding-bottom: 8px; border-bottom:3px solid #cccccc; text-align: center; font-size:10px; font-family:Verdana, Helvetica, Arial;" colspan="2"><b>Produto</b></td>

          <td style="padding-bottom: 8px; border-bottom:3px solid #cccccc; text-align: center; font-size:10px; font-family:Verdana, Helvetica, Arial;" width="90"><b>Data</b></td>

          <td style="padding-bottom: 8px; border-bottom:3px solid #cccccc; text-align: center; font-size:10px; font-family:Verdana, Helvetica, Arial;" width="90"><b>Preço</b></td>

        </tr>

        <!--@LoopStart(OrderLines)-->

          <tr>

            <td style="font-size:10px; border-bottom:1px solid #cccccc;" width="120" valign="top"><img src="http://falesiahotel.dev.dynamicweb.pt<!--@Ecom:Product.ImageSmall.Default.Clean-->" alt="<!--@Ecom:Order:OrderLine.ProductName.Short-->" /></td>

            <td style="font-size:10px; border-bottom:1px solid #cccccc; font-family:Verdana, Helvetica, Arial;" valign="top">

              <table border="0" cellspacing="0" cellpadding="2" width="100%">

                <tr>

                  <td style="font-size:12px; font-family:Verdana, Helvetica, Arial;"><b><!--@Ecom:Order:OrderLine.ProductName.Short--></b></td>

                </tr>

                <tr>

                  <td style="font-size:10px;">

                    <table border="0" cellspacing="0" cellpadding="0">

                      <tr>

                        <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><b>Pensão:</b></td>

                        <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><!--@HotelBooking:Reservation:BoardType--></td>

                      </tr>

                      <tr>

                        <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><b>Adultos:</b></td>

                        <td style="font-size:10px; font-family:Verdana, Helvetica, Arial;"><!--@HotelBooking:Reservation:NumberOfAdults--></td>

                      </tr>

                    </table>

                  </td>

                </tr>

                <tr>

                  <td style="font-size:10px;">

                    <table border="0" cellspacing="0" cellpadding="2">

                      <tr>

                        <td style="vertical-align:top; font-size:10px; font-family:Verdana, Helvetica, Arial;"><b>Suplementos:</b></td>

                        <td style="vertical-align:top; font-size:10px; font-family:Verdana, Helvetica, Arial;">

                          <!--@LoopStart(BOMItems)-->

                            <!--@Ecom:Order:OrderLine.ProductName.Short--><br />

                          <!--@LoopEnd(BOMItems)-->

                        </td>

                      </tr>

                    </table>

                  </td>

                </tr>

              </table>

            </td>

            <td style="font-size:10px; text-align:center; border-bottom:1px solid #cccccc; font-family:Verdana, Helvetica, Arial;">

              <!--@HotelBooking:Reservation:CheckInDate--><br/>a<br/><!--@HotelBooking:Reservation:CheckOutDate-->

            </td>

            <td style="font-size:12px; text-align:right; border-bottom:1px solid #cccccc; font-family:Verdana, Helvetica, Arial;"><!--@Ecom:Order:OrderLine.TotalPrice--></td>

          </tr>

        <!--@LoopEnd(OrderLines)-->

        <tr>

          <td colspan="4" align="right" style="font-size:12px; font-family:Verdana, Helvetica, Arial;"><b>Total <!--@Ecom:Order.Price.PriceFormatted--></b></td>

        </tr>

      </table>

    </td>

  </tr>

</table>

 

The Exception:

 

Object reference not set to an instance of an object.

 

at Dynamicweb.eCommerce.Frontend.Renderer.RenderProduct(Product Product, Boolean ExtendedProperties, Template Template, Int32 loopCounter)

   at Dynamicweb.eCommerce.Frontend.Renderer.RenderOrderLine(OrderLine OrderLine, Template Template)

   at Dynamicweb.eCommerce.Frontend.Renderer.RenderOrderLines(OrderLineCollection OrderLines, Template ParentTemplate, String LoopName)

   at Dynamicweb.eCommerce.Frontend.Renderer.RenderOrder(Order Order, Template Template, Boolean ExtendedProperties, Int32 stepReq)

   at Dynamicweb.eCommerce.Orders.Order.SendTo(PageView& PageView, String ToMailAddress, String FromMailAddress, Template& MailTemplate)

   at Redunicre3PaymentPage.Page_Load(Object sender, EventArgs e)

 
Reply
Hi Humberto

I think it's your pageview object that is not initialized properly.

Try using
pv = Dynamicweb.Frontent.PageView.GetPageView();

 - Lasse
 
Nicolai Høeg Pedersen
Reply

Should use Pageview.Current instead

 
Reply


It's working!!! it was just call the Load method to fill the object

Thanks for your help!!


PageView
pv = new Dynamicweb.Frontend.PageView(101);

pv.Load();

 
Nicolai Høeg Pedersen
Reply
You should be carefull about that method of creating an instance of the pageview. It could result in redirects, and other unwanted frontend behaviour.

Use PageView.GetPageviewByPageID(101) instead - it loads the object correctly and makes it more suitable for API usage.

 
Reply

I’m sorry to post again, I forgot that I had hardcoded parameters.
Have two more problems, the email is send but is in text plain, I thought  that the SendTo(…) method send an email like if the buyer pass throw step 6 in the shopping cart.

And, in my code the path to the html template is hardcoded, once this module is meant to be used in other  applications how could I get that information dynamically?

Thanks!

 
Reply
Hi Humberto

If you need more control of the email, you can actually judt render the order yourself by calling the RenderOrder method of Dynamicweb.eCommerce.Frontend.Renderer. After you have the output you can do with it what you want (e.g. sending an email).

If you need to make the template path dynamic, you can build a custom module and have the template path being a part of the control panel settings for that module.

 - Lasse

 

You must be logged in to post in the forum