如何扩展NopCommerce CMS的GenericPathRoutecs

本文关键字:NopCommerce CMS GenericPathRoutecs 扩展 何扩展 | 更新日期: 2023-09-27 18:31:17

有没有办法从我的自定义插件扩展 GenericPathRoute 中支持的实体.cs GetRouteData(...),以便我可以为我的自定义实体添加通用 url 支持?

//process URL
            switch (urlRecord.EntityName.ToLowerInvariant())
            {
                case "product":
                    {
                        data.Values["controller"] = "Catalog";
                        data.Values["action"] = "Product";
                        data.Values["productid"] = urlRecord.EntityId;
                        data.Values["SeName"] = urlRecord.Slug;
                    }
                    break;
                 ...
                case "MyCustomEntity":

如何扩展NopCommerce CMS的GenericPathRoutecs

可以试试这个:

 <i>
 public class CmsCustomUrlRecordEntityNameRequested : IConsumer<CustomUrlRecordEntityNameRequested>
{
    void HandleEvent(CustomUrlRecordEntityNameRequested eventMessage)
    {
                            eventMessage.RouteData.Values["controller"] = "Topic";
                            eventMessage.RouteData.Values["action"] = "TopicDetails";
                            eventMessage.RouteData.Values["topicId"] = urlRecord.EntityId;
                            eventMessage.RouteData.Values["SeName"] = urlRecord.Slug;
    }
}
</i>