module-matrixrate icon indicating copy to clipboard operation
module-matrixrate copied to clipboard

Rate not found if total weight is exactly equal to condition_from_value

Open emorandin opened this issue 2 years ago • 1 comments

Inside vendor/webshopapps/module-matrixrate/src/Model/ResourceModel/Carrier/Matrixrate.php

at line 308:

            $select->where('condition_from_value < :condition_value');
            $select->where('condition_to_value >= :condition_value');

The first condition means that if i have rates like:

condition_from_value;condition_to_value 100.0000;149.9999 150.0000;199.9999 200.0000;299.9999 300.0000;399.9999

And my order total weight is exactly 200, then the module won't find any rates.

It should work by changing the first condition:

            $select->where('condition_from_value <= :condition_value');
            $select->where('condition_to_value >= :condition_value');

emorandin avatar Mar 26 '24 12:03 emorandin

The issue you're encountering with the vendor/webshopapps/module-matrixrate/src/Model/ResourceModel/Carrier/Matrixrate.php file is related to how the condition checks for the order total weight are structured, specifically at the point where order weight exactly matches the lower boundary of a given rate range. The current logic will exclude any rate where condition_from_value is equal to the order's total weight because of the strict < operator used in the query:

$select->where('condition_from_value < :condition_value'); $select->where('condition_to_value >= :condition_value');

In the scenario you provided, an order with a total weight of exactly 200 will not match any of the specified rate ranges due to the < condition, even though logically, it should fall into the 200.0000;299.9999 range.

Proposed Solution To address this issue, you can adjust the query to include rates where the condition_from_value is less than or equal to the condition_value. This modification will ensure that an order with a weight that exactly matches the lower boundary of a rate range is included within that range. Here's how you can adjust the code:

$select->where('condition_from_value <= :condition_value'); $select->where('condition_to_value >= :condition_value');

By changing the < operator to <= for condition_from_value, you ensure that weights that exactly match the lower bound of a range are correctly included.

Moving forward:

MatrixRates is a free, unsupported product. We do offer a wide selection of documentation that should help you answer your questions and those can be found here:

https://docs.shipperhq.com/?s=matrixrate http://support.webshopapps.com/matrixrate/

shqsupport avatar Mar 27 '24 15:03 shqsupport