Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In D7, most (if not all) shipping modules had a `hook_rates()` to allow modifying the rates for various reasons.
Comment | File | Size | Author |
---|---|---|---|
#14 | 2991416=14-rates-event.patch | 12.32 KB | bojanz |
#8 | commerce_shipping-dispatch-event-2991416-8.patch | 6.27 KB | sah62 |
| |||
#7 | interdiff-2-7.txt | 2.76 KB | mitrpaka |
#7 | commerce_shipping-dispatch-event-2991416-7.patch | 6.15 KB | mitrpaka |
#5 | commerce_shipping-dispatch-event-2991416-5.patch | 6.19 KB | krystalcode |
Comments
Comment #2
thejacer87 CreditAttribution: thejacer87 at Acro Commerce commentedComment #3
krystalcode CreditAttribution: krystalcode at Acro Commerce commented`$shipping_rates` is an array of `ShippingRate` objects, right? You shouldn't need to get them again from the event (`$shipping_rates = $event->getRates()` as objects are always passed by reference, including in arrays. You can remove that line, just test it works as expected after removing it.
Comment #4
thejacer87 CreditAttribution: thejacer87 at Acro Commerce commentedya for w/e reason, it won't work like you expect
i looked around and saw other modules using the same pattern:
TaxTypeBase.php
ProductVariationStorage.php
PluginItemDeriver
Comment #5
krystalcode CreditAttribution: krystalcode at Acro Commerce commented- Provided the shipping method to the event as well as the shipping rates do not provide any context.
- Improved docblocks.
Comment #7
mitrpaka CreditAttribution: mitrpaka as a volunteer commentedRe-roll of previous patch file.
Comment #8
sah62 CreditAttribution: sah62 commentedReroll...
Comment #9
sah62 CreditAttribution: sah62 commentedI've implemented the latest patch on my test site and can confirm that it seems to be working fine. I can successfully subscribe to events and be notified when they fire. Can we get this committed and released?
Comment #10
NiklanTested it today. Everything works as expected. Thank you for patch!
Comment #11
jsacksick CreditAttribution: jsacksick at Centarro commentedAn event is also being added as part of the patch from #3098140: Simplify calculating rates for a shipment.
This also adds a new service which has a method for calculating rates, so it makes more sense to have the event fired there (instead of the field widget).
Comment #13
bojanz CreditAttribution: bojanz at Centarro commentedRetitling.
Patch doesn't apply to -dev.
I'll extract jsacksick's improvements from #3098140: Simplify calculating rates for a shipment back into a new patch.
Comment #14
bojanz CreditAttribution: bojanz at Centarro commentedHere's a rerolled patch.
The SHIPPING_RATES_POST_CALCULATE event has been renamed to SHIPPING_RATES, since that matches D7 and is shorter. We now $rate->fromArray() and $rate->toArray() methods to simplify altering, and we have test coverage that serves as an example.
Comment #16
bojanz CreditAttribution: bojanz at Centarro commentedWe have random fails in our functional tests. I'll fix that in another issue.
Thanks, everyone!