Hide payment method with subtotal below a specified value

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 лет назад
Hi All,

I'm using the HidePaymentMethod of IPaymentMethod interface.
For now working ok but have only a little question:

If the product have a discount the price still is the base price, because using the (ShoppingCartItem cart) I can't access the PriceIncludingTax for example.

A few idea in how to access the product price including tax?

For now is that:

public bool HidePaymentMethod(IList<ShoppingCartItem> cart)
        {            
            if (_cashOnDeliveryPaymentSettings.UseMinValue)
            {
                decimal totalItens = 0;
              
                foreach (var item in cart)
                {
                    var product = item.Product;

                    decimal productPrice = product.Price;                  

                    totalItens += (productPrice * item.Quantity);
                }

                if(totalItens < _cashOnDeliveryPaymentSettings.MinValue)
                {
                    return true;
                }
            }
            //you can put any logic here
            //for example, hide this payment method if all products in the cart are downloadable
            //or hide this payment method if current customer is from certain country
            return false;
        }
6 лет назад
You should use OrderTotalCalculationService GetShoppingCartSubTotal()
6 лет назад
Thank You New York,

Problem solved, using the OrderTotalCalculationService GetShoppingCartTotal

Simple:

public bool HidePaymentMethod(IList<ShoppingCartItem> cart)
        {
            var orderTotal = _orderTotalCalculationService.GetShoppingCartTotal(cart);

            if (_cashOnDeliveryPaymentSettings.UseMinValue)
            {
                if(orderTotal < _cashOnDeliveryPaymentSettings.MinValue)
                {
                    return true;
                }
            }

            return false;
        }
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.