Expand the ShipmentWeight condition to support ranges

Created on 26 October 2017, about 7 years ago
Updated 16 July 2024, 5 months ago

We need to be able to set a shipping price based on the weight of the shipped items. I can set each rate to have a minimum or maximum weight, but not a range. This results in a bunch on rates appearing on the checkout that are not applicable.

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇬Bulgaria Thunders

    After upgrading the Physical Fields module to 8.x-1.3 Patch in #8 gives an error. After the update, the Minimum and Maximum fields stopped appearing, and the old shipping methods did not work.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    123 pass, 8 fail
  • Just tested patch #8 again with Drupal 9.5.8 , Drupal Commerce 8.x-2.x-dev updated 7 Apr 2023

    The patch still works.

    I also found another module that can do the same thing here -> https://github.com/gnikolovski/commerce_gnikolovski

    The module might be better for existing site since it provided you another new option Limit by shipment weight range in case you don't want current config to mixed up and got an error "Invalid weight unit "" provided." after patched.

  • 🇲🇰Macedonia meri_atanasovska

    I tested and reviewed Patch #8 and I can confirm that it's solving this issue.

  • Status changed to RTBC over 1 year ago
  • 🇺🇸United States Charles Gantt

    Patch in #5 works and resolves the issue. Marking RTBC!

  • 🇹🇭Thailand AlfTheCat

    Wow, what a blast from the past! I literally said a little prayer before hitting enter and applying the patch from #8. It applied and on top of that it's working. Absolutely saved my life, I did not expect commerce shipping to not be able to handle different shipping rates for different weights.

    The commerce shipping tariff module is either not working (it's in alpha) or wasn't designed to cover this use case. There is a commerce shipping linear weight module, which in its current incarnation does not support a base rate and assumes the weight and price increments to be, well, linear. This patch was the last and only hope.

    I now need to make 122 shipping methods (viva the entity_clone module!) to cover all the weight ranges, but at least with this patch we can get the required functionality working and deliver the site.

    Legendary patch!

  • What is the schedule to get this feature into the production release?

  • Status changed to Needs work 10 months ago
  • 🇮🇱Israel jsacksick

    Well the patch has failing tests... And doesn't respect coding standards, so it is not RTBC.
    Additionally, anybody applying the patch with existing shipment weight conditions is going to experience issues with it (configuration is going to be lost).

    This change is a breaking change, it needs to be backwards compatible to support existing shipping methods using this condition...

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 10 months ago
    150 pass
  • Pipeline finished with Success
    10 months ago
    Total: 337s
    #119958
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 10 months ago
    174 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 10 months ago
    174 pass
  • Pipeline finished with Canceled
    10 months ago
    Total: 39s
    #119992
  • Pipeline finished with Success
    10 months ago
    Total: 326s
    #119995
  • Status changed to Needs review 10 months ago
  • Status changed to Needs work 10 months ago
  • 🇮🇱Israel jsacksick

    I think the extra setting isn't required and make the UI more confusing...
    We should probably simply override getComparisonOperators() to add extra operators.
    Perhaps we should add "between" or 2 extra operators?

    "< >" 
    "<= >=" 
    

    Not sure about the labeks. Perhaps "Between (exclusive)" and "Between (inclusive)"?

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 10 months ago
    160 pass
  • Pipeline finished with Success
    10 months ago
    Total: 522s
    #120174
  • Status changed to Needs review 10 months ago
  • Status changed to RTBC 7 months ago
  • Just tested MR35 and it works great. New 2 options "Between (Inclusive)" and "Between (exclusive)" appear in the "Shipment > Shipment Weight -> Operator"

  • Pipeline finished with Skipped
    7 months ago
    #180023
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 7 months ago
    160 pass
  • Status changed to Fixed 7 months ago
  • 🇮🇱Israel jsacksick

    Merged! Thank you everyone!!

  • patch from #8 does not apply to commerce_shipping:8.x-2.9
    Had to downgrade /src/Plugin/Commerce/Condition/ShipmentWeight.php to the version in commerce_shipping:8.x-2.8
    Then apply patch #8.

  • 🇮🇱Israel jsacksick

    How is that not available in 2.9? The change was committed? There are 2 new operators.

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • 🇧🇪Belgium stijnd Belgium

    @99gs3 I also noticed this but now you can use the "Between" operator to set a weight range.
    Thanks for the work everyone. Happy to see this patch can be ditched after 6 years!

  • 🇬🇧United Kingdom Jon Pollard

    Initially I also thought that this was not functioning - but then I realised that I needed to rebuild all of the shipping rules that were using weight to use the new operators.

    The patch that we had previously did not require this and I think that's where confusion may arise.

Production build 0.71.5 2024