Rune Grønkjærs Blog
Abonnér på mit feed

How to use the Tea Commerce events

UPDATED: 10. june 2011

How to use the Tea Commerce Event Model

All you need to do to sign up for one or more of the Tea Commerce events are to implement ITeaCommerceExtension interface. Tea Commerce will then automatically run the Initialize method, so you can sign up for the events you want. All Events are located on the class WebEvents.

It is important to say that the Tea Commerce objects, you are passed as parameters, are the cached objects. You must save the objects yourself to persist the data. You do this by calling the Save() method on the order. If you add new objects it might be a good idea to save if you need their id’s. When you call Save() the new objects are stored in the database and they get their id’s.

The Save method also saves “children”. That is, if you edit an order line and then call save on the order, your order line will be saved. You will be able to edit order properties, order lines, order line prices etc. and with a single order.Save(), to save all changes. We observe what changes you make on the fly. This means that we are able to optimize the saving process to only save what you have updated, added, deleted, destroyed or otherwise changed.

Example of using the Tea Commerce Events

using TeaCommerce.Data.Extensibility;
using TeaCommerce.Data;
using System.Net.Mail;
namespace TeaCommerce.WebShop.Integration {
  public class LicenseExtension : ITeaCommerceExtension {

    #region ITeaCommerceExtension Members

    //The Initialize method lets you subscribe to all Tea Commerce events
    public void Initialize() {
      WebshopEvents.BeforeOrderMailSend += OrderController_BeforeOrderMailSend;
      WebshopEvents.OrderLineAdded += WebshopEvents_OrderLineAdded;
      WebshopEvents.BeforePaymentFormGenerated += new TCPaymentFormGeneratedEventHandler( WebshopEvents_BeforePaymentFormGenerated );
    }

    #endregion

    void WebshopEvents_OrderLineAdded(Order order, OrderLine orderLine) {
      orderLine.Quantity += 5;
      orderLine.AddProperty(new OrderProperty("game", "Civilization"));
    }

    void WebshopEvents_BeforePaymentFormGenerated( Order order, Dictionary<string, string> paymentProviderSettings, string paymentProviderAlias ) {
      //Setting the autocapture to true on the payment settings
      //You could do this after checking the orderlines to see if it would be ok
      paymentProviderSettings[ "autocapture" ] = "1";
    }

    void OrderController_BeforeOrderMailSend(Order order, MailMessage mail) {
      //Here we set an ekstra reciever for the confirmation e-mail
      mail.Bcc.Add(new MailAddress("rune@gronkjaer.dk"));
    }

  }
}

Explanation of all event handlers

Below I have written down all event handlers that can be used. I have cheated a little and gives you both the name of the event handler and its profile. That way I can show the parameters too.

OrderCreated

/// <summary>
/// This event is fired when the order has just been created
/// </summary>
OrderCreated( Order order );

OrderChanged

/// <summary>
/// This event is fired when the current order has been changed.
/// The user will now be working on a partial clone of the order.
/// The Clone wil have brand new ID's for everything and the order status will have changed.
/// Created and modified dates will have changed as well.
/// The eventhandler will have the CLONED order passed as a parameter.
/// </summary>
OrderChanged( Order order );

OrderDeleted

/// 
/// This event is fired when the order is deleted
/// 
OrderDeleted( Order order );

AfterOrderMailSend

/// <summary>
/// This event is fired when one or more order properties has been updated
/// </summary>
AfterOrderMailSend( Order order, List<OrderProperty> orderProperties );

BeforeOrderConfirmationMailSend

/// 
/// This event is fired before the confirmation e-mail is sent to the user.
/// 
BeforeOrderConfirmationMailSend( Order order, MailMessage mail )

AfterOrderConfirmationMailSend

/// 
/// This event is fired after the confirmation mail has been sent to the user
/// 
AfterOrderConfirmationMailSend( Order order )

AfterOrderConfirmationMailSend

/// 
/// This event is fired after the confirmation mail has been sent to the user
/// 
AfterOrderConfirmationMailSend( Order order )

OrderConfirmationMailError

/// 
/// This event is fired if the mail somehow could not be sent.
/// 
OrderConfirmationMailError( Order order );

