Sunanda-Systematix
Sunanda-Systematix

Reputation: 66

How to stop 'Send order notification' & 'Send payment notification' in checkout process from code side in kentico

I know there is option in kentico admin setting to stop the sending notification email. but I want to check this in the code for my customization. so could you please suggest me where should I get the code in kentico.

Setting in kentico

Upvotes: 2

Views: 139

Answers (3)

Gina
Gina

Reputation: 33

Using the CMS.Ecommerce library you can check these settings through the API

SiteInfoIdentifier sii = new SiteInfoIdentifier(SiteContext.CurrentSiteID); bool sendOrderNotificationEmail = CMS.Ecommerce.ECommerceSettings.SendOrderNotification(sii);

If you wanted to set them programmatically you would have to use the SettingsKeyInfoProvider SettingsKeyInfoProvider.SetValue("CMSStoreSendOrderNotification ", false);

Upvotes: 1

Enn
Enn

Reputation: 2209

If you are looking to intercept an action when a notification is being sent, you can use Global events for the EmailInfo object like this:

[assembly: RegisterModule(typeof(GlobalEventsModule))]
public class GlobalEventsModule : Module
{
    public GlobalEventsModule() : base (typeof(GlobalEventsModule).Name)
    {
    }

    protected override void OnInit()
    {
        base.OnInit();

        EmailInfo.TYPEINFO.Events.Insert.Before += Insert_Before;
    }

    private void Insert_Before(object sender, ObjectEventArgs e)
    {
         // executed before an e-mail is inserted into DB
         var email = (EmailInfo)e.Object;
    }
}

To cancel the execution in code you can call Cancel() method (although you might get exceptions in this case - you have to test for yourself in your scenario):

private void Insert_Before(object sender, ObjectEventArgs e)
{
    var email = (EmailInfo)e.Object;

    e.Cancel();
}

This will also work only if you are using Email queue (which is highly recommended anyway) and will be executed for all outgoing e-mails, not just notifications.

Upvotes: 1

rocky
rocky

Reputation: 7696

Please refer to the official documentation.

You need to use SettingsKeyInfoProvider:

SettingsKeyInfoProvider.SetValue("CMSSettingName", "SiteName", value);

Leave out the site name parameter if you want to set it globally.

The settings names you are looking for are CMSStoreSendOrderNotification and CMSStoreSendPaymentNotification.

You can find more settings by querying the DB:

SELECT * FROM [CMS_SettingsKey] where keyname like '%cmsstoresend%'

Upvotes: 1

Related Questions