コード例 #1
0
        /// <summary>
        /// Get the render widget models
        /// </summary>
        /// <param name="widgetZone">Name of widget zone</param>
        /// <param name="additionalData">Additional data object</param>
        /// <returns>List of the render widget models</returns>
        public virtual List <RenderWidgetModel> PrepareRenderWidgetModel(string widgetZone, object additionalData = null)
        {
            var roles = _customerService.GetCustomerRoleIds(_workContext.CurrentCustomer);

            var cacheKey = _cacheKeyService.PrepareKeyForShortTermCache(NopModelCacheDefaults.WidgetModelKey,
                                                                        roles, _storeContext.CurrentStore, widgetZone, _themeContext.WorkingThemeName);

            var cachedModels = _staticCacheManager.Get(cacheKey, () =>
                                                       _widgetPluginManager.LoadActivePlugins(_workContext.CurrentCustomer, _storeContext.CurrentStore.Id, widgetZone)
                                                       .Select(widget => new RenderWidgetModel
            {
                WidgetViewComponentName      = widget.GetWidgetViewComponentName(widgetZone),
                WidgetViewComponentArguments = new RouteValueDictionary {
                    ["widgetZone"] = widgetZone
                }
            }));

            //"WidgetViewComponentArguments" property of widget models depends on "additionalData".
            //We need to clone the cached model before modifications (the updated one should not be cached)
            var models = cachedModels.Select(renderModel => new RenderWidgetModel
            {
                WidgetViewComponentName      = renderModel.WidgetViewComponentName,
                WidgetViewComponentArguments = new RouteValueDictionary {
                    ["widgetZone"] = widgetZone, ["additionalData"] = additionalData
                }
            }).ToList();

            return(models);
        }
コード例 #2
0
        /// <summary>
        /// Prepare render widget models
        /// </summary>
        /// <param name="widgetZone">Widget zone name</param>
        /// <param name="additionalData">Additional data</param>
        /// <returns>List of render widget models</returns>
        public virtual IList <RenderWidgetModel> PrepareRenderWidgetModels(string widgetZone, object additionalData = null)
        {
            //get active widgets by widget zone
            var widgets = _widgetPluginManager.LoadActivePlugins(_workContext.CurrentCustomer, widgetZone: widgetZone);

            //prepare models
            var models = widgets.Select(widget => new RenderWidgetModel
            {
                WidgetViewComponentName      = widget.GetWidgetViewComponentName(widgetZone),
                WidgetViewComponentArguments = new RouteValueDictionary {
                    ["widgetZone"] = widgetZone, ["additionalData"] = additionalData
                }
            }).ToList();

            return(models);
        }