Previous Docs Version
The documentation you are viewing is for a previous version of Tea Commerce. Click here to jump to the current stable version.
Previous Docs Version
The documentation you are viewing is for a previous version of Tea Commerce. Click here to jump to the current stable version.
Attaches a handler to a Tea Commerce event.
There are two kind of event types that your script can be notified about - "before" and "after" events. To specify the eventType you concatenate the keyword "before" or "after" and then the name of the method to be notified about - e.g afterSetCurrentCurrency.
The notification for before events is invoked everytime a JavaScript API method is executed asynchronously or for each method specified in a ajaxForm that is posted. Besides the more specific events being invoked, the universal "beforeCartUpdated" is also invoked, but just ones.
For each method returned in the method called object will result in an after event being invoked. The universal "afterCartUpdated" event is invoked everytime a method called object is returned from a JavaScript Api method.
The universal "cartUpdateError" event is invoked if an error happens during any of the JavaScript API method calls.
Name | Type | Description |
---|---|---|
event | string | Name of the event. |
handler([model,] data[, jQForm]) | function() | A function to execute each time the event is triggered. |
TC.bind('afterCartUpdated', function (data, jQForm) {
if(data.order){
alert('Total price: ' + data.order.subtotalPrice.withVatFormatted);
}
});
TC.bind('beforeSetCurrentCurrency', function (data, jQForm) {
alert('Changing currency');
});
TC.bind('afterAddOrUpdateOrderLine', function (model, data, jQForm) {
alert('New order line quantity: ' + model.quantity);
});
The notification center is the heart of the Tea Commerce event model. This is where your code can be notified when different events happens in the Tea Commerce system. The way to subscribe to the notification center using Umbraco, depends on which version you use. Read about the Application event registration to learn how.
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using TeaCommerce.Api.Models;
using TeaCommerce.Api.Notifications;
using Umbraco.Core;
namespace TeaCommerce.Tests.Notifications {
public class ApplicationStartup : ApplicationEventHandler {
public ApplicationStartup() {
NotificationCenter.Order.OrderPropertiesUpdated += Order_OrderPropertiesUpdated;
NotificationCenter.EmailTemplate.MailSending += EmailTemplate_MailSending;
}
void Order_OrderPropertiesUpdated( Order order, OrderPropertiesUpdatedEventArgs e ) {
CustomProperty couponCode = e.Properties.SingleOrDefault( p => p.Alias == "couponCode" );
if ( couponCode != null /* && couponCode is valid */ ) {
order.Properties.AddOrUpdate( new CustomProperty( "discount", "0.1" ) { ServerSideOnly = true } );
order.Save();
}
}
void EmailTemplate_MailSending( EmailTemplate emailTemplate, MailSendingEventArgs e ) {
if ( emailTemplate.Alias == "confirmationEmail" ) {
e.MailMessage.Bcc.Add( "info@teacommerce.net" );
}
}
}
}