verbb / postie

A Craft Commerce shipping calculator plugin.
Other
12 stars 18 forks source link

Add event to modify rate-hydrated Shipping Methods before they get registered #67

Closed michaelrog closed 3 years ago

michaelrog commented 3 years ago

What are you trying to do?

I need a way to modify the final collection of Shipping Methods before they get registered with Commerce, but after they have prices assigned.

It looks like the modifyShippingMethods event, as currently implemented, only allows me to modify the list of potential shipping methods. This occurs before the list of Shipping Methods is hydrated with price info from the Rates.

My specific use case is: I'm implementing a "Free Shipping" feature, but I only want to apply a discount to the method that would otherwise be least expensive. I need to detect the least expensive Shipping Method and change both its price and its name.

What's your proposed solution?

Add a beforeRegisterShippingMethods event that lives in Service::registerShippingMethods() rather than in an individual provider.

engram-design commented 3 years ago

Thanks so much for the PR. Good point on this, and hadn't really considered that case when needing to compare multiple providers, but makes total sense. I never say no to more events!

engram-design commented 3 years ago

Added in 2.4.8