2017-02-20 119 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 
}