Start a new topic
Answered

Qualifying for shipment and payment methods

How do I prevent a shipping method from being displayed to the customer?

The way I am doing it now is evaluate some data in the CalculateRates method, and then return an empty ShippingRate array:

 

if (!isNorwegianShipment)
                return new ShippingRate[] { };

 

Is this the correct way?


I have not tried with payment method yet, but still wonder how it is done correctly.


:Sigve


Best Answer

Just need add double check or check on storefront. Wait I'll add these changes in dev.

Done. https://github.com/VirtoCommerce/vc-community/commit/394b5a3b4a0656e7ca31881f1052b9e489944360


Each store have individual payments and shipment methods management interfaces. You can enable or disable individual methods here.




This was not what i was thinking about.

I have a shipping method that is available to the customer based on their address. In my shipping method I ask an external API if this specific customer address is covered by this shipping method.


And in my sample above, I have a shipping method that is only available to delivery addresses in Norway.


:Sigve 

You can change IsActive property inside you CalculateRates method.

And then does not display not active methods in checkout.

I tried doing the following:

 

if (isNorwegianShipment)
            {
                IsActive = false;
                return new ShippingRate[] { new ShippingRate { Rate = 0, Currency = shippingEvalContext.ShoppingCart.Currency, ShippingMethod = this } };
            }

 But it does not work. Looking at the CartModule it seems to be too late to change the IsActive property:

 

public IHttpActionResult GetShipmentMethods(string cartId)
        {
            var cart = _shoppingCartService.GetById(cartId);
            var store = _storeService.GetById(cart.StoreId);
            var evalContext = new ShippingEvaluationContext(cart);

            var retVal = store.ShippingMethods.Where(x => x.IsActive)
                                              .SelectMany(x => x.CalculateRates(evalContext))
                                              .Select(x => x.ToWebModel()).ToArray();

            return Ok(retVal);
        }

 

:Sigve

Answer

Just need add double check or check on storefront. Wait I'll add these changes in dev.

Done. https://github.com/VirtoCommerce/vc-community/commit/394b5a3b4a0656e7ca31881f1052b9e489944360

Login or Signup to post a comment