将附加按钮添加到购物车nopCommerce
本文关键字:购物车 nopCommerce 添加 按钮 | 更新日期: 2023-09-27 17:59:36
我想写一个插件,为购物车添加一个新按钮。
这个按钮将是更新按钮和继续按钮旁边的第三个按钮。
在图片中,你可以看到一个红色按钮,就像我想添加的那个。这张图片只是一个演示。比例失调。
我有一个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!
图片
我的第二个想法是:
将原始OrderSummery.cshtml复制到我的Views
文件夹中。这应该会覆盖原来的内容。但这不起作用。
下面是完整的插件代码。
完整代码
要做到这一点,您需要一个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 }
};
}
这修复了我的项目。
上面的代码是neededbeaucse,你需要重定向根。
您可以这样做:将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"
};
}
希望这对你有帮助!