简体   繁体   English

NopCommerce - 有条件地隐藏付款选项

[英]NopCommerce - Conditionally hide payment options

Is there a way to conditionally hide certain payment methods based upon some user criteria?有没有办法根据某些用户标准有条件地隐藏某些付款方式?

For example:例如:

if (!_workContext.CurrentCustomer.IsRegistered()){
    // Hide Credit Card payment method
}

The above is just an example, but I have created a custom payment method plugin, and based upon some different things I need to show/hide said payment method from the front end.上面只是一个例子,但我已经创建了一个自定义付款方式插件,并且基于一些不同的东西,我需要从前端显示/隐藏所述付款方式。 Thoughts?想法?

Yes, there are various ways to do so.是的,有多种方法可以做到这一点。 Payment methods code located at Nop.Web > View > Checkout > opcPaymentMethods.cshtml (one page checkout) nopCommerce 3.90付款方式代码位于Nop.Web > View > Checkout > opcPaymentMethods.cshtml (一页结帐) nopCommerce 3.90

<ul class="method-list" id="payment-method-block">
    @for (int i = 0; i < Model.PaymentMethods.Count; i++)
    {
        var paymentMethod = Model.PaymentMethods[i];
        var paymentMethodName = paymentMethod.Name;
        if (!String.IsNullOrEmpty(paymentMethod.Fee))
        {
            paymentMethodName = T("Checkout.SelectPaymentMethod.MethodAndFee", paymentMethodName, paymentMethod.Fee).Text;
            ...
            ....
        }
    }
</ul>

I'm not able find IsRegistered property, so I'm using email address here, and check it with plugin system name, if condition matched then skip that payment method.我找不到IsRegistered属性,所以我在这里使用电子邮件地址,并使用插件系统名称检查它,如果条件匹配,则跳过该付款方式。

@using Nop.Core.Infrastructure;
@using Nop.Core;

<ul class="method-list" id="payment-method-block">
  @for (int i = 0; i < Model.PaymentMethods.Count; i++)
  {                    
      var customerEmail = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.Email;

      var paymentMethod = Model.PaymentMethods[i];

      string _paymentMethodSystemName = paymentMethod.PaymentMethodSystemName;

      if(customerEmail == "admin@yourstore.com")
      {
        if (_paymentMethodSystemName == "Payments.CheckMoneyOrder")
        {
            continue;
        }
      }

      var paymentMethodName = paymentMethod.Name;
  }
  ...
  .....

Now, CheckMoneyOrder won't load for admin user.现在,CheckMoneyOrder 不会为管理员用户加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM