2017-02-20 117 views
0

我已经创建了自定义网关类,并且需要在管理模块中注册此类。在Kentico中注册自定义类9

我已经添加在CS文件这条线,但它抛出一个命名空间误差

[组件:RegisterCustomClass( “CustomGateway” 的typeof(CustomGateway))]

此外,在管理员 - >模块 - >电子-commerce - >类标签它说我不能添加或删除已安装的模块中的类。

我该如何注册我的自定义门类?

回答

0

确保在.cs文件中为CMS名称空间添加using语句。

using CMS; 

此外,如果你的CustomGateway类是一个自定义命名空间(我们称之为MyCompany),你将需要添加一个using声明该命名空间,以及。

using CMS; 
using MyCompany; 


关于“类”选项卡 - 电子商务类都无关,与注册自定义的支付网关。 只要您使用RegisterCustomClass属性进行注册,就没关系。

然后,您可以在“Store配置”应用程序中继续进行设置。

关于定制支付网关的完整文档可以在here找到。

0

您无法在管理界面的模块中注册自定义支付网关类,只能将.cs文件放入您的模块文件夹中。这将允许在您的模块中轻松导出网关类。

0

这是我在8.2中完成的。以下示例适用于电子商务模块。试试看:

public partial class CMSModuleLoader 
{ 
    #region "Macro methods loader attribute" 

    /// <summary> 
    /// Module registration 
    /// </summary> 
    private class CustomGatewayLoaderAttribute : CMSLoaderAttribute 
    { 
     /// <summary> 
     /// Constructor 
     /// </summary> 
     public CustomGatewayLoaderAttribute() 
     { 
      // Require E-commerce module to load properly 
      RequiredModules = new string[] { ModuleName.ECOMMERCE }; 
     } 


     /// <summary> 
     /// Initializes the module 
     /// </summary> 
     public override void Init() 
     { 
      // This line provides the ability to register the classes via web.config cms.extensibility section from App_Code 
      ClassHelper.OnGetCustomClass += GetCustomClass; 
     } 


     /// <summary> 
     /// Gets the custom class object based on the given class name. This handler is called when the assembly name is App_Code. 
     /// </summary> 
     private static void GetCustomClass(object sender, ClassEventArgs e) 
     { 
      if (e.Object == null) 
      { 
       // Provide your custom classes 
       switch (e.ClassName.ToLower()) 
       { 
        // Define the class CustomGatewayProvider inheriting the CMSPaymentGatewayProvider and you can customize the provider 
        case "customgatewayprovider": 
         e.Object = new CustomGatewayProvider(); 
         break; 
       } 
      } 
     } 
    } 

    #endregion 
}