添加额外的按钮到购物车 nopCommerce

Add additional button to shopping cart nopCommerce

我想写一个插件,向购物车添加一个新按钮。

此按钮将是更新按钮和继续按钮旁边的第三个按钮。

在图片中,您可以看到一个红色按钮,就像我要添加的按钮一样。 图片只是演示。比例不对。

我有一个 customViewEngine。

这是我的 Configure.cshtml 我的插件。 我知道我可以更改 OrderSummery.cshtml 但我想通过插件来完成。

@model ShoppingCartModel

@using Nop.Web.Models.ShoppingCart;

@{

    <input type="submit" name="continueshopping2" value="@T("ShoppingCart.ContinueShopping")" class="button-2 continue-shopping-button" />
    <script>
    $(document).ready(function(){
        $("#continueshopping2").appendTo(".cart-options .common-buttons");
    });
    </script>

}

Hello World!

picture

我的第二个方法是:

将原始 OrderSummery.cshtml 复制到我的 Views 文件夹中。 那应该覆盖原来的。但这是行不通的。

下面是完整的插件代码。

Full Code

为此,您需要 index.cshtml。

使用此代码。

<input type="submit" id="check-cart-button" value="Check Cart Button" class="button-2 continue-shopping-button" />
<script type="text/javascript">
    $(document).ready(function () {
        $("#check-cart-button").appendTo(".cart-options .common-buttons");
    });
</script>

并且在 Plugin.cs

你必须添加

public IList<string> GetWidgetZones()
{
    return new[] { "order_summary_content_after" };
}

public void GetDisplayWidgetRoute(string widgetZone, out string actionName, out string controllerName, out RouteValueDictionary routeValues)
{
    actionName = "Index";
    controllerName = "CheckCart";
    routeValues = new RouteValueDictionary {
        { "Namespaces", "Nop.Plugin.Misc.CheckCart.Controllers" },
        { "area", null },
        { "widgetZone", widgetZone }
    };
}

这修复了我的项目。

需要上面的代码,因为您需要重定向根目录。

你可以这样做: 将 ShoppingCart 文件夹添加到插件视图文件夹中。并将 OrderSummary.cshtml 文件添加到 ShoppingCart 文件夹中。 现在将 PluginviewEngine.cs 添加到您的插件和此代码中。

 public PluginViewEngine()
        {
            PartialViewLocationFormats =
                new[]
                {     //themes
                      "~/Themes/{2}/Views/{1}/{0}.cshtml",                   
                     "~/Plugins/Yourpluginname/Views/{1}/{0}.cshtml"
                };

            ViewLocationFormats =
                new[]
                {      
                     //themes
                      "~/Themes/{2}/Views/{1}/{0}.cshtml",
                     "~/Plugins/YourPluginName/Views/ShoppingCart/{0}.cshtml"
                };
        }  

希望对您有所帮助!