[1.x] Commerce Shipping Best Rate

Created on 3 September 2024, 8 months ago

https://www.drupal.org/project/commerce_shipping_best_rate โ†’

Commerce Shipping Best Rate is a Drupal module that extends the functionality of Commerce Shipping โ†’ and it's plugin based rate calculation functionality.

It allows a site administrator to filter shipping rates presented to the customer based on service grouping and selection criteria.

It achieves this by subscribing to the ShippingEvents::SHIPPING_RATES event which triggers after a shipping rate has been calculated. Each individual shipping rate returned triggers the event once so the module has to process and store information during the request using the drupal_static() core function to assemble a complete list of rates to be acted upon.

The event also gets the shipping method configuration for all of the active best rate shipping methods and stores it in a static variable for the duration of the request. Due to shipping methods being content entities instead of configuration entities adding configuration to the already existing shipping methods was not possible.

The best rate shipping methods serve as a container for grouping configuration information, label, description. They also create a generic rate that is added to the list with it's price adjusted later to reflect the outcome of price comparison for that group.

Once the event is triggered it gets the configuration and stores it. Then for each non best rate it compares it's ID to the list of configured IDs in the best rate methods and any matching rates are stored in the static variable. The original rate object is then deleted, unless configured to remain.

Once the event triggers for best rates, which are expected to be sorted to the bottom of the list (last to be processed), the list of rates is compared and the cheapest one is selected. The generic rate's price is modified and then saved.

Once all of the events are processed then the commerece_shipping module goes on to render the resulting list of rates and display it to the user.

This module was programmed by me as part of my employment and was designed for use on my employer's website. I determined it's functionality might be useful for other community members and decided to publish it. It is considered feature complete unless a community member brings forth other relevant features to add.

Ongoing maintenance will be performed by myself, paid or not.

๐Ÿ“Œ Task
Status

Needs review

Component

module

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States rhovland Oregon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024