Nopcommerce小部件插件dey

时间:2017-06-12 14:35:44

标签: nopcommerce

我是nopcommerce插件开发的新手,但我学得很快。

我正在开发一个小部件插件,在产品详细信息页面中显示供应商信息框,但是遇到了一些问题,产品页面停止显示并抛出错误。

在此问题的下方和下方将是我的代码和产品页面错误的图片。

位指示:

[ChildActionOnly]
public ActionResult PublicInfo(string widgetZone, Vendor vm, object additionalData)
{
        ActionResult actionResult;
        EmptyResult emptyResult = new EmptyResult();
        var activeStoreScopeConfiguration = this.GetActiveStoreScopeConfiguration(this._storeService, this._workContext);
        VendorDetailsSettings VendorDetailsSetting = _settingService.LoadSetting<VendorDetailsSettings>(activeStoreScopeConfiguration);
        if (VendorDetailsSetting != null)
        {
           int QproductId = Convert.ToInt32(System.Web.HttpContext.Current.Request.RequestContext.RouteData.Values["productId"]);


           var productId = Convert.ToInt32(additionalData);
            if (productId != 0)
            {
                Product productById = _productService.GetProductById(productId);
                if (productById == null ? false : productById.VendorId != 0)
                {
                    Vendor vendorById = _vendorService.GetVendorById(productById.VendorId);

                    if (vendorById == null || vendorById.Deleted ? false : vendorById.Active)
                    {
                        var Model = new PublicInfoModel();
                        //Model.Id =  vendorById.Id;
                        ParameterExpression parameterExpression = Expression.Parameter(typeof(Vendor), "x");
                        Model.Name = LocalizationExtensions.GetLocalized<Vendor>(vendorById, Expression.Lambda<Func<Vendor, string>>(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Vendor).GetMethod("Name").MethodHandle)), new ParameterExpression[] { parameterExpression }));
                        parameterExpression = Expression.Parameter(typeof(Vendor), "x");
                        Model.Description = LocalizationExtensions.GetLocalized<Vendor>(vendorById, Expression.Lambda<Func<Vendor, string>>(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Vendor).GetMethod("Description").MethodHandle)), new ParameterExpression[] { parameterExpression }));
                        Model.SeName = SeoExtensions.GetSeName<Vendor>(vendorById);
                        PublicInfoModel model = Model;
                      if (VendorDetailsSetting.ShowVendorEmail || VendorDetailsSetting.ShowVendorPhoneNumer || VendorDetailsSetting.ShowVendorVendorRating)
                        {
                            model.Email = vendorById.Email;


                        }
                      return View("~/Plugins/Widgets.VendorDetails/Views/PublicInfo.cshtml", model);
                    }
                    else
                    {
                        actionResult = emptyResult;
                    }
                }
                else
                {
                    actionResult = emptyResult;
                }
            }
            else
            {
                actionResult = emptyResult;
            }
        }
        else
        {
            actionResult = emptyResult;
        }
        return actionResult;
    }

Plugin.cs:

public IList<string> GetWidgetZones()
{
    return string.IsNullOrEmpty(_vendorDetailsSettings.WidgetZone) ? new List<string>() : new List<string> { _vendorDetailsSettings.WidgetZone };
}


public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
{
    actionName = "Configure";
    controllerName = "WidgetsVendorDetails";
    routeValues = new RouteValueDictionary { { "Namespaces", "Nop.Plugin.Widgets.VendorDetails.Controllers" }, { "area", null } };
}

/// <summary>
/// Gets a route for displaying widget
/// </summary>
/// <param name="widgetZone">Widget zone where it's displayed</param>
/// <param name="actionName">Action name</param>
/// <param name="controllerName">Controller name</param>
/// <param name="routeValues">Route values</param>
public void GetDisplayWidgetRoute(string widgetZone, out string actionName, out string controllerName, out RouteValueDictionary routeValues)
{
    actionName = "PublicInfo";
    controllerName = "WidgetsVendoDetails";
    routeValues = new RouteValueDictionary
    {
        {"Namespaces", "Nop.Plugin.Widgets.VendorDetails.Controllers"},
        {"area", null},
        {"widgetZone", widgetZone}
    };
}


public override void Install()
{
    var settings = new VendorDetailsSettings
    {
        WidgetZone = "productbox_add_info"
    };
    _settingService.SaveSetting(settings);
    base.Install();
}

public override void Uninstall()
{
    _settingService.DeleteSetting<VendorDetailsSettings>();
    base.Uninstall();
 }   
}

1 个答案:

答案 0 :(得分:0)

错误是产品页面没有实现IControllers ......但我已经解决了它。通过返回基数。改为查看()或仅查看...  谢谢。