AfterOrderFinalized

/// <summary>
/// This event is fired after the order has been finalized
/// </summary>
AfterOrderFinalized( Order order );

BeforeMailSend

/// 
/// This event is fired before the e-mail is sent to the user.
/// 
BeforeMailSend( Order order, MailMessage mail, EmailTemplate emailTemplate );

AfterMailSend

/// 
/// This event is fired after the mail has been sent to the user
/// 
AfterMailSend( Order order, EmailTemplate emailTemplate );

MailError

/// 
/// This event is fired if the mail somehow could not be sent.
/// 
MailError( Order order, MailMessage mail, Exception ex, EmailTemplate emailTemplate );

OrderLineAdded

/// <summary>
/// This event is fired when an order line has just been added to the order.
/// The orderline may not be new. In that case the quantity has been changed.
/// </summary>
OrderLineAdded( Order order, OrderLine orderLine );

OrderLineRemoved

/// 
/// This event is fired when an order line has just been removed to the order.
/// 
OrderLineRemoved( Order order, OrderLine orderLine );

OrderLineChanged

/// 
/// This event is fired when an order line has just been chnaged.
/// 
OrderLineChanged( Order order, OrderLine orderLine );

OrderLinePropertiesUpdated

/// 
/// This event is fired when one or more order line properties has been updated
/// 
OrderLinePropertiesUpdated( Order order, OrderLine orderLine, IEnumerable orderLineProperties );

CurrencyChanged

/// 
/// This event is fired  a new currency is selected for the order
/// The new currency is passed in the eventhandler
/// 
CurrencyChanged( Order order, Currency currency );

CountryChanged

/// <summary>
/// This event is fired after a new delivery country is selected for the order
/// The new country is passed in the eventhandler
/// </summary>
CountryChanged( Order order, Country country );

ShippingMethodChanged

/// <summary>
/// This event is fired after a new shippingMethod is selected for the order
/// The new shippingMethod is passed in the eventhandler
/// </summary>
ShippingMethodChanged( Order order, ShippingMethod shippingMethod );

PaymentMethodChanged

/// <summary>
/// This event is fired after a new paymentMethod is selected for the order
/// The new paymentMethod is passed in the eventhandler
/// </summary>
PaymentMethodChanged( Order order, PaymentMethod paymentMethod );

OrderStatusChanged

/// <summary>
/// This event is fired after a new orderStatus is selected for the order
/// The new orderStatus is passed in the eventhandler
/// </summary>
OrderStatusChanged( Order order, OrderStatus orderStatus );

PaymentStatusChanged

/// 
/// This event is fired  a new payment status has been set
/// 
PaymentStatusChanged( Order order, PaymentStatus? paymentStatus, APIInfo apiInfo );

BeforePaymentFormGenerated

/// <summary>
/// This event is fired before the payment provider generates the payment form for the javascript
/// </summary>
BeforePaymentFormGenerated( Order order, Dictionary<string, string> paymentProviderSettings, string paymentProviderAlias );

Tea Commerce links

This post was written in .NET, e-commerce, Tea Commerce, Umbraco. Ad permalink to favorites. Follow all comments with RSS feed for this posts. Drop a comment or a trackback: Trackback URL. | Læs denne side på dansk dansk version

One comment

  1. Written November 28, 2010 at 2:47 am | Permalink

    Awesome :-)

2 Trackbacks

  1. Af Tea Commerce lingo and concepts on December 3, 2010 at 10:20 am

    [...] Skip to content Home CVModal WindowjQ Modal WindowjQuery Modal Window standard settingsjQuery Modal Window DocumentationImage ViewerjQ LightViewLightview standard settingsjQuery Image Viewer standard settings A danish blog about Javascript and Webdevelopment « How to use the Tea Commerce events [...]

  2. Af Tea Commerce dynamic VAT on April 12, 2011 at 1:06 pm

    [...] http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl. I choose to sign up for two Tea Commerce events where I have the ability to manipulate the order. One is “CountryChanged” which of [...]

Drop a comment

Your email is never published nor shared. Required fields are marked *

*
*

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Dansk